1
0
mirror of https://github.com/louislam/uptime-kuma.git synced 2024-12-14 10:23:16 +02:00
uptime-kuma/server/notification-providers/telegram.js
shyneko b91fe9d96d Added a more telegram options
such as thread id, silent notifications and forward protect
2023-01-12 15:09:05 +02:00

37 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;