Skip to content

Commit

Permalink
🐛 fix: telegram send message script
Browse files Browse the repository at this point in the history
  • Loading branch information
KartikSoneji committed Jul 15, 2023
1 parent 8f55c88 commit 1a257e5
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions util/post-telegram-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 1a257e5

Please sign in to comment.