What is an Update?
An update is a JSON object from Telegram that contains information about an event. Each update has:- A unique
update_idthat increments sequentially - Exactly one of many possible update types (message, callback_query, etc.)
Update Types
Message Updates
The most common updates are messages:message- New message in a chatedited_message- A message was editedchannel_post- New channel postedited_channel_post- Channel post edited
Business Updates
For Telegram Business accounts:business_connection- Business account connected/disconnectedbusiness_message- New message in business chatedited_business_message- Business message editeddeleted_business_messages- Messages deleted from business chat
Callback Queries
When users click inline buttons:Inline Queries
When users type@your_bot query in any chat:
Reactions
When users react to messages:You must enable
message_reaction in allowed_updates to receive reaction updates:Chat Member Updates
Other Update Types
Receiving Updates
There are two ways to receive updates:Long Polling (Default)
The bot repeatedly callsgetUpdates to fetch new updates:
- Easy to set up
- Works anywhere (no public URL needed)
- Good for development
- Slightly higher latency
- Keeps a persistent connection
- Limited scalability for high-load bots
Webhooks
Telegram sends updates to your server via HTTP POST:- Lower latency
- Better for high-load bots
- Serverless-friendly
- Requires public HTTPS URL
- More complex setup
Allowed Updates
By default, grammY requests most update types but excludes:chat_membermessage_reactionmessage_reaction_count
All Available Update Types
Update Processing
Sequential Processing
By default, grammY processes updates sequentially:- Messages from the same user are processed in order
- No race conditions with shared state
- Predictable behavior
Concurrent Processing
For high-load bots, use @grammyjs/runner:- Processes multiple updates simultaneously
- Maintains order for updates from the same chat
- Handles backpressure automatically
- Provides graceful shutdown
Update Confirmation
Telegram needs confirmation that you received updates. This is handled automatically:Long Polling
Webhooks
Dropping Pending Updates
When starting your bot, you can drop all pending updates:- During development when you don’t want old test messages
- After bot downtime when old updates are no longer relevant
- When changing the bot’s behavior significantly
Update ID Management
Each update has a sequentialupdate_id:
- Ensures no updates are skipped
- Resumes from the correct position after restart
- Handles errors gracefully
Handling Updates Manually
Process updates without long polling:- Testing
- Custom update sources
- Webhook implementations
Best Practices
Update Flow
Debugging Updates
Log all incoming updates:Related
- Context - How updates are wrapped in context
- Middleware - Processing updates
- Filter Queries - Filtering update types
- Webhooks - Setting up webhooks
- Long Polling - Long polling details