Skip to content

Instantly share code, notes, and snippets.

@dl6nm
Forked from subzeta/gist:26cd1a1f1526411862b3a3a0b4422d3d
Last active December 13, 2023 16:21
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dl6nm/c312acbc6fddf1a56d749e045f040ca3 to your computer and use it in GitHub Desktop.
Save dl6nm/c312acbc6fddf1a56d749e045f040ca3 to your computer and use it in GitHub Desktop.
How to create a Grafana bot for Telegram

Set up a Telegram Bot

  1. Go to Grafana > Alerting > Notification channels > New channel.
  2. Type: Telegram. It will ask you for a Bot API Token and a Chat ID.
  3. Open a chat with BotFather on Telegram.
  4. Type /newbot
  5. Type your bots name. e.g. Grafana Bot
  6. Type your bots username. e.g. a_new_grafana_bot
  7. You get your Bot API Token. Paste it on Grafana.
  8. Before making getUpdates (in the next step) you should add your bot into your telegram client and run /start. Thus you start chatting with the bot and this room is assigned chat id. (Thanks to @KES777)
  9. Open this URL address, substituing YOUR_API_TOKEN_KEY with yours: https://api.telegram.org/bot<YOUR_API_TOKEN_KEY>/getUpdates
  10. The response may look like this: {"ok":true,"result":[{"update_id":BLA_BLA_BLA", chat":{"id":[CHAT_ID],"title".... Copy that CHAT_ID, even with the minus sign.
  11. Paste it on Grafana.
  12. Test it click on Send Test. You can test it using Telegram API too, just substitute the parameters with your API Token and Chat ID: https://api.telegram.org/botYOUR_API_TOKEN/sendMessage?chat_id=YOUR_CHAT_ID&text=a_message

Links

@jongkwang
Copy link

Thank you for the post.
We have cited your article as a help to our project.

https://github.com/dsrvlabs/mina-performance-dashboard

@kevinschweikert
Copy link

You have to send a message/open the chat to the bot in order to create the chat id

@missoneturn
Copy link

image
i got this message when i do step no 8. it's this correct?

@dl6nm
Copy link
Author

dl6nm commented Jun 16, 2021

No this isn't correct. You have to replace <YOUR_API_TOKEN_KEY> in the URL by your Bot API Token from step 7.
If your token for example is 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11, then the URL should look something like:

https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getUpdates

@crabvk
Copy link

crabvk commented Feb 17, 2022

Is this instruction outdated? I have no Notification channels in Grafana 8.3.6

Screenshot

UPD
Fixed with disabling so called "Unified alerting"

[unified_alerting]
enabled = false

@KES777
Copy link

KES777 commented Feb 18, 2022

I have next response: {"ok":true,"result":[]}

Before making getUpdates you should add your bot into your telegram client and run /start. Thus you start chatting with bot and this room is assigned chat id.

@ianaz
Copy link

ianaz commented Sep 26, 2022

Thanks @KES777 this worked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment