Polling
Polling is a mode where your server periodically requests updates from Telegram. Suitable for development and testing.
Advantages
Section titled “Advantages”- ✅ Does not require public URL
- ✅ Simple setup
- ✅ Suitable for development
- ✅ Can be used locally
Disadvantages
Section titled “Disadvantages”- ❌ Delay in receiving updates
- ❌ Inefficient resource usage
- ❌ Not recommended for production with high load
1. Configuration in config/hybridgram.php
Section titled “1. Configuration in config/hybridgram.php”'bots' => [ [ 'token' => env('BOT_TOKEN'), 'bot_id' => 'main', 'update_mode' => UpdateModeEnum::POLLING, 'routes_file' => base_path('routes/telegram.php'), 'polling_limit' => env('TELEGRAM_POLLING_LIMIT', 100), 'polling_timeout' => env('TELEGRAM_POLLING_TIMEOUT', 0), 'allowed_updates' => explode(',', env('ALLOWED_TELEGRAM_UPDATES', '')), ],],2. Environment Variables
Section titled “2. Environment Variables”BOT_TOKEN=your_tokenBOT_ID=mainTELEGRAM_UPDATE_MODE=POLLINGTELEGRAM_POLLING_LIMIT=100TELEGRAM_POLLING_TIMEOUT=0ALLOWED_TELEGRAM_UPDATES=message,callback_query3. Starting Polling
Section titled “3. Starting Polling”Basic Run
Section titled “Basic Run”php artisan hybridgram:polling mainWith Hot-reload (for development)
Section titled “With Hot-reload (for development)”php artisan hybridgram:polling main --hot-reloadHot-reload automatically restarts command when code changes.
With Watch Settings
Section titled “With Watch Settings”php artisan hybridgram:polling main \ --hot-reload \ --watch=app,routes,config,src \ --watch-interval=1Parameters:
--watch— directories to watch (comma-separated)--watch-interval— check interval in seconds
Limiting Update Types
Section titled “Limiting Update Types”php artisan hybridgram:polling main --allowed-updates=message,callback_queryOr in config:
'allowed_updates' => ['message', 'callback_query'],hybridgram:polling command options
Section titled “hybridgram:polling command options”| Option | Short | Description |
|---|---|---|
--log-updates | -L | Print a one-line summary for every received update |
--full | -F | Print full update payload as pretty JSON (implies --log-updates) |
--hot-reload | -R | Auto-restart on code changes (for development) |
--watch= | -W= | Comma-separated paths to watch (default: app,routes,config,src) |
--watch-interval=1 | -I | Seconds between file scans in hot-reload mode |
Examples with short aliases:
php artisan hybridgram:polling main -Lphp artisan hybridgram:polling main -Fphp artisan hybridgram:polling main -R -W=app,routes -I 2Polling Parameters
Section titled “Polling Parameters”polling_limit
Section titled “polling_limit”Maximum number of updates per request (1-100):
'polling_limit' => 100, // MaximumMore updates = fewer requests, but more delay.
polling_timeout
Section titled “polling_timeout”Request timeout in seconds (0 = short polling):
'polling_timeout' => 0, // Short pollingFor long polling:
'polling_timeout' => 60, // Long polling (up to 60 seconds)Long polling reduces number of requests but increases response delay to commands.
Hot-reload in Development
Section titled “Hot-reload in Development”Hot-reload automatically restarts command when files change:
php artisan hybridgram:polling main --hot-reload --watch=app,routesThis allows:
- Not restarting command manually
- Quickly seeing code changes
- Convenient local development
Running via Supervisor (production)
Section titled “Running via Supervisor (production)”For continuous operation in production:
[program:telegram-polling]command=php /path/to/artisan hybridgram:polling maindirectory=/path/to/projectautostart=trueautorestart=truestopasgroup=truekillasgroup=trueuser=www-dataredirect_stderr=truestdout_logfile=/path/to/storage/logs/polling.logLimitations
Section titled “Limitations”allowed_updates
Section titled “allowed_updates”Limit update types to reduce load:
'allowed_updates' => [ 'message', 'callback_query', // Only needed types],One Process per Bot
Section titled “One Process per Bot”Don’t run multiple polling processes for the same bot simultaneously — this may lead to duplicate updates.
Debugging
Section titled “Debugging”Logging
Section titled “Logging”To see received updates in the console, use -L (one-line summary per update) or -F (full JSON):
php artisan hybridgram:polling main -Lphp artisan hybridgram:polling main -FExample output with -L:
Processing update 12345...Processing update 12346...Status Check
Section titled “Status Check”Check that polling is working:
ps aux | grep "hybridgram:polling"Transitioning from Polling to Webhook
Section titled “Transitioning from Polling to Webhook”When ready for production:
-
Set up webhook:
Terminal window php artisan hybridgram:set-webhook main -
Stop polling:
Terminal window # Find and stop processpkill -f "hybridgram:polling" -
Delete webhook (if need to return to polling):
Terminal window php artisan hybridgram:delete-webhook main
Recommendations
Section titled “Recommendations”For Development
Section titled “For Development”- ✅ Use hot-reload
- ✅ Limit
allowed_updatesto only needed types - ✅ Use
polling_limit = 10-20for fast response
For Production
Section titled “For Production”- ❌ Not recommended to use polling in production
- ✅ Use webhook instead of polling
- ✅ If necessary, use long polling with timeout
When to Use Polling
Section titled “When to Use Polling”Use polling when:
- Developing bot locally
- Testing functionality
- No ability to set up HTTPS
- Low load and no critical delays
Don’t use polling when:
- Production environment
- High load
- Critical update delays
- Maximum performance needed
What’s Next?
Section titled “What’s Next?”- Webhook — recommended mode for production
- Sending Messages — working with TelegramBotApi