Telegram Channel
The Telegram channel enables ZeroClaw to communicate via Telegram’s Bot API with support for polling, streaming responses, attachments, and group chat controls.Overview
- Channel Name:
telegram - Transport: Long-polling (Bot API)
- Authentication: Bot token
- Public Port Required: No
- Supports: Text, images, documents, voice messages, video notes
Configuration
Required Settings
Complete Configuration
Environment Variables
You can override configuration with environment variables:Authentication
Getting a Bot Token
- Open Telegram and search for
@BotFather - Send
/newbotand follow the prompts - Copy the bot token (format:
123456789:ABCdefGHIjklMNOpqrsTUVwxyz) - Add the token to your configuration
User Authorization
Pairing Mode (No Allowed Users)
Ifallowed_users is empty, the channel starts in pairing mode:
allowed_users in the config file.
Allowlist Format
Features
Message Splitting
Telegram has a 4096 character limit. ZeroClaw automatically:- Splits long messages at word boundaries
- Prefers splitting at newlines
- Adds continuation markers when needed
- Sends multiple messages sequentially
Streaming Responses
Control how the bot displays responses:partial mode:
- Bot sends initial message
- Edits message as tokens stream in
- Throttled by
draft_update_interval_ms(default: 1000ms)
Acknowledgment Reactions
Whenack_enabled = true (default), the bot reacts to incoming messages with a random emoji:
- ⚡️ (lightning)
- 👌 (ok hand)
- 👀 (eyes)
- 🔥 (fire)
- 👍 (thumbs up)
Group Chat Control
Reply to All Messages
Mention-Only Mode
- Explicitly mentioned:
@your_bot hello - In a 1-on-1 direct message
- Sender is in
allowed_sender_ids
VIP Senders
Interruption Control
Prevent stale responses when users send multiple messages:- Cancels in-flight generation when a new message arrives
- Same sender + same chat only
- Preserves interrupted turn in conversation history
- Restarts generation on newest message
Attachment Support
Incoming Attachments
The bot automatically downloads and processes: Images (converted to[IMAGE:/path] markers):
- PNG, JPG, JPEG, GIF, WebP, BMP
- Up to 20 MB (Telegram API limit)
- Saved to
telegram_files/in workspace
- Saved to
telegram_files/ - Marked as
[Document: name] /path
- OGG/Opus audio
- Transcribed if transcription is enabled
- Otherwise treated as audio file
Outgoing Attachments
Send attachments by using markers in your message:[IMAGE:path]- Send as image[PHOTO:path]- Alias for IMAGE[DOCUMENT:path]- Send as document/file[FILE:path]- Alias for DOCUMENT[VIDEO:path]- Send as video[AUDIO:path]- Send as audio[VOICE:path]- Send as voice message
- Absolute paths:
/full/path/to/file - Workspace-relative:
file.txt→/workspace/file.txt - Explicit workspace:
/workspace/subdir/file.txt
- All paths must be within the configured workspace
- Directory traversal (
../) is blocked - Symlinks are validated
Voice Transcription
Enable voice message transcription:- Voice messages are downloaded
- Audio is sent to transcription provider
- Transcript is injected into message content
- Original audio is preserved in workspace
Thread Support
Telegram group threads are supported:- Incoming
thread_tsis extracted frommessage_thread_id - Replies are sent to the same thread
- Format:
chat_id:thread_id
Tool Approval Prompts
When supervised tools require approval:/approve-allow abc-123-def/approve-deny abc-123-def
Implementation Details
Source Location
src/channels/telegram.rs (1600+ lines)
Key Components
TelegramChannel Struct
Polling Loop
The channel uses long-polling with:- Method:
getUpdateswith offset tracking - Timeout: 30 seconds per request
- Error Handling: Exponential backoff on failures
- Conflict Detection: HTTP 409 indicates duplicate bot instance
Message Processing
- Poll
getUpdatesendpoint - Filter by allowlist (username or user ID)
- Check mention requirements (if in groups)
- Handle special commands (
/bind,/new,/model, etc.) - Download attachments if present
- Convert to
ChannelMessage - Send to agent
API Endpoints Used
| Method | Purpose |
|---|---|
getUpdates | Poll for new messages |
sendMessage | Send text messages |
editMessageText | Edit messages (streaming) |
setMessageReaction | Add emoji reactions |
getFile | Get file path for download |
sendDocument | Send document attachments |
sendPhoto | Send images |
sendVideo | Send videos |
sendAudio | Send audio files |
sendVoice | Send voice messages |
getMe | Get bot username/ID |
setMyCommands | Register bot commands |
Custom API Base URL
For local Bot API servers or testing:https://api.telegram.org
Error Handling
Common Errors
Polling Conflict (409):Error Sanitization
All Telegram API errors are sanitized to remove:- Bot tokens from URLs
- Sensitive authentication headers
- Internal implementation details
/bot<token>/ → /bot[REDACTED]/
Runtime Commands
Available in chat:/new- Start new conversation/model- Show/switch current model/models- Show/switch provider/approve-allow <id>- Approve tool execution/approve-deny <id>- Deny tool execution/bind <code>- Pair account (pairing mode only)
Best Practices
- Secure Your Token: Never commit bot tokens to version control
- Use Allowlists: Start with specific users, not
* - Enable Pairing: Let users self-service authorization
- Group Mode: Use
mention_onlyin public groups - Interruption: Enable for responsive multi-message handling
- ACK Reactions: Keep enabled for user feedback
Troubleshooting
Bot Doesn’t Respond
Check Allowlist:Telegram: ignoring message from unauthorized user:Telegram polling conflict (409):Telegram poll error:
Group Chat Not Working
Bot Not Added:- Add bot to the group
- Grant admin rights if needed
- User ID and username both work
- Check sender identity in logs
Attachments Not Working
Workspace Not Configured: Ensure workspace directory exists and is writable Path Escapes Workspace: All attachment paths must be inside configured workspace File Size Limit: Telegram enforces 20 MB download limit via Bot APIPerformance
Message Throughput
- Polling Interval: 30 seconds (long-polling timeout)
- Batch Size: Up to 100 updates per poll
- Concurrent Processing: One message at a time per sender
Optimization Tips
- Streaming: Use
partialmode for long responses - Edit Throttle: Increase
draft_update_interval_msto reduce API calls - ACK Reactions: Disable if not needed
- Attachment Download: Lazy - only when received
Security
Token Protection
- Tokens are redacted from logs
- Never exposed in error messages
- Stored in config file (protect with file permissions)
User Verification
- Allowlist is checked before any processing
- Pairing codes expire after failed attempts
- Bind commands have rate limiting
Workspace Sandboxing
- All file paths validated against workspace root
- Directory traversal blocked
- Symlink targets validated
- Non-workspace paths rejected