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;