← Back to blog

Telegram alerts in two taps — why we run the bot so you don't have to make one

2026-11-30

engineeringalerting

The usual way to get Telegram alerts from a monitoring tool: message @BotFather, run /newbot, copy the token it gives you into the tool, then work out your chat ID and paste that too. It works, but it's five minutes of setup in another product before your first alert, and a bot token sitting in a settings field.

okokumo runs one bot for every customer instead. You create a Telegram channel, press Connect Telegram, then press Start. This post covers what happens during those two taps, what we keep afterwards, and what someone who gets hold of your connect link can do with it.

The two taps

  1. In Alert channels, choose New channel → Telegram and press Create. There's nothing to fill in. The server generates a random one-time token (16 bytes, shown as 32 hex characters) and saves the channel with that token and no destination. The channel is listed as pending.

  2. Press Connect Telegram. It's a link to https://t.me/<our bot>?start=<token>, built on the server from the bot's username and your token. If you close the tab halfway through, the link is still on the channel row. Links expire after 24 hours; the Alert channels page swaps in a fresh one whenever it loads and the old one has expired or has less than an hour left.

  3. Telegram opens a chat with the bot. Press Start. Telegram sends /start <token> to the bot, which forwards it to our webhook.

  4. The webhook finds the channel whose token matches, records the chat ID, marks the channel validated and removes the token, all in a single write. Then it posts a confirmation in the chat, with the first line in bold:

    ✅ Connected to Okokumo
    Alerts sent to the “<channel name>” channel will arrive in this chat.
    

The channel row now shows the chat by name: a group's title, otherwise your @username, otherwise your first name. That's the only way to tell several Telegram channels apart in the dashboard.

The Connect Telegram link opens a private chat with the bot. To send alerts to a group, press Connect a group instead. That link is https://t.me/<our bot>?startgroup=<token>, with the same token. According to Telegram's deep-linking docs, Telegram asks which group to add the bot to, adds it, and sends the bot /start@<bot username> <token> from that group. The webhook accepts that form and binds whichever chat the command came from, so the stored chat ID is the group's. We haven't yet run this end to end against our live bot, and we don't know whether Telegram sends the command again when the bot is already in the group. If no confirmation shows up, type /start@<bot username> <token> in the group yourself (the token is the part after start= in the Connect Telegram link). The webhook handles that the same way.

What a stolen connect link can and can't do

Pressing Start proves two things: you have the token, and you control the chat it was sent from. Email channels get the same proof from a clicked confirmation link. So it's worth being exact about the token.

Once your chat is connected, the link is dead. Binding clears the token in the same write that stores the chat ID. A second /start with the same token matches no channel, and the webhook drops it. If the link was pasted in a team group, or sits in someone's browser history, nobody can use it later to point your alerts at a different chat.

Before you press Start, the link is live for 24 hours. The token expires 24 hours after it was generated, and earlier if a chat uses it or you delete the channel. An expired or replaced link binds nothing. What the bot says depends on whether the channel still holds that token. Okokumo swaps in a new link whenever it lists your channels (the Alert channels page, the Checks pages, the API or the MCP server) and the old one has expired or has less than an hour left. If that hasn't happened since your link expired, the bot replies that it has expired and points you to Alert channels. If it has, the old token matches nothing and the bot stays silent. Either way, reload Alert channels and use the link it shows. Within those 24 hours, if somebody else follows your link and presses Start before you do, their chat gets bound to your channel and receives your alerts. You'd see it in the dashboard, because the row shows their name instead of yours. To fix that, delete the channel and create a new one: deleting it forgets the chat and kills its link. If you send some checks only to that channel, add the new one to them. Editing a Telegram channel only changes its name. The chat stays connected, so a rename doesn't pause your alerts. Treat an unused connect link the way you'd treat an invite link.

Nobody can fake the Start. The webhook address has to be public, since Telegram calls it. The handler rejects every request that doesn't carry the secret we set when we registered the webhook, which Telegram sends in the X-Telegram-Bot-Api-Secret-Token header. Without that header it answers 401 and binds nothing. If the deployment has no secret configured, it rejects everything.

A link gives no access to okokumo. Every alert includes a link to the check in the dashboard. Opening that link still means signing in.

What we store, and what we read

For a connected channel we store the chat ID and the chat's display label. We don't store a bot token of yours, because you never made one.

Telegram only sends our webhook updates addressed to our bot. The handler reads one thing from each: whether the text is /start followed by exactly one token. Everything else, whether a bare /start, "hello" or malformed JSON, gets a 200 and is otherwise ignored. The 200 is on purpose: Telegram keeps redelivering anything that doesn't get a 2xx. Whatever else you type to the bot is not stored. We can't speak for what Telegram itself keeps. That's between you and Telegram.

What an alert looks like

Alerts are written for a phone's lock screen, so the first line says what broke. Here's a failing nightly backup that reported its error with a /fail ping, as it arrives in Telegram (the first line is bold):

🔴 Down: nightly pg_dump <prod> & rotate
up → down
The job reported a failure
2026-11-30T03:12:04Z
https://app.okokumo.com/checks/…
pg_dump: error: connection to server at "10.0.0.5", port 5432 failed:
FATAL:  password authentication failed for user "backup"

The lines are: status and check name; the state change; the reason; the checked URL, for HTTP checks; the time in UTC; the dashboard link; and, on a down alert only, the job's own output in a monospace block. A recovery starts with 🟢 Recovered, and the job output is left out.

The check name in that example contains <, > and & on purpose. We send alerts with Telegram's HTML parse mode, and the code comment gives the reason: Telegram's legacy Markdown mode "chokes on underscores and brackets, which appear in real check names and URLs". HTML mode has three reserved characters, and every field we put in the message is escaped for them: the name, reason, URL and job output. So what actually goes over the wire is <b>Down: nightly pg_dump &lt;prod&gt; &amp; rotate</b>. Without the escaping, Telegram doesn't render the name oddly. It rejects the message with a 400, and you'd get no alert at all.

Long job output

okokumo keeps up to 10 KB of the output a job sends with a /fail ping. Telegram rejects any message longer than 4,096 characters, so the job output gets whatever room the rest of the alert leaves. The rest of the alert is never dropped to make room.

If the output doesn't fit, we cut the middle, not the end: a job's log usually ends with why it failed. The alert keeps a short piece of the beginning, which tends to say what was running, then a line with …, then the end of the output, which gets three quarters of the room. Escaping can make text longer (one & becomes five characters), so the code measures the escaped result and searches for the largest cut that still fits. Output full of & and < therefore shows fewer of its own characters, but the message still fills close to the limit. Slack and Discord alerts cut job output the same way, at their own limits.

The full stored output is on the check's page in the dashboard, kept for 30 days.

When Telegram says no

If you block the bot, or the chat no longer exists, Telegram refuses the send with a 4xx error. We don't retry those, since sending the same request again gets the same answer. The failure goes into the check's delivery log with Telegram's status code and its error text, so a missing alert has an explanation you can read. The channel stays connected, so later alerts are tried and logged too. Unblock the bot, or replace the channel with a new one and connect a new chat. 5xx errors and network failures are retried twice, after 1 and 3 seconds.

Telegram sits next to email, Slack, Discord and signed webhooks on the alerting page, and you can route each check to the channels you choose.