How to create Telegram Bot and get chat ID

by Daniel Pham
Published: Updated:
This entry is part 9 of 14 in the series Install Prometheus and Grafana on Ubuntu 18

In this article, I will guide you how to create a Telegram Bot and get chat ID. You are writing this to help you set up Alertmanager Telegram bot.

Note: every action you perform on Telegram web.

How to create Telegram Bot

To create a new bot, first, in the search box, type in BotFather.

How to create Telegram Bot and get chat ID
Find BotFather in Telegram and create a telegram bot.

In the chat window with BotFather, type:

/start

Next you type:

/newbot

Next, you will name your bot. For example: alertmanagerBot. You type:

alertmanagerBot

Then you need to set a username for your bot. The username will end with the word _bot. You type:

alertmanagerBot_bot

After this step, BotFather will send you a token that looks like the one below.

xxxxxxxxxx:t4HhZjSk9LznjPkFPw4b6cZL8XQ9ETNALZr

You need to save it to use in the /etc/telegrambot/config.yaml file (content in the article I linked at the beginning of the article).

Find user ID in Telegram

Now you need to find the user ID in your Telegram. The purpose will be clear to you in the next step.

In the search box, type in userinfobot.

How to create Telegram Bot and get chat ID
Find userinfobot in Telegram.

In the chat window with userinfobot, type:

/start

Userinfobot will send you back information like below. The xxxxxxxxxx range is your user ID number.

Id: xxxxxxxxxx
First: DevOpsLite
Last: dotCom

How to get chat ID in Telegram

This is the second most important part, in addition to the Token you have above. You will need the chat ID so the alertmanager can send alerts via telegram bot.

To get the chat ID, create any new room and add your bot. Note that you add the bot you created above to the room. In the example, I will add a bot named alertmanagerBot.

Now in the chat room you just created. You type the command with the following syntax:

/user-ID @botusername

For example:

/xxxxxxxxxx @alertmanagerBot_bot

The bot will send you a message with the following content:

Chat id is '-yyyyyyyyy'

Now, you can use this chat ID in /etc/alertmanager/alertmanager.yml file.

Conclusion

So I have guided you step by step to create a bot in Telegram and get chat ID. With the bot token and chat ID, you can configure alertmanager to send alert messages to your Telegram room. Good luck.

Install Prometheus and Grafana on Ubuntu 18

Alertmanager sends alerts with Telegram bot How to delete old targets in Prometheus database
0 0 votes
Article Rating

You may also like

Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

0
Would love your thoughts, please comment.x
()
x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.