diff --git a/server/notification-providers/wecom.js b/server/notification-providers/wecom.js new file mode 100644 index 000000000..7ba8c3783 --- /dev/null +++ b/server/notification-providers/wecom.js @@ -0,0 +1,47 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const { DOWN, UP } = require("../../src/util"); + +class WeCom extends NotificationProvider { + + name = "WeCom"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + + try { + let WeComUrl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" + notification.weComBotKey; + let config = { + headers: { + "Content-Type": "application/json" + } + }; + let body = this.composeMessage(heartbeatJSON, msg); + await axios.post(WeComUrl, body, config); + return okMsg; + } catch (error) { + this.throwGeneralAxiosError(error); + } + } + + composeMessage(heartbeatJSON, msg) { + let title; + if (msg != null && heartbeatJSON != null && heartbeatJSON['status'] == UP) { + title = "UptimeKuma Monitor Up"; + } + if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] == DOWN) { + title = "UptimeKuma Monitor Down"; + } + if (msg != null) { + title = "UptimeKuma Message"; + } + return { + msgtype: "text", + text: { + content: title + msg + } + }; + } +} + +module.exports = WeCom; diff --git a/server/notification.js b/server/notification.js index 56a7e84d8..4d72c81c7 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 WeCom = require("./notification-providers/wecom"); const GoogleChat = require("./notification-providers/google-chat"); class Notification { @@ -63,6 +64,7 @@ class Notification { new Bark(), new SerwerSMS(), new Stackfield(), + new WeCom(), new GoogleChat() ]; diff --git a/src/components/notifications/WeCom.vue b/src/components/notifications/WeCom.vue new file mode 100644 index 000000000..cef3708d1 --- /dev/null +++ b/src/components/notifications/WeCom.vue @@ -0,0 +1,12 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 9d870f91c..be73d9ef8 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -23,7 +23,8 @@ import AliyunSMS from "./AliyunSms.vue"; import DingDing from "./DingDing.vue"; import Bark from "./Bark.vue"; import SerwerSMS from "./SerwerSMS.vue"; -import Stackfield from "./Stackfield.vue"; +import Stackfield from './Stackfield.vue'; +import WeCom from "./WeCom.vue"; import GoogleChat from "./GoogleChat.vue"; /** @@ -58,6 +59,7 @@ const NotificationFormList = { "Bark": Bark, "serwersms": SerwerSMS, "stackfield": Stackfield, + "WeCom": WeCom, "Google Chat (Google Workspace only)": GoogleChat };