Skip to main content

Installation

Environment Variables

Create a bot using @BotFather on Telegram to get your bot token.

Configuration Options

Setup

Webhook Handler

Features

Supported Events

  • message - Regular messages in chats/groups
  • edited_message - Edited messages
  • channel_post - Channel posts
  • callback_query - Inline button clicks
  • message_reaction - Reactions added/removed

Message Types

Telegram supports:
  • Private chats - 1:1 conversations
  • Groups - Multi-user chats
  • Supergroups - Large groups with threads/topics
  • Channels - Broadcast channels

Topic Threads (Supergroups)

For groups with topics enabled:

Inline Keyboards (Buttons)

Create messages with inline buttons:
Handle button clicks:
Telegram automatically acknowledges button clicks. The adapter calls answerCallbackQuery for you.

Reactions

Add/remove reactions:

File Uploads

Send files with messages:
Telegram adapter supports one file per message. Multiple files will throw a validation error.

Markdown Formatting

Telegram supports markdown in messages:

Thread IDs

Telegram thread IDs encode chat ID and optional topic:
Examples:
  • Private chat: telegram:123456789
  • Group: telegram:-987654321
  • Group with topic: telegram:-987654321:42
Chat IDs are negative for groups/supergroups, positive for users.

Opening DMs

Create a private chat with a user:
User must have started a conversation with the bot first (via /start command or deep link).

Message History

Message history is cached in-memory:
Telegram Bot API doesn’t provide a message history endpoint. The adapter caches messages it receives. For persistent history, use a custom StateAdapter.

Platform Limits

  • Message length: 4,096 characters
  • Caption length: 1,024 characters (for files)
  • File size: 50 MB (20 MB via Bot API by default, 50 MB with local Bot API server)
  • Rate limits: 30 messages/second globally, 1 message/second per chat
  • Inline keyboard buttons: 100 buttons max
See Telegram limits for details.

Code Examples

Polling Control

Manually start/stop polling:

Troubleshooting

  • Set secretToken in adapter config and webhook URL
  • Verify secret token matches in both places
  • Check that header x-telegram-bot-api-secret-token is present
  • Disable Privacy Mode via @BotFather
  • Or add bot as admin to receive all messages
  • Groups require /setprivacy disabled to receive non-command messages
  • Only one polling instance can run at a time
  • Use telegram.stopPolling() before starting a new instance
  • Check telegram.isPolling before starting
  • Verify file size is under 50 MB
  • Only one file per message is supported
  • Use proper MIME types (optional but recommended)

Bot Commands

Register commands via @BotFather:
Handle commands in code:

Next Steps

Message Handling

Process messages and build conversation flows

Inline Keyboards

Create interactive buttons with cards

Telegram Bot API

Learn about Telegram’s Bot API

State Management

Persist data across requests