Overview
OpenSRE’s Telegram integration delivers investigation findings to any chat your bot has been added to — useful for mobile-first on-call rotations and personal alerting. With the gateway running, you can also DM the agent for two-way chat. Start the interactive shell withopensre (no subcommand). Slash commands below are run from that REPL.
Prerequisites
- A Telegram account.
- The Telegram mobile or desktop app, signed in.
- The chat (group, channel, or direct message) where you want to receive findings.
Setup
Option 1: Onboarding wizard (recommended)
/onboard or /integrations setup telegram.
Choose Telegram. The wizard prompts for:
- Bot token (required) — stored as
TELEGRAM_BOT_TOKENin.envand~/.opensre/credentials.json - Default chat ID or
@channelname(required) — written to.envasTELEGRAM_DEFAULT_CHAT_ID
~/.opensre/integrations.json via upsert_integration("telegram", ...).
Both answers are checked before anything is saved, so a wrong token or a chat the bot was never added to fails here rather than silently at the first alert.
Setup confirms the bot can see the chat, not that it may post there. For a channel the bot still needs the Post Messages permission.
Option 2: Environment variables
Credential resolution. Every Telegram delivery surface — investigations, background RCA completion notifications, the scheduler,
/watchdog, /hermes watch, and /watch — resolves the bot token the same way: integration store first, then resolve_env_credential("TELEGRAM_BOT_TOKEN") (process env, then the credentials file). Chat id is non-secret: --chat-id → store default_chat_id → TELEGRAM_DEFAULT_CHAT_ID env (plain os.getenv).Credentials
Create a bot with BotFather
BotFather is Telegram’s official bot for creating other bots.- Open Telegram and search for
@BotFather. Open the chat and tap Start. - Send
/newbot. - When prompted, send a display name for your bot (e.g.
OpenSRE Alerts). - Send a username that ends in
bot(e.g.opensre_alerts_bot). It must be globally unique. - BotFather replies with an HTTP API token of the form
<numeric-id>:<token-secret>. Copy it — treat it like a password.
Add the bot to a chat
- Group chat
- Channel
- Direct message
- Open the group where you want findings to land.
- Tap the group name → Add members → search for your bot username → Add.
- By default, bots in groups only see messages addressed to them, which is fine for delivery-only.
Find your chat_id
The chat ID identifies where the bot should post. It is required — without it the bot has nowhere to send anything.
-
Send any message in the destination chat — for a channel, post anything; for a DM, send
/startto your bot. -
In a browser, open:
-
In the JSON response, look for a
chat.idfield:Copy the entire value, including the leading minus sign for groups and channels.
If
getUpdates returns an empty array, post a fresh message in the chat and reload — Telegram only buffers recent updates.Investigation tools
resolve_env_credential("TELEGRAM_BOT_TOKEN") (env then keyring). If chat_id is omitted, it sends through the configured default_chat_id.
Delivery is an external side effect. Its result includes a stable status, sent, error_type, chat_id, reply_to_message_id, and message_length shape so follow-up tool calls can tell configuration failures from Telegram delivery failures.
Two-way chat gateway (DM text)
Skip this if you only need outbound delivery (alerts, cron reports, investigation findings). Setup + verify are sufficient for that.v1 supports text-only direct messages (no groups, voice, or attachments).
Allow your Telegram user
Find your numeric user id with @userinfobot, then:/messaging allow -p telegram -u 123456789.
DM pairing (optional)
/pair <code>.
Start the gateway daemon
Also available in the REPL via
/gateway start|status|logs|stop.
Logs: ~/.opensre/gateway/gateway.log. If Telegram is not configured the daemon still runs the other components and status shows telegram: not configured.
The gateway uses long polling — no public HTTPS URL or port forwarding is required for local use. Built-in commands: /new, /help, /pair <code>.
The gateway uses the same headless agent harness as the interactive shell, with Telegram-specific wiring:
- Prompt grounding — CLI reference, AGENTS.md, integration list, and investigation flow context
- Read-only evidence tools — live integration queries via the gather pass when integrations are configured
- Action tools —
shell_runandinvestigation_start
Deploying the gateway to a remote host
Running the gateway on a server withmake deploy-gateway (EC2) is different from local use: the remote host cannot read your local machine’s keychain. Guided setup stores the bot token (and your LLM API key) in the system keyring, which does not travel to the deployed instance.
So make deploy-gateway validates that the required secrets are present as plaintext env vars in .env:
MISSING: TELEGRAM_BOT_TOKEN even though local setup succeeded, copy the values into .env (or .env.deploy.example) for the deploy.
Scheduled, background, and watchdog delivery
Background investigation completion (RCA)
Configure Telegram first (setup + verify — the gateway is not required), then:/background show <task_id>. A notification problem never fails the investigation itself. See Background investigations.
Cron (recurring reports)
Watchdog (process threshold alarms)
/watch, /watches, /unwatch, /watchdog.
Hermes incident escalation
Verify
/integrations verify telegram or /verify telegram.
This calls Telegram’s getMe endpoint. On success it reports the bot @username. It does not start a listening process and does not test two-way communication or delivery chat routing.
Delivery test:
Troubleshooting
Verify only callsgetMe, so it surfaces token-validity errors but cannot detect chat-routing problems. Delivery-time errors appear in OpenSRE logs as [telegram] post message failed: <description>.
Security
- Treat the bot token like a password; prefer
~/.opensre/credentials.json. - Use numeric user ids on the allow-list — never
@username. - Prefer a dedicated bot for OpenSRE.
- For remote deploy, put secrets in plaintext
.envon the host (keyring does not travel). - Store secrets out of source control.