From d0bda2bbcb005f57d282635146aba31dc750914e Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Wed, 3 May 2023 09:21:14 +0800 Subject: [PATCH] chore: add option to disable notification --- src/index.ts | 20 +++++++++++++++----- src/message.ts | 1 + 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0c55b39..1420635 100644 --- a/src/index.ts +++ b/src/index.ts @@ -54,7 +54,10 @@ router.post("/t/:webhookId", async (context) => { return; } const result: RichMessage = await context.req.body.json(); - await sendToChat(JSON.parse(chat), formatRichMessage(result), "HTML"); + await sendToChat(JSON.parse(chat), formatRichMessage(result), { + parseMode: "HTML", + disableNotification: result.notify === false, + }); context.res.body = { ok: true }; }); @@ -95,13 +98,16 @@ async function processUpdate(update: Update): Promise { "emoji": "👋", "metadata": { "email": "test@example.com" - } + }, + "notify": true } * Only event is required `, - "HTML" + { + parseMode: "HTML", + } ); } } @@ -112,7 +118,10 @@ async function sendToChat( messageThreadId?: number; }, text: string, - parseMode?: "HTML" + options?: { + parseMode?: "HTML"; + disableNotification?: boolean; + } ): Promise { await fetch(`https://api.telegram.org/bot${BOT_TOKEN}/sendMessage`, { method: "POST", @@ -123,7 +132,8 @@ async function sendToChat( chat_id: chat.chatId, message_thread_id: chat.messageThreadId, text, - parse_mode: parseMode, + parse_mode: options?.parseMode, + disable_notification: options?.disableNotification, }), }); } diff --git a/src/message.ts b/src/message.ts index 5a09b97..7f6c5a8 100644 --- a/src/message.ts +++ b/src/message.ts @@ -4,6 +4,7 @@ export type RichMessage = { text?: string; emoji?: string; metadata?: Record; + notify?: boolean; }; export function formatRichMessage(message: RichMessage): string {