Environment variables
| Variable | Required | Description |
|---|---|---|
TELEGRAM_BOT_TOKEN | Yes | The bot token from @BotFather |
TELEGRAM_ALLOWLIST | No | Comma-separated chat IDs allowed to message the bot |
Setup
Create a bot with @BotFather
Open Telegram and start a chat with @BotFather. Run the
/newbot command and follow the prompts to choose a name and username for your bot.Copy your bot token
After creating the bot, BotFather sends you a token that looks like this:Keep this token private. Anyone with it can control your bot.
Find your chat ID
To restrict your bot to your own chat, you need your Telegram chat ID. The easiest way is to start a chat with @userinfobot — it replies with your numeric user ID.Alternatively, send any message to your bot and watch the gateway logs. The log line for an unallowlisted sender includes the chat ID:
Set the environment variables
Add both values to your To allow multiple chat IDs, separate them with commas:
.env file:Allowlist behavior
The gateway evaluates every incoming message againstTELEGRAM_ALLOWLIST before passing it to the router.
- Empty allowlist — the bot accepts messages from any chat ID. This is suitable for private bots running on a local machine, but not for bots exposed to the public.
- Populated allowlist — only chat IDs in the list are accepted. Messages from other senders are dropped and logged as a warning.
How messages are routed
The bot listens formessage:text events. When a message arrives:
- The chat ID is extracted from the update.
- The allowlist check runs.
- If the sender is allowed, the message is wrapped in an
IncomingMessagewith aconversationIdof the formtelegram:<chatId>and handed to the router. - The router passes the message to the agent backend and sends the reply back via
bot.api.sendMessage.
Attachments
The Telegram integration currently handles text messages only. If the agent produces an attachment in its reply (for example, a file generated by a code run), the gateway sends a notice explaining that the attachment is available at the path specified in
ATTACHMENTS_DIR.ATTACHMENTS_DIR defaults to .gateway/attachments/. The agent can write files there and reference them in replies.