Skip to main content
Long polling is the simplest way to receive updates from Telegram. Your bot repeatedly asks Telegram’s servers for new updates, waiting for up to 30 seconds for new data to arrive.

Basic Usage

The easiest way to start receiving updates:
That’s it! The bot will now receive and process all updates.

Configuration Options

Stopping the Bot

Handling Signals

Gracefully shut down on process termination:

Allowed Updates

Control which updates your bot receives:
If you don’t specify allowed_updates, Telegram will send all update types except chat_member, message_reaction, and message_reaction_count.

Available Update Types

  • message - New incoming message
  • edited_message - Message was edited
  • channel_post - New channel post
  • edited_channel_post - Channel post was edited
  • business_connection - Business connection status changed
  • business_message - New business message
  • edited_business_message - Business message edited
  • deleted_business_messages - Business messages deleted
  • inline_query - New inline query
  • chosen_inline_result - Result of inline query chosen
  • callback_query - Callback button pressed
  • shipping_query - Shipping query for invoice
  • pre_checkout_query - Pre-checkout query for invoice
  • purchased_paid_media - Paid media purchased
  • poll - Poll state changed
  • poll_answer - User changed poll answer
  • my_chat_member - Bot’s chat member status changed
  • chat_member - Chat member status changed
  • chat_join_request - User requested to join chat
  • chat_boost - Chat boost added
  • removed_chat_boost - Chat boost removed
  • message_reaction - Message reaction changed
  • message_reaction_count - Anonymous reactions changed

Error Handling

Startup Callback

Run code when the bot is ready:

Drop Pending Updates

Skip old updates when starting:
This permanently deletes all pending updates. Only use this if you’re sure you don’t need old updates.

Long Polling vs Webhooks

Advantages:
  • Simple setup, no server configuration
  • Works behind firewalls and NAT
  • No HTTPS certificate required
  • Great for development
Disadvantages:
  • Higher latency (up to 30 seconds)
  • Keeps a connection open
  • Doesn’t scale as well
  • Not ideal for serverless

Sequential Update Processing

By default, grammY processes updates sequentially:

Concurrent Processing

For better performance with independent updates, use the run helper:
Use concurrent processing when updates are independent. Be careful with shared state!

Development Setup

Typical development configuration:

Best Practices

Graceful Shutdown

Always handle SIGINT/SIGTERM to stop the bot gracefully

Use Webhooks in Production

Switch to webhooks for better performance in production

Set allowed_updates

Only receive update types you need to reduce bandwidth

Handle Errors

Install an error handler with bot.catch() to prevent crashes

Troubleshooting

  • Check if another bot instance is running (only one can receive updates at a time)
  • Verify your bot token is correct
  • Make sure no webhook is set: await bot.api.deleteWebhook()
  • Check if you’re filtering out updates with allowed_updates
  • Add error handling with bot.catch()
  • Check for unhandled promise rejections
  • Make sure your process doesn’t exit unexpectedly
  • Monitor your server’s resources
  • Consider using concurrent processing with run()
  • Optimize slow operations
  • Consider switching to webhooks
  • Check your network connection

Example: Complete Bot

See Also