Created
May 17, 2023 15:53
-
-
Save stavros-melidoniotis/abcdb691ce7e4b9aac36ff319f7fb143 to your computer and use it in GitHub Desktop.
Send notifications via Telegram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BOT_TOKEN = process.env.BOT_TOKEN; | |
const CHANNEL_ID = process.env.CHANNEL_ID; | |
export const sendMessage = async (message) => { | |
const options = { | |
method: "POST", | |
headers: { | |
accept: "application/json", | |
"User-Agent": | |
"Telegram Bot SDK - (https://github.com/irazasyed/telegram-bot-sdk)", | |
"content-type": "application/json", | |
}, | |
body: JSON.stringify({ | |
text: message, | |
parse_mode: "Markdown", | |
disable_web_page_preview: false, | |
disable_notification: false, | |
reply_to_message_id: null, | |
chat_id: CHANNEL_ID, | |
}), | |
}; | |
try { | |
const res = await fetch( | |
`https://api.telegram.org/bot${BOT_TOKEN}/sendMessage`, | |
options | |
); | |
return res.ok; | |
} catch (err) { | |
console.error(err); | |
return false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment