Telegram Setup
Each DjinnBot agent can have its own Telegram bot, created through BotFather. Users message the bot directly — no routing needed. The TelegramBridgeManager handles hot-reloading, so you can enable or disable agents’ bots without restarting the engine.
Overview
Telegram uses a one-bot-per-agent model:
- Each agent gets its own Telegram bot (created via BotFather)
- Users DM the bot directly — messages go straight to that agent
- No routing ambiguity, no shared accounts
- Bots use long-polling via grammY, so no public URL or webhook endpoint is required
Step 1: Create Bots with BotFather
For each agent you want on Telegram:
Open BotFather
Open Telegram and start a conversation with @BotFather.
Create a new bot
Send /newbot and follow the prompts:
- Choose a display name (e.g., “Eric - Product Owner”)
- Choose a username (must end in
bot, e.g.,djinnbot_eric_bot) - BotFather will reply with the bot token — save this
Customize the bot (optional)
/setdescription— what users see before starting a conversation/setabouttext— shown on the bot’s profile page/setuserpic— upload the agent’s avatar
Repeat for each agent you want on Telegram.
Step 2: Configure in the Dashboard
The easiest way to set up Telegram is through the dashboard:
- Open the DjinnBot dashboard
- Go to Settings > Integrations > Telegram
- For each agent, enter the bot token from BotFather
- Toggle the agent to Enabled
- Save
The engine picks up the change immediately via Redis pub/sub — no restart needed.
Alternative: Environment Variables
You can also configure Telegram via environment variables and YAML files.
Add the bot token to .env:
TELEGRAM_ERIC_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz
TELEGRAM_FINN_BOT_TOKEN=987654321:ZYXwvuTSRqpoNMLkjihGFEdcbaCreate agents/<agent-id>/telegram.yml:
bot_token: ${TELEGRAM_ERIC_BOT_TOKEN}Then restart:
docker compose restart engineStep 3: Set Up Allowlists
By default, Telegram bots are open to anyone who finds them. To restrict access:
- Go to Settings > Integrations > Telegram in the dashboard
- Under each agent, configure the Allowlist
- Add allowed users by Telegram user ID or username
- Or toggle Allow All if the bot should be publicly accessible
To find a user’s Telegram ID, have them message @userinfobot.
How Telegram Integration Works
Message Flow
- User sends a message to an agent’s Telegram bot
- The grammY long-polling loop picks it up
- Allowlist check — unauthorized users are silently ignored
- Typing indicator starts (the bot shows “typing…” in the chat)
- Message is routed to a ChatSessionManager session
- Agent processes the message in a full container with tools and memory
- Response is converted from markdown to Telegram HTML and sent back
- Long responses are automatically split into multiple messages
Typing Indicators
While an agent works, Telegram shows the “typing…” indicator. This is refreshed every few seconds (Telegram typing expires after ~5s), so the user always knows the agent is processing.
Message Formatting
Agent responses are converted from markdown to Telegram’s HTML format:
**bold**becomes<b>bold</b>`code`becomes<code>code</code>- Code blocks become
<pre>blocks with language tags - Links are preserved as
<a>tags
If HTML parsing fails (edge cases in agent output), the bot falls back to plain text.
Hot Reload
The TelegramBridgeManager listens for Redis pub/sub events on telegram:config:changed:{agentId}. When you update an agent’s Telegram config in the dashboard:
- The API publishes a config change event
- The manager stops the old bot (if running)
- The manager starts a new bot with the updated config
No engine restart required.
Troubleshooting
Bot doesn’t respond
- Verify the bot token is correct — send
/tokento BotFather to see active tokens - Check that the agent is enabled in the dashboard Telegram settings
- Check engine logs:
docker compose logs engine | grep -i telegram - Make sure the user is on the allowlist (or Allow All is on)
“Chat sessions not yet configured” error
- The ChatSessionManager hasn’t been injected yet — this usually means the engine is still starting up. Wait a few seconds and try again.
Bot responds to some users but not others
- Check the allowlist — only users matching an allowlist entry (by Telegram user ID or username) get a response. Others are silently ignored.
Telegram Resources
- BotFather — create and manage Telegram bots
- Telegram Bot API
- grammY Framework — the TypeScript Telegram bot framework used by DjinnBot