You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.3 KiB
37 lines
1.3 KiB
const NotificationProvider = require("./notification-provider");
|
|
const axios = require("axios");
|
|
|
|
class Telegram extends NotificationProvider {
|
|
|
|
name = "telegram";
|
|
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
let okMsg = "Sent Successfully.";
|
|
|
|
try {
|
|
const paramsObj =
|
|
{
|
|
chat_id: notification.telegramChatID,
|
|
text: msg,
|
|
disable_notification: notification.telegramSilentNotification ?? false,
|
|
protect_content: notification.telegramProtectContent ?? false,
|
|
|
|
};
|
|
// if telegramChatThread specified, then add it to paramsObj
|
|
if (notification.telegramChatThread && notification.telegramChatThread.length > 0) {
|
|
paramsObj.message_thread_id = notification.telegramChatThread;
|
|
}
|
|
await axios.get(`https://api.telegram.org/bot${notification.telegramBotToken}/sendMessage`, {
|
|
params: paramsObj
|
|
});
|
|
return okMsg;
|
|
|
|
} catch (error) {
|
|
let msg = (error.response.data.description) ? error.response.data.description : "Error without description";
|
|
throw new Error(msg);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = Telegram;
|