Wednesday, 28 August 2024

How to setup Telegram BOT for notifications

Assume the bot name is my_bot. 1- Add the bot to the group. Go to the group, click on group name, click on Add members, in the searchbox search for your bot like this: @my_bot, select your bot and click add. 2- Send a dummy message to the bot. You can use this example: /my_id @my_bot (I tried a few messages, not all the messages work. The example above works fine. Maybe the message should start with /) 3- Go to following url: https://api.telegram.org/botXXX:YYYY/getUpdates replace XXX:YYYY with your bot token 4- Look for "chat":{"id":-zzzzzzzzzz, -zzzzzzzzzz is your chat id (with the negative sign). 5- Testing: You can test sending a message to the group with a curl: curl -X POST "https://api.telegram.org/botXXX:YYYY/sendMessage" -d "chat_id=-zzzzzzzzzz&text=my sample text" If you miss step 2, there would be no update for the group you are looking for. Also if there are multiple groups, you can look for the group name in the response ("title":"group_name").



You can get a token from https://t.me/BotFather. In order to get the group chat id, do as follows: Add the Telegram BOT to the group. Get the list of updates for your BOT: https://api.telegram.org/bot/getUpdates Ex: https://api.telegram.org/bot123456789:jbd78sadvbdy63d37gda37bd8/getUpdates Look for the "chat" object: { "update_id": 8393, "message": { "message_id": 3, "from": { "id": 7474, "first_name": "AAA" }, "chat": { "id": , "title": "" }, "date": 25497, "new_chat_participant": { "id": 71, "first_name": "NAME", "username": "YOUR_BOT_NAME" } } } This is a sample of the response when you add your BOT into a group. Use the "id" of the "chat" object to send your messages. (If you created the new group with the bot and you only get {"ok":true,"result":[]}, remove and add the bot again to the group) Private chart only works in image argoprojlabs/argocd-notifications:v1.1.0 or above.

No comments:

Post a Comment