Telegram
Enable SurfSense chat from Telegram
Telegram Messaging Channel
Telegram lets users chat with the SurfSense agent from a Telegram bot. Users pair their Telegram chat from User Settings > Messaging Channels.
Environment Variables
For Docker installs, add these to docker/.env. For manual installs, add them to
surfsense_backend/.env.
TELEGRAM_SHARED_BOT_TOKEN=123456:bot-token-from-botfather
TELEGRAM_SHARED_BOT_USERNAME=your_bot_username
TELEGRAM_WEBHOOK_SECRET=generate-a-long-random-secret
GATEWAY_BASE_URL=https://api.example.com
GATEWAY_TELEGRAM_INTAKE_MODE=webhookTELEGRAM_WEBHOOK_SECRET must be 1-256 characters and contain only A-Z, a-z,
0-9, _, or -.
Intake Modes
| Mode | Use when |
|---|---|
webhook | Production or any deployment with a public HTTPS backend URL |
longpoll | Single-replica self-host installs that cannot expose a public HTTPS webhook |
disabled | You do not want Telegram intake enabled |
For SaaS-style or multi-replica deployments, use webhook. Long polling should
only run in a single backend process.
Webhook URL
Telegram webhooks use this shape:
${GATEWAY_BASE_URL}/api/v1/gateway/webhooks/telegram/{account_id}After deploying the backend, register the webhook:
cd surfsense_backend
uv run python scripts/register_webhook.pyIf switching a bot from long polling to webhooks, delete any existing Telegram
webhook or pending getUpdates session before relying on the new mode.
Pairing Flow
- The user opens User Settings > Messaging Channels.
- The user starts Telegram pairing.
- SurfSense provides a pairing code or bot link.
- The user sends the pairing command to the Telegram bot.
- SurfSense binds that Telegram chat to the selected search space.
