From 1a257e5e9efe1cd5a49f7e29228024df6253e279 Mon Sep 17 00:00:00 2001 From: Kartik Soneji Date: Sat, 15 Jul 2023 21:55:42 +0530 Subject: [PATCH] :bug: fix: telegram send message script --- util/post-telegram-message.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/util/post-telegram-message.js b/util/post-telegram-message.js index a3e3b8f7..18210c03 100644 --- a/util/post-telegram-message.js +++ b/util/post-telegram-message.js @@ -40,7 +40,16 @@ async function sendApiRequestRaw(method, body = {}) { } async function sendApiRequest(method, body) { - return sendApiRequestRaw(method, body).then((e) => e.json()); + let { ok, result, error_code, description } = await sendApiRequestRaw( + method, + body + ).then((e) => e.json()); + if (!ok) { + console.error(`request failed: ${method}`); + console.error(`error ${error_code}: ${description}`); + console.error(body); + } + return result; } async function sendMessageToChat(chat_id, text) { @@ -53,7 +62,7 @@ async function sendMessageToChat(chat_id, text) { } async function sendAndPinMessageToChat(chat_id, text) { - let { message_id } = await sendMessageToChat(text); + let { message_id } = await sendMessageToChat(chat_id, text); return sendApiRequest("pinChatMessage", { chat_id, message_id @@ -79,7 +88,11 @@ async function main() { return 1; } - await sendAndPinMessageToChat(chat_id, message); + let response = await sendAndPinMessageToChat(chat_id, message); + if (!response) { + console.error(`failed to send telegram message`); + return 2; + } } if (require.main)