mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-01 02:34:03 +00:00
b91fe9d96d
such as thread id, silent notifications and forward protect
36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
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;
|