Alerts in Telegram

On this page

Alerts in Telegram

A Telegram channel in BxLens sends alerts and reports to a chat, a group or a Telegram channel through a bot that you make. It needs BoxLang+.

1. Make the bot

  1. In Telegram, open a chat with @BotFather and send /newbot.
  2. Choose a name and a user name that ends in bot (for example acme_bxlens_bot).
  3. BotFather answers with the bot token, which looks like 123456789:AAH.... Anyone who has it controls the bot, so treat it like a password.

2. Find the chat id

  • A chat with you: open the chat with your bot and press Start (a bot cannot write to you before that), then send it any message. Open https://api.telegram.org/bot<token>/getUpdates in a browser, with your token, and read message.chat.id. It is a number such as 123456789.
  • A group: add the bot to the group, send a message in it and read getUpdates the same way. The id is negative, such as -1001234567890.
  • A Telegram channel: add the bot as an administrator who may post. A public channel can use its name, @yourchannel. A private one has an id that starts with -100.

The chat id is not a secret and is kept with the other settings.

3. Add the channel in BxLens

  1. Open Settings, Notifications, Channels and press + Add channel.
  2. Choose Telegram, give it a name, paste the bot token (write only, stored encrypted, never shown again) and enter the chat id.
  3. Choose the alerts, the lowest severity and the reports, press Save, then Send test.

What the message looks like

Bold heading with an icon (a red circle for critical, an orange one for a warning, a check mark for resolved), the server, severity and time, the sentence that says what is wrong, the facts, and an Open in BxLens link when console.publicUrl is set. The message is sent with parse_mode HTML, so BxLens escapes &, < and > in all text from your servers. The text is at most 4096 characters; a longer one is cut with three dots before it is escaped.

Good to know

  • BxLens calls https://api.telegram.org/bot<token>/sendMessage and nothing else. The host cannot be changed.
  • The token is part of that address, so it is never put in a log line, an error message or the audit log.
  • Telegram answers 429 when you send too many messages to one chat. BxLens tries again after 5 minutes and sends at most maxPerHour messages an hour to a channel.
  • If Telegram says chat not found, the bot has not been started in that chat or the id is wrong.

See Notifications for how alerts are routed.