Skip to content

Commit 687fb1b

Browse files
docs: add Telegram forum topic support (#453)
1 parent b79541e commit 687fb1b

2 files changed

Lines changed: 54 additions & 20 deletions

File tree

constructs/telegram-alert-channel.mdx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: 'TelegramAlertChannel Construct'
3-
description: 'Learn how to configure Telegram alert channels with the Checkly CLI.'
3+
description: 'Learn how to configure Telegram alert channels and forum topics with the Checkly CLI.'
44
sidebarTitle: 'Telegram'
55
canonical: 'https://www.checklyhq.com/docs/constructs/telegram-alert-channel/'
66
---
@@ -33,6 +33,7 @@ const telegramChannel = new TelegramAlertChannel('my-telegramchannel-1', {
3333
name: 'My Telegram channel',
3434
apiKey: 'xxxxxx',
3535
chatId: 'xxxxxx',
36+
messageThreadId: '42',
3637
sendRecovery: true,
3738
sendFailure: true,
3839
sendDegraded: true,
@@ -43,6 +44,10 @@ const telegramChannel = new TelegramAlertChannel('my-telegramchannel-1', {
4344

4445
</CodeGroup>
4546

47+
<Note>
48+
`messageThreadId` requires Checkly CLI 8.18.0 or later.
49+
</Note>
50+
4651
<Note>
4752
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).
4853
</Note>
@@ -63,6 +68,10 @@ The API key associated with your Telegram bot.
6368
The chat ID of the Telegram channel you want to send alerts to.
6469
</ResponseField>
6570

71+
<ResponseField name="messageThreadId" type="string">
72+
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+
6675
<ResponseField name="payload" type="string">
6776
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.
6877

integrations/alerts/telegram.mdx

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
---
22
title: 'Send Alerts via Telegram'
3-
description: 'Find out how Checkly integrates with Telegram to send failure, degradation, and recovery messages to any chat'
3+
description: 'Learn how to send Checkly alerts to Telegram direct chats, groups, and forum topics'
44
sidebarTitle: 'Telegram'
55
canonical: 'https://www.checklyhq.com/docs/integrations/alerts/telegram/'
66
---
77

8-
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.
1110

12-
1. Your own Telegram bot and its associated HTTP API Token
13-
2. Your own Telegram user's Chat ID
11+
<Accordion title="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>
1418

1519
## Telegram Bot
1620

@@ -26,37 +30,57 @@ To enable the Telegram alert channel, you'll need two things:
2630

2731
## Chat ID
2832

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.
3034

3135
#### ID Bot
3236

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`.
3438

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.
3640

3741
#### API Query
3842

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.
4044

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.
4247

4348
![setup checkly telegram_bot step 5](/images/docs/images/integrations/telegram/telegram_step5.png)
4449

45-
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>
4673

4774
## Checkly Integration
4875

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.
5077

5178
1. Log in to Checkly and navigate to [Alert Settings](https://app.checklyhq.com/alert-settings/).
5279
Click the "Add more channels" button, find Telegram on the list, and click "Add channel".
5380

5481
![setup checkly telegram_bot step 6](/images/docs/images/integrations/telegram/telegram_step6.png)
5582

56-
2. Give the alert channel a name and **paste the API Token and Chat ID** in the dedicated input fields. Here you can also tweak
57-
which alerts you want to be notified of and which checks or check groups should trigger this channel.
58-
59-
![setup checkly telegram_bot step 7](/images/docs/images/integrations/telegram/telegram_step7.png)
83+
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.
6084

6185
<Callout type="note">
6286
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!
6690

6791
## Alternatives
6892

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.
7094

7195
## Telegram Best Practices
7296

7397
### Group vs Direct Messages
7498

7599
- **Direct Messages**: Use your personal chat ID for personal notifications
76100
- **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
77102
- **Channels**: Bots can post to channels if added as administrators
78103

79104
### Message Formatting
@@ -96,4 +121,4 @@ Error: {{CHECK_ERROR_MESSAGE}}
96121

97122
- **Bot Token Security**: Keep your bot tokens secure and never share them publicly
98123
- **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

Comments
 (0)