Installation
Installation via Composer
Section titled “Installation via Composer”Install the package in your Laravel project:
composer require hybridgram/tgbot-laravelPublish Configuration
Section titled “Publish Configuration”Publish the package configuration file:
php artisan vendor:publish --provider="HybridGram\Providers\TelegramServiceProvider"This will create the config/hybridgram.php file where you can configure your bots.
Environment Variables Setup
Section titled “Environment Variables Setup”Add the following variables to your .env file:
# Your bot token from @BotFatherBOT_TOKEN=your_bot_token
# Bot ID (optional, defaults to 'main')# If not specified, BOT_TOKEN will be used as the identifierBOT_ID=main
# Update receiving mode: POLLING or WEBHOOKTELEGRAM_UPDATE_MODE=POLLING
# Path to routes file (optional)TELEGRAM_ROUTES_FILE=routes/telegram.phpAdditional Webhook Settings
Section titled “Additional Webhook Settings”If you’re using Webhook mode, add:
# Webhook URLTELEGRAM_WEBHOOK_URL=https://your-domain.com/telegram/bot/webhook/main
# Secret token for security (optional)TELEGRAM_SECRET_TOKEN=your_secret_token
# Port for webhook processing (if using Go handler)TELEGRAM_WEBHOOK_PORT=9070
# Path to SSL certificate (if required)TELEGRAM_CERTIFICATE_PATH=/path/to/certificate.pem
# Drop pending updates when setting webhookTELEGRAM_WEBHOOK_DROP_PENDING=falsePolling Settings
Section titled “Polling Settings”For Polling mode:
# Updates limit per request (default 100)TELEGRAM_POLLING_LIMIT=100
# Request timeout in seconds (default 0)TELEGRAM_POLLING_TIMEOUT=0
# Allowed update types (comma-separated)ALLOWED_TELEGRAM_UPDATES=message,callback_queryCreating Routes File
Section titled “Creating Routes File”Create a file to define your bot routes. By default, it’s routes/telegram.php:
<?php
use HybridGram\Facades\TelegramRouter;use HybridGram\Core\Routing\RouteData\CommandData;
TelegramRouter::onCommand('/start', function(CommandData $data) { $telegram = app(\HybridGram\Telegram\TelegramBotApi::class); $telegram->sendMessage($data->chatId, 'Hello! 👋');});Installation Verification
Section titled “Installation Verification”After installation, make sure that:
- ✅ Package is installed via Composer
- ✅ Configuration file is published
- ✅ Environment variables are configured
- ✅ Routes file is created
What’s Next?
Section titled “What’s Next?”- Configuration — detailed package configuration
- Creating Your First Route — start creating handlers