Skip to content

feat: Telegram bot integration — per-agent bots with media support (#216) - #234

Merged
vybe merged 1 commit into
mainfrom
feature/216-telegram-bot-integration
Mar 31, 2026
Merged

vybe merged 1 commit into
mainfrom
feature/216-telegram-bot-integration

Conversation

@vybe

@vybe vybe commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Phase 0: Generalized ChannelMessageRouter — replaced 6 Slack-specific hardcodings with adapter method calls (channel_type, get_rate_key, get_session_identifier, get_source_identifier, get_bot_token). Zero behavior change for existing Slack users.
  • Phase 1: Added Telegram as a clean, separate module — TelegramAdapter, webhook transport, encrypted bot token storage (AES-256-GCM), media download with SSRF prevention, API endpoints with owner-gated auth, bot commands (/start, /help, /reset), HTML response formatting with 4096-char splitting, and webhook reconciliation on startup.
  • No new Python dependencies (httpx only). No polling transport — webhook-only.

Changes

  • src/backend/adapters/base.py — 5 new abstract methods on ChannelAdapter
  • src/backend/adapters/message_router.py — Generalized router, removed Slack helpers
  • src/backend/adapters/slack_adapter.py — Backward-compatible method overrides
  • src/backend/adapters/telegram_adapter.py — NEW TelegramAdapter
  • src/backend/adapters/transports/telegram_webhook.py — NEW Webhook transport
  • src/backend/db/telegram_channels.py — NEW DB operations (encrypted tokens)
  • src/backend/db/migrations.py — telegram_bindings + telegram_chat_links tables
  • src/backend/routers/telegram.py — NEW 5 API endpoints (webhook + CRUD + test)
  • src/backend/services/telegram_media.py — NEW Media download with SSRF prevention
  • src/backend/database.py — Telegram delegation methods
  • src/backend/main.py — Router registration, transport startup, shutdown hook

Security

  • Bot tokens AES-256-GCM encrypted at rest
  • Webhook auth via X-Telegram-Bot-Api-Secret-Token header
  • SSRF prevention: media downloads restricted to api.telegram.org
  • Owner-gated endpoints via OwnedAgentByName dependency
  • Restricted tools for Telegram users (WebSearch, WebFetch)
  • /cso --diff audit: 0 findings above 8/10 confidence gate

Test Plan

  • Configure a Telegram bot via PUT /api/agents/{name}/telegram with a valid BotFather token
  • Send a text message to the bot → agent responds in HTML
  • Send /start, /help, /reset commands → correct responses
  • Send a photo/document → context extracted and passed to agent
  • Verify webhook receives updates and processes async
  • Verify bot token is encrypted in DB (not plaintext)
  • Verify non-owner cannot PUT/DELETE another user's binding (403)
  • Verify Slack integration still works unchanged

Closes #216

🤖 Generated with Claude Code

)

Phase 0: Generalize ChannelMessageRouter — replace 6 Slack-specific
hardcodings with adapter method calls (channel_type, get_rate_key,
get_session_identifier, get_source_identifier, get_bot_token). Zero
behavior change for existing Slack users.

Phase 1: Add Telegram as a clean, separate module — TelegramAdapter,
webhook transport, encrypted bot token storage, media download with
SSRF prevention, API endpoints with owner-gated auth, bot commands
(/start, /help, /reset), HTML response formatting with 4096-char
splitting, and webhook reconciliation on startup.

Closes #216

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@vybe
vybe merged commit 1babe9f into main Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram Bot Integration — per-agent bots with media, public link sharing

1 participant