|
|
@ -15,9 +15,21 @@ class Notification {
|
|
|
|
* @returns {Promise<string>} Successful msg
|
|
|
|
* @returns {Promise<string>} Successful msg
|
|
|
|
* Throw Error with fail msg
|
|
|
|
* Throw Error with fail msg
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
|
|
static async send(notification, monitorName = null, monitorJSON = null, heartbeatJSON = null) {
|
|
|
|
let okMsg = "Sent Successfully. ";
|
|
|
|
let okMsg = "Sent Successfully. ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let msg = `[${notification.name}] Testing`;
|
|
|
|
|
|
|
|
// heartbeatJSON is only defined if we're not testing
|
|
|
|
|
|
|
|
if(heartbeatJSON) {
|
|
|
|
|
|
|
|
let text;
|
|
|
|
|
|
|
|
if (heartbeatJSON["status"] === 1) {
|
|
|
|
|
|
|
|
text = "✅ Up"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
text = "🔴 Down"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = `[${monitorName}] [${text}] ${heartbeatJSON["msg"]}`;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (notification.type === "telegram") {
|
|
|
|
if (notification.type === "telegram") {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
await axios.get(`https://api.telegram.org/bot${notification.telegramBotToken}/sendMessage`, {
|
|
|
|
await axios.get(`https://api.telegram.org/bot${notification.telegramBotToken}/sendMessage`, {
|
|
|
|