Add Telegram as a messaging channel for NanoClaw. Telegram can run alongside existing channels or replace them entirely.Documentation Index
Fetch the complete documentation index at: https://docs.nanoclaw.dev/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Telegram integration uses the grammy library to connect to Telegram’s Bot API. It supports all core NanoClaw features including group chats, isolated contexts, scheduled tasks, and typing indicators.Features
- Full channel support - Direct messages, group chats, and channels
- Forum topics - Replies land in the correct topic thread in supergroups
- Bot commands - Built-in
/chatidcommand for registration - Typing indicators - Shows when the assistant is working
- Concurrent chats - Handle multiple conversations simultaneously
- Flexible deployment - Run alongside existing channels or as the only channel
Adding Telegram
Use the/add-telegram skill to add Telegram support:
Choose deployment mode
- Replace existing channels - Telegram becomes the only channel
- Alongside - Add Telegram alongside existing channels
Apply code changes
The skill merges the
skill/telegram branch which adds:src/channels/telegram.ts(TelegramChannel implementation)src/channels/telegram.test.ts(46 unit tests)- Multi-channel support in
src/index.ts - Telegram config in
src/config.ts - The
grammyNPM package
Creating a Telegram bot
If you don’t already have a Telegram bot:Create the bot
Send
/newbot and follow the prompts:- Bot name: Something friendly (e.g., “Andy Assistant”)
- Bot username: Must end with “bot” (e.g., “andy_ai_bot”)
Configuration
Environment variables
Add to.env:
Sync to container
The container reads environment fromdata/env/env:
Group privacy settings
By default, Telegram bots only see messages that @mention them or start with/ in group chats.
To let the bot see all messages in groups:
This is optional. If you only want trigger-based responses (via @mentions), leave group privacy enabled.
Build and restart
After configuration:Registering chats
Get chat ID
Register the chat
For your main chat (responds to all messages):Testing the connection
Send a message to your registered Telegram chat:- For main chat: Any message works
- For non-main chats:
@Andy helloor @mention the bot
Check logs
JID format
Telegram chats use thetg: prefix:
- Individual chat:
tg:123456789 - Group chat:
tg:-1001234567890 - Channel:
tg:-1001234567890
Forum topics (supergroups)
Telegram supergroups can enable Topics to organize conversations into threads. The Telegram integration automatically tracksmessage_thread_id from incoming messages and routes replies to the correct topic.
How it works
- When a user messages the bot from a specific topic, the bot extracts the
message_thread_id - Replies and typing indicators are sent back to the same topic thread
- Non-forum groups (without topics enabled) work as before — no configuration needed
Forum topics support requires no additional setup. The bot detects and tracks thread IDs automatically.
Enabling topics in a group
- Open your Telegram supergroup settings
- Go to Topics and enable them
- The bot will automatically reply within the correct topic
Implementation details
The Telegram channel implements theChannel interface. Incoming messages include the thread_id when sent from a forum topic, and outgoing messages route to the correct thread:
Troubleshooting
Bot not responding
Check these common issues:Token not configured
Token not configured
Verify
TELEGRAM_BOT_TOKEN is set in .env and synced to data/env/env:Chat not registered
Chat not registered
Check if the chat is in the database:
Service not running
Service not running
Check if NanoClaw is running:
Trigger pattern not matched
Trigger pattern not matched
For non-main chats with
requiresTrigger: true, messages must include the trigger pattern (e.g., @Andy).Bot replies in General instead of the correct topic
If your supergroup has topics enabled but the bot always replies in the General thread:- Make sure you’re running the latest version of the Telegram skill — topic support was added in the
message_thread_idfix - Re-merge the skill branch to pick up the update:
- Rebuild and restart NanoClaw
Bot only responds to @mentions in groups
This is the default Telegram behavior. To change:- Open @BotFather
- Send
/mybotsand select your bot - Bot Settings → Group Privacy → Turn off
- Remove and re-add the bot to the group (required for change to take effect)
Getting chat ID fails
If/chatid doesn’t work:
-
Verify the bot token:
-
Check that NanoClaw is running:
- Make sure the bot is started (it should connect on launch)
Agent swarms (teams)
The/add-telegram-swarm skill extends the Telegram integration with specialized agent swarm support. Each subagent appears as a different Telegram bot in the group, making it clear which agent is speaking.
How it works
- Each swarm agent gets its own Telegram bot token and identity
- When the orchestrator delegates to a subagent, that agent’s responses come from its own bot
- Users can see which agent is working on what, and interact with specific agents directly
- The orchestrator coordinates the team and routes tasks
Installation
The swarm skill depends on the base Telegram integration. If you already have/add-telegram applied:
Configuration
Each swarm agent needs its own bot token. Create additional bots via @BotFather and add their tokens to.env:
The swarm skill has a 14KB SKILL.md with detailed setup instructions. Running
/add-telegram-swarm in Claude Code walks you through the full configuration interactively.Removing Telegram
Since Telegram was added via a git merge, you remove it by reverting the merge commit:Find the merge commit
abc1234 Merge remote-tracking branch 'upstream/skill/telegram'.Next steps
Add Discord
Add Discord support to your installation
Add Slack
Add Slack support to your installation
Skills system
Learn more about how skills work