You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -33,6 +33,7 @@ const telegramChannel = new TelegramAlertChannel('my-telegramchannel-1', {
33
33
name: 'My Telegram channel',
34
34
apiKey: 'xxxxxx',
35
35
chatId: 'xxxxxx',
36
+
messageThreadId: '42',
36
37
sendRecovery: true,
37
38
sendFailure: true,
38
39
sendDegraded: true,
@@ -43,6 +44,10 @@ const telegramChannel = new TelegramAlertChannel('my-telegramchannel-1', {
43
44
44
45
</CodeGroup>
45
46
47
+
<Note>
48
+
`messageThreadId` requires Checkly CLI 8.18.0 or later.
49
+
</Note>
50
+
46
51
<Note>
47
52
If you need to reference existing alert channels that were created outside of your CLI project, use [`fromId()`](/constructs/alert-channel#using-fromid-to-reference-an-existing-channel).
48
53
</Note>
@@ -63,6 +68,10 @@ The API key associated with your Telegram bot.
63
68
The chat ID of the Telegram channel you want to send alerts to.
The positive integer Message Thread ID of a Telegram forum topic. Use it together with `chatId` to send alerts to a specific topic.
73
+
</ResponseField>
74
+
66
75
<ResponseFieldname="payload"type="string">
67
76
The message sent to the chat when an alert is triggered. If this is not specified, we'll send a default payload with some basic information about the alert.
Checkly integrates with [Telegram](https://telegram.org/) and can
9
-
deliver failure, degradation, and recovery messages to any chat (direct or groups). You can add as many Telegram chats as you wish.
10
-
To enable the Telegram alert channel, you'll need two things:
8
+
Checkly integrates with [Telegram](https://telegram.org/) and can
9
+
deliver failure, degradation, and recovery messages to direct chats, groups, and forum topics. You can add as many Telegram chats as you wish.
11
10
12
-
1. Your own Telegram bot and its associated HTTP API Token
13
-
2. Your own Telegram user's Chat ID
11
+
<Accordiontitle="Prerequisites">
12
+
13
+
- A Telegram bot and its HTTP API token
14
+
- The Chat ID for the direct chat, group, or channel that should receive alerts
15
+
- Optional: the Message Thread ID for a specific Telegram forum topic
16
+
17
+
</Accordion>
14
18
15
19
## Telegram Bot
16
20
@@ -26,37 +30,57 @@ To enable the Telegram alert channel, you'll need two things:
26
30
27
31
## Chat ID
28
32
29
-
There are multiple methods for getting your own users Chat ID in Telegram and we'll cover two of them. First, we can leverage another Telegram bot and they will reply to us with our own ID. Second, we can use the newly created HTTP API Token to query the Telegram API.
33
+
For direct messages, you can retrieve your user Chat ID with an ID bot. For groups and forum topics, query the Telegram API to retrieve the target group's Chat ID and optional Message Thread ID.
30
34
31
35
#### ID Bot
32
36
33
-
You can retrieve your own Telegram Chat ID by starting a chat with another bot. This Telegram bot user can be found at `@get_id_bot`.
37
+
You can retrieve your own Telegram Chat ID by starting a chat with another bot. This Telegram bot user can be found at `@get_id_bot`.
34
38
35
-
1. Send this`@get_id_bot` bot the command message `/my_id`and they will reply with a 9 digit number which identifies you in Telegram. **This is the second and last piece of information we need for the Checkly Telegram integration**.
39
+
1. Send the`@get_id_bot` bot the `/my_id`command. Copy the ID from its reply.
36
40
37
41
#### API Query
38
42
39
-
Alternatively, we can use the API token we generated with the bot earlier and query the Telegram API for our own Chat ID.
43
+
Use the bot API to retrieve a Chat ID for any target chat. For a forum group, the same response includes the Message Thread ID, which Telegram also calls the topic ID.
40
44
41
-
1. In a browser enter the following URL, `https://api.telegram.org/bot<API_TOKEN>/getUpdates`, of course replacing the `<API_TOKEN>` part with the actual token we obtained previously. Your browser should now display some JSON formatted data which looks like the following:
45
+
1. Add your bot to the target chat or group. If you want alerts in a specific forum topic, send the bot a command from that topic.
46
+
2. In a browser, open `https://api.telegram.org/bot<API_TOKEN>/getUpdates`, replacing `<API_TOKEN>` with your bot's API token.
In the `result` array, you will see the message you sent to your Bot previously to start it, including the `id` of the user who sent it - your own. This should be a 9-digit number. **This is the second and last piece of information we need for the Checkly Telegram integration**.
50
+
3. Find the message in the `result` array and copy these values:
51
+
52
+
-`message.chat.id`: the Chat ID
53
+
-`message.message_thread_id`: the optional Message Thread ID for the forum topic
54
+
55
+
The relevant fields look like this:
56
+
57
+
```json Telegram update
58
+
{
59
+
"message": {
60
+
"message_thread_id": 42,
61
+
"chat": {
62
+
"id": -1001234567890,
63
+
"type": "supergroup",
64
+
"is_forum": true
65
+
}
66
+
}
67
+
}
68
+
```
69
+
70
+
<Note>
71
+
The `getUpdates` method does not work while your bot has an outgoing webhook configured. In that case, retrieve these fields from the update sent to your webhook.
72
+
</Note>
46
73
47
74
## Checkly Integration
48
75
49
-
With the (1) **HTTP API Token**and (2)**Chat ID** in hand, we can go back to Checkly and create a new Telegram alert channel.
76
+
With the **HTTP API Token**, **Chat ID**, and optional**Message Thread ID** in hand, you can create a Telegram alert channel in Checkly.
50
77
51
78
1. Log in to Checkly and navigate to [Alert Settings](https://app.checklyhq.com/alert-settings/).
52
79
Click the "Add more channels" button, find Telegram on the list, and click "Add channel".
2. Give the alert channel a name and paste the API Token and Chat ID into the dedicated fields. To send alerts to a specific forum topic, also paste its topic ID into **Message Thread ID**. You can then choose which alerts you want to receive and which checks or check groups should trigger this channel.
60
84
61
85
<Callouttype="note">
62
86
Note that we provide a preconfigured message payload, but you may want to edit the payload to modify the Telegram alert message contents. Such as by adding more variables or changing existing variables. Click the "Edit payload" button and reference the "Help & variables" tab.
@@ -66,14 +90,15 @@ Congratulations! You have successfully integrated Checkly with Telegram!
66
90
67
91
## Alternatives
68
92
69
-
Telegram also accepts messages via an HTTP `GET` request. Therefore, you can use the API Token and Chat ID to create a custom Telegram alert channel by leveraging our [**webhook alert channel**](/integrations/alerts/webhooks). The webhook should use the `GET` method and target this URL, `https://api.telegram.org/bot<API_TOKEN>/sendMessage?chat_id=<CHAT_ID>&text=Your%20Alert%20Title`. More information about sending messages via Telegram bots and the API can be found [here](https://core.telegram.org/bots/api#sendmessage).
93
+
Telegram also accepts messages via an HTTP `GET` request. Therefore, you can use the API Token and Chat ID to create a custom Telegram alert channel with a [webhook alert channel](/integrations/alerts/webhooks). The webhook should use the `GET` method and target `https://api.telegram.org/bot<API_TOKEN>/sendMessage?chat_id=<CHAT_ID>&text=Your%20Alert%20Title`. To target a forum topic, add `&message_thread_id=<MESSAGE_THREAD_ID>` before the `text` parameter. See Telegram's [`sendMessage` documentation](https://core.telegram.org/bots/api#sendmessage) for more information.
70
94
71
95
## Telegram Best Practices
72
96
73
97
### Group vs Direct Messages
74
98
75
99
-**Direct Messages**: Use your personal chat ID for personal notifications
76
100
-**Group Chats**: Add the bot to group chats and use the group's Chat ID for team notifications
101
+
-**Forum Topics**: Use the group's Chat ID together with the topic's Message Thread ID
77
102
-**Channels**: Bots can post to channels if added as administrators
78
103
79
104
### Message Formatting
@@ -96,4 +121,4 @@ Error: {{CHECK_ERROR_MESSAGE}}
96
121
97
122
-**Bot Token Security**: Keep your bot tokens secure and never share them publicly
98
123
-**Chat ID Privacy**: Chat IDs can be sensitive information, especially for private groups
99
-
-**Bot Permissions**: Only give your bot the minimum necessary permissions in group chats
124
+
-**Bot Permissions**: Only give your bot the minimum necessary permissions in group chats
0 commit comments