diff --git a/server/notification-providers/google-chat.js b/server/notification-providers/google-chat.js new file mode 100644 index 000000000..f73f4b5a5 --- /dev/null +++ b/server/notification-providers/google-chat.js @@ -0,0 +1,46 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const { setting } = require("../util-server"); +const { getMonitorRelativeURL } = require("../../src/util"); + +class GoogleChat extends NotificationProvider { + + name = "Google Chat"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + try { + // Google Chat message formatting: https://developers.google.com/chat/api/guides/message-formats/basic + + let textMsg = '' + if (heartbeatJSON && heartbeatJSON.status === UP) { + textMsg = `✅ Application is back online`; + } else { + textMsg = `🔴 Application went down`; + } + + if (monitorJSON && monitorJSON.name) { + textMsg += `\n*${monitorJSON.name}*`; + } + + textMsg += `\n${msg}`; + + const baseURL = await setting("primaryBaseURL"); + if (baseURL) { + textMsg += `\n${baseURL + getMonitorRelativeURL(monitorJSON.id)}`; + } + + const data = { + "text": textMsg, + }; + + await axios.post(notification.googleChatWebhookURL, data); + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + + } +} + +module.exports = GoogleChat; diff --git a/server/notification.js b/server/notification.js index 3eb5f97bf..56a7e84d8 100644 --- a/server/notification.js +++ b/server/notification.js @@ -25,6 +25,7 @@ const DingDing = require("./notification-providers/dingding"); const Bark = require("./notification-providers/bark"); const SerwerSMS = require("./notification-providers/serwersms"); const Stackfield = require("./notification-providers/stackfield"); +const GoogleChat = require("./notification-providers/google-chat"); class Notification { @@ -62,6 +63,7 @@ class Notification { new Bark(), new SerwerSMS(), new Stackfield(), + new GoogleChat() ]; for (let item of list) { diff --git a/src/components/notifications/GoogleChat.vue b/src/components/notifications/GoogleChat.vue new file mode 100644 index 000000000..c19cae0de --- /dev/null +++ b/src/components/notifications/GoogleChat.vue @@ -0,0 +1,13 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 155a1ab26..678106102 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -24,6 +24,7 @@ import DingDing from "./DingDing.vue"; import Bark from "./Bark.vue"; import SerwerSMS from "./SerwerSMS.vue"; import Stackfield from './Stackfield.vue'; +import GoogleChat from './GoogleChat.vue'; /** * Manage all notification form. @@ -57,6 +58,7 @@ const NotificationFormList = { "Bark": Bark, "serwersms": SerwerSMS, "stackfield": Stackfield, + "Google Chat": GoogleChat } export default NotificationFormList