Telegram Bot Integration
File: assistant/telegram.go (172 lines)
Active Telegram bot integration for the assistant framework. The Telegram notifier implements interfaces.Notifier and provides full message routing with RBAC, smart triggers, and platform tracking.
Architecture
StartTelegramBot(token)
↓
tgbotapi.NewBotAPI(token) → authenticate
↓
Register TelegramNotifier with interfaces.SetTelegramNotifier()
↓
Poll for updates (60s timeout)
↓
For each message:
ProcessTelegramMessage()
→ RBAC lookup (GetContactByTelegramID / GetContactByTelegramUsername)
→ Smart trigger check (ShouldTriggerAI)
→ Group vs DM detection
→ QueryAssistantWithOptions()
→ Send response via Telegram
Key Functions
| Function | Purpose |
|---|---|
StartTelegramBot(token) |
Initialize bot, register notifier, start update loop |
ProcessTelegramMessage() |
Full message pipeline with RBAC, routing, response |
SendMessage() |
Send text with Markdown formatting (fallback to plain text) |
SendAudio() |
Not implemented (returns error) |
SendImage() |
Not implemented (returns error) |
SendEmail() |
Not supported via Telegram |
Features
- RBAC Integration: Maps Telegram users to roles via
GetContactByTelegramIDandGetContactByTelegramUsername - Smart Trigger: Checks
ShouldTriggerAIto determine if agent response is needed - Group Handling: In group chats, only responds when @mentioned or triggered
- Markdown Support: Messages sent with Markdown parse mode, with automatic fallback to plain text
- Typing Indicator: Sends chat action "typing" while agent processes
- Platform Tracking:
opts.Platform = "telegram"for platform-aware routing - Status Flag:
floatingvariables.GlobalTelegramStatustracks bot availability
Status
Active and fully operational (unlike slack.go which is a ghost framework with all functions commented out).
See also: Architecture