Skip to content

Commit 620c7a4

Browse files
bobweaselclaabs
andauthored
Support Telegram topics/threads (#463)
* feature: telegram topic/threads * feature: telegram topic/threads, linting prettier fix * feature: telegram topic/threads, linting prettier fix * feature: telegram topic/threads, linting prettier fix * support env var --------- Co-authored-by: Charlie Laabs <[email protected]>
1 parent 4e4ee5f commit 620c7a4

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ The config file is stored in the mounted `/usr/app/config` volume and can be nam
5858
"apiUrl": "https://api.telegram.org",
5959
"token": "644739147:AAGMPo-Jz3mKRnHRTnrPEDi7jUF1vqNOD5k",
6060
"chatId": "-987654321",
61+
"topic": 5,
6162
},
6263
{
6364
"type": "apprise",

src/common/config/classes.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ export class TelegramConfig extends NotifierConfig {
207207
@IsNotEmpty()
208208
chatId: string;
209209

210+
/**
211+
* Identifier for the topic/thread to send the messages
212+
* @example 5
213+
* @env TELEGRAM_TOPIC
214+
*/
215+
@IsInt()
216+
@IsOptional()
217+
topic?: number;
218+
210219
/**
211220
* Custom TELEGRAM server URL
212221
* @default https://api.telegram.org
@@ -1074,11 +1083,12 @@ export class AppConfig {
10741083
}
10751084

10761085
// Use environment variables to fill telegram notification config if present
1077-
const { TELEGRAM_TOKEN, TELEGRAM_CHAT_ID } = process.env;
1086+
const { TELEGRAM_TOKEN, TELEGRAM_CHAT_ID, TELEGRAM_TOPIC } = process.env;
10781087
if (TELEGRAM_TOKEN && TELEGRAM_CHAT_ID) {
10791088
const telegram = new TelegramConfig();
10801089
telegram.token = TELEGRAM_TOKEN;
10811090
telegram.chatId = TELEGRAM_CHAT_ID;
1091+
telegram.topic = TELEGRAM_TOPIC ? parseInt(TELEGRAM_TOPIC, 10) : undefined;
10821092
this.notifiers ??= [];
10831093
if (!this.notifiers.some((notifConfig) => notifConfig instanceof TelegramConfig)) {
10841094
this.notifiers.push(telegram);

src/notifiers/telegram.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export class TelegramNotifier extends NotifierService {
3333
text: escapedMessage,
3434
disable_web_page_preview: true,
3535
parse_mode: 'MarkdownV2',
36+
...(this.config.topic ? { message_thread_id: this.config.topic } : {}),
3637
};
3738

3839
L.trace({ jsonPayload }, 'Sending json payload');

0 commit comments

Comments
 (0)