Skip to content

Polling

Polling is a mode where your server periodically requests updates from Telegram. Suitable for development and testing.

  • ✅ Does not require public URL
  • ✅ Simple setup
  • ✅ Suitable for development
  • ✅ Can be used locally
  • ❌ Delay in receiving updates
  • ❌ Inefficient resource usage
  • ❌ Not recommended for production with high load
'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', '')),
],
],
BOT_TOKEN=your_token
BOT_ID=main
TELEGRAM_UPDATE_MODE=POLLING
TELEGRAM_POLLING_LIMIT=100
TELEGRAM_POLLING_TIMEOUT=0
ALLOWED_TELEGRAM_UPDATES=message,callback_query
Terminal window
php artisan hybridgram:polling main
Terminal window
php artisan hybridgram:polling main --hot-reload

Hot-reload automatically restarts command when code changes.

Terminal window
php artisan hybridgram:polling main \
--hot-reload \
--watch=app,routes,config,src \
--watch-interval=1

Parameters:

  • --watch — directories to watch (comma-separated)
  • --watch-interval — check interval in seconds
Terminal window
php artisan hybridgram:polling main --allowed-updates=message,callback_query

Or in config:

'allowed_updates' => ['message', 'callback_query'],
OptionShortDescription
--log-updates-LPrint a one-line summary for every received update
--full-FPrint full update payload as pretty JSON (implies --log-updates)
--hot-reload-RAuto-restart on code changes (for development)
--watch=-W=Comma-separated paths to watch (default: app,routes,config,src)
--watch-interval=1-ISeconds between file scans in hot-reload mode

Examples with short aliases:

Terminal window
php artisan hybridgram:polling main -L
php artisan hybridgram:polling main -F
php artisan hybridgram:polling main -R -W=app,routes -I 2

Maximum number of updates per request (1-100):

'polling_limit' => 100, // Maximum

More updates = fewer requests, but more delay.

Request timeout in seconds (0 = short polling):

'polling_timeout' => 0, // Short polling

For 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 automatically restarts command when files change:

Terminal window
php artisan hybridgram:polling main --hot-reload --watch=app,routes

This allows:

  • Not restarting command manually
  • Quickly seeing code changes
  • Convenient local development

For continuous operation in production:

[program:telegram-polling]
command=php /path/to/artisan hybridgram:polling main
directory=/path/to/project
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=www-data
redirect_stderr=true
stdout_logfile=/path/to/storage/logs/polling.log

Limit update types to reduce load:

'allowed_updates' => [
'message',
'callback_query',
// Only needed types
],

Don’t run multiple polling processes for the same bot simultaneously — this may lead to duplicate updates.

To see received updates in the console, use -L (one-line summary per update) or -F (full JSON):

Terminal window
php artisan hybridgram:polling main -L
php artisan hybridgram:polling main -F

Example output with -L:

Processing update 12345...
Processing update 12346...

Check that polling is working:

Terminal window
ps aux | grep "hybridgram:polling"

When ready for production:

  1. Set up webhook:

    Terminal window
    php artisan hybridgram:set-webhook main
  2. Stop polling:

    Terminal window
    # Find and stop process
    pkill -f "hybridgram:polling"
  3. Delete webhook (if need to return to polling):

    Terminal window
    php artisan hybridgram:delete-webhook main
  • ✅ Use hot-reload
  • ✅ Limit allowed_updates to only needed types
  • ✅ Use polling_limit = 10-20 for fast response
  • ❌ Not recommended to use polling in production
  • ✅ Use webhook instead of polling
  • ✅ If necessary, use long polling with timeout

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