Telegram Alert Channel configuration

Hi folks, get updated to latest 4.2 release and trying to get Alerts through new Telegram Alert Channel.
There is nothing written in docs and even no information about Telegram: http://docs.grafana.org/alerting/notifications/
So what I did already:

  1. Created a bot via @BotFather, got an API token
  2. Created a group chat and invited the Bot to the channel
    There is to parameters in Telegram Notification Channel options:
  • BOT API Token (Got)

  • Chat ID (???)
    So I have no idea what to type in field named “Chat ID”: tried my @user_name and created channel name with “@” in begining - but nothing works. In Grafana log got this lines:

    мар 24 15:01:44 grafana grafana-server[11223]: t=2017-03-24T15:01:44+0300 lvl=info msg=“Sending notification” logger=alerting.notifier type=telegram id=0 isDefault=false
    мар 24 15:01:44 grafana grafana-server[11223]: t=2017-03-24T15:01:44+0300 lvl=info msg=“Sending alert notification to” logger=alerting.notifier.telegram bot_token=bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
    мар 24 15:01:44 grafana grafana-server[11223]: t=2017-03-24T15:01:44+0300 lvl=info msg=“Sending alert notification to” logger=alerting.notifier.telegram chat_id=@user_name
    мар 24 15:01:44 grafana grafana-server[11223]: t=2017-03-24T15:01:44+0300 lvl=eror msg=“Failed to send webhook” logger=alerting.notifier.telegram error=“Webhook response status 400 Bad Request” webhook="Telegram Alert"
    мар 24 15:01:44 grafana grafana-server[11223]: t=2017-03-24T15:01:44+0300 lvl=eror msg=“Failed to send alert notifications” logger=context userId=1 orgId=1 uname=admin error="Webhook response status 400 Bad Request"
    мар 24 15:01:44 grafana grafana-server[11223]: t=2017-03-24T15:01:44+0300 lvl=eror msg=“Request Completed” logger=context userId=1 orgId=1 uname=admin method=POST path=/api/alert-notifications/test status=500 remote_addr=“CLASSIFIED_IP, CLASSIFIED_PROXY” time_ms=633ns size=48

So I found how it works!!!
0. After bot creation via @BotFather in Telegram App you get the Bot API Token

  1. First thing you need is to create new Chat Group in Telegram App, for example: “Super Dooper Alert Group” with people who need to be alerted.
  2. Invite your bot to this group
  3. Use cURL or just place this on any Browsers Address Bar: https://api.telegram.org/bot<TOKEN>/getUpdates
  4. Previous step should return JSON object, you need to find key “chat” like this one:
    "chat":{"id":-456343576,"title":"Super Dooper Alert Group","type":"group","all_members_are_administrators":true}
  5. You need that number: -456343576 - just place it in according fielld after Bot API Token in Telegram Channel configuration page - and thats all!!!
1 Like

Thanks for describing the flow. We’ll add this to the documentation.

I put that address in with the token and this is all i get in the browser:
{“ok”:true,“result”:[]}

@pdizzle You have to send at least one message using the chatroom. Then you should get a valid JSON.

1 Like

Ok, guys I can’t make it work. I get “permision denied” on the save or test message.

I have a bot ID.
516282135:AAFgnSkeg-9tuxxklne5U-Y4k_Hi_LAWXCw

Do I Enter it with the “bot” prefix in the “bot api token” field or without? Neither seems to work.

Also For the chat ID: I have created chat with the bot. But cant figure out the id of the chat. is it 150887337?

Any Ideas TIA

@rpi-openhab3:~$ curl https://api.telegram.org/bot516282135:AAFgnSkeg-9tuxxklne5U-Y4k_Hi_LAWXCw/getUpdates {"ok":true,"result":[{"update_id":852422248, "message":{"message_id":2,"from":{"id":150887337,"is_bot":false,"first_name":"Maciej","last_name":"E"},"chat":{"id":150887337,"first_name":"Maciej","last_name":"E","type":"private"},"date":1516535600,"text":"/start","entities":[{"offset":0,"length":6,"type":"bot_command"}]}},{"update_id":852422249, "message":{"message_id":3,"from":{"id":150887337,"is_bot":false,"first_name":"Maciej","last_name":"E","language_code":"en-US"},"chat":{"id":150887337,"first_name":"Maciej","last_name":"E","type":"private"},"date":1516536675,"text":"Test"}},{"update_id":852422250, "message":{"message_id":4,"from":{"id":150887337,"is_bot":false,"first_name":"Maciej","last_name":"E","language_code":"en-US"},"chat":{"id":150887337,"first_name":"Maciej","last_name":"E","type":"private"},"date":1516537148,"text":"test"}},{"update_id":852422251, "message":{"message_id":5,"from":{"id":150887337,"is_bot":false,"first_name":"Maciej","last_name":"E","language_code":"en-US"},"chat":{"id":150887337,"first_name":"Maciej","last_name":"E","type":"private"},"date":1516537729,"text":"/help","entities":[{"offset":0,"length":5,"type":"bot_command"}]}},{"update_id":852422252, "message":{"message_id":6,"from":{"id":150887337,"is_bot":false,"first_name":"Maciej","last_name":"E","language_code":"en-US"},"chat":{"id":150887337,"first_name":"Maciej","last_name":"E","type":"private"},"date":1516537738,"text":"/start","entities":[{"offset":0,"length":6,"type":"bot_command"}]}},{"update_id":852422253, "message":{"message_id":7,"from":{"id":150887337,"is_bot":false,"first_name":"Maciej","last_name":"E","language_code":"en-US"},"chat":{"id":150887337,"first_name":"Maciej","last_name":"E","type":"private"},"date":1516537753,"text":"/post","entities":[{"offset":0,"length":5,"type":"bot_command"}]}}]}[13:48:10] openhabian@rpi-openhab3:~$

Never mind, it was grafana login issue. got it working
BTW You need to enter the bot ID without bot prefix

Ok so I upgraded to 5.0.4 from 4.x and now you need a bot prefix in the grafana bot token setup

Chat ID:

  1. Go to https://web.telegram.org
  2. Go to your Group and find your link (URL) of Group like (https://web.telegram.org/#/im?p=g123456789)
  3. Copy that number after g and put a (-) before that -123456789

And, yes, Telegram supports images:

all i get {“ok”:true,“result”:[]}
can be a little more detail ??

Hi, setting up to send message to Group work but all users can send message to group. I would like that only Grafana, so the BOT, can send message to Group.
Setting permission on Group it becomes a SuperGroup and the using the s1234567 number it not work…
It’s possible send alerts to multiple Users?
Can I to set Grafana to send message to a more chat_id?

Thanks