Configure telegram as notification using API in group. In VMware solutions, these can be used as event based alerting for VEBA or vROPS or VRLI
Summary tasks:
- Configure Bot
- Telegram group for notification
- Sent message using API
Configure BotFather
- chat with botfather
- command newbot. For this lab, I use teddyalert1bot as botname. I purposely modify the API access.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23teddy setiawan, [29 Jan 2021 16.29.35]:
/newbot
BotFather, [29 Jan 2021 16.29.35]:
Alright, a new bot. How are we going to call it? Please choose a name for your bot.
teddy setiawan, [29 Jan 2021 16.30.08]:
teddyaler1tbot
BotFather, [29 Jan 2021 16.30.08]:
Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: TetrisBot or tetris_bot.
teddy setiawan, [29 Jan 2021 16.30.24]:
teddyalert1bot
BotFather, [29 Jan 2021 16.30.25]:
Done! Congratulations on your new bot. You will find it at t.me/teddyalert1bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this.
Use this token to access the HTTP API:
1605817578:AAFv7kfczLJ29hRmCQ0Jv1yA5J6RR4TEDDY
Keep your token secure and store it safely, it can be used by anyone to control your bot.
For a description of the Bot API, see this page: https://core.telegram.org/bots/api
Telegram group
- Create telegram group
- Include our newly create bot into this group.
- Use REST API to check group chat ID. The url to get update response from telegram: https://api.telegram.org/botTOKEN API/getUpdates
If the response empty, try to sent chat message to the target group.Find the telegram group with property “title”.
1 | curl -v https://api.telegram.org/bot1605817578:AAFv7kfczLJ29hRmCQ0Jv1yA5J6RR4TEDDY/getUpdates |
In above example, the group chat id = -587481951
Sent message using API
to sent simple message, use URL: https://api.telegram.org/botTOKENAPI/sendMessage?chat_id=-GROUPID&text=chatmessage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22curl -v https://api.telegram.org/bot1605817578:AAFv7kfczLJ29hRmCQ0Jv1yA5J6RR4TEDDY/sendMessage?chat_id=-587481951&text=hohoho
{
"ok": true,
"result": {
"message_id": 3,
"from": {
"id": 1605817578,
"is_bot": true,
"first_name": "teddyaler1tbot",
"username": "teddyalert1bot"
},
"chat": {
"id": -587481951,
"title": "teddyaler1",
"type": "group",
"all_members_are_administrators": true
},
"date": 1611915159,
"text": "hohoho"
}
}verify the message in group