diff --git a/server/notification-providers/feishu.js b/server/notification-providers/feishu.js new file mode 100644 index 00000000..a3e34030 --- /dev/null +++ b/server/notification-providers/feishu.js @@ -0,0 +1,83 @@ +const NotificationProvider = require("./notification-provider"); +const axios = require("axios"); +const { DOWN, UP } = require("../../src/util"); + +class Feishu extends NotificationProvider { + name = "Feishu"; + + async send(notification, msg, monitorJSON = null, heartbeatJSON = null) { + let okMsg = "Sent Successfully."; + let feishuWebHookUrl = notification.feishuWebHookUrl; + + try { + if (heartbeatJSON == null) { + let testdata = { + msg_type: "text", + content: { + text: msg, + }, + }; + await axios.post(feishuWebHookUrl, testdata); + return okMsg; + } + + if (heartbeatJSON["status"] == DOWN) { + let downdata = { + msg_type: "post", + content: { + post: { + zh_cn: { + title: "UptimeKuma Alert: " + monitorJSON["name"], + content: [ + [ + { + tag: "text", + text: + "[Down] " + + heartbeatJSON["msg"] + + "\nTime (UTC): " + + heartbeatJSON["time"], + }, + ], + ], + }, + }, + }, + }; + await axios.post(feishuWebHookUrl, downdata); + return okMsg; + } + + if (heartbeatJSON["status"] == UP) { + let updata = { + msg_type: "post", + content: { + post: { + zh_cn: { + title: "UptimeKuma Alert: " + monitorJSON["name"], + content: [ + [ + { + tag: "text", + text: + "[Up] " + + heartbeatJSON["msg"] + + "\nTime (UTC): " + + heartbeatJSON["time"], + }, + ], + ], + }, + }, + }, + }; + await axios.post(feishuWebHookUrl, updata); + return okMsg; + } + } catch (error) { + this.throwGeneralAxiosError(error); + } + } +} + +module.exports = Feishu; diff --git a/server/notification.js b/server/notification.js index 5b104bf8..41a0063c 100644 --- a/server/notification.js +++ b/server/notification.js @@ -18,6 +18,7 @@ const SMTP = require("./notification-providers/smtp"); const Teams = require("./notification-providers/teams"); const Telegram = require("./notification-providers/telegram"); const Webhook = require("./notification-providers/webhook"); +const Feishu = require("./notification-providers/feishu"); class Notification { @@ -35,6 +36,7 @@ class Notification { new Gotify(), new Line(), new LunaSea(), + new Feishu(), new Mattermost(), new Matrix(), new Octopush(), diff --git a/src/components/notifications/Feishu.vue b/src/components/notifications/Feishu.vue new file mode 100644 index 00000000..18dc2642 --- /dev/null +++ b/src/components/notifications/Feishu.vue @@ -0,0 +1,15 @@ + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 7d70eea1..140c1180 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -12,6 +12,7 @@ import Pushy from "./Pushy.vue"; import Octopush from "./Octopush.vue"; import PromoSMS from "./PromoSMS.vue"; import LunaSea from "./LunaSea.vue"; +import Feishu from "./Feishu.vue"; import Apprise from "./Apprise.vue"; import Pushbullet from "./Pushbullet.vue"; import Line from "./Line.vue"; @@ -38,6 +39,7 @@ const NotificationFormList = { "octopush": Octopush, "promosms": PromoSMS, "lunasea": LunaSea, + "Feishu": Feishu, "apprise": Apprise, "pushbullet": Pushbullet, "line": Line, diff --git a/src/languages/en.js b/src/languages/en.js index 119b558e..d93714f6 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -280,5 +280,6 @@ export default { promosmsTypeSpeed: "SMS SPEED - Highest priority in system. Very quick and reliable but costly (about twice of SMS FULL price).", promosmsPhoneNumber: "Phone number (for Polish recipient You can skip area codes)", promosmsSMSSender: "SMS Sender Name : Pre-registred name or one of defaults: InfoSMS, SMS Info, MaxSMS, INFO, SMS", + "Feishu WebHookUrl": "Feishu WebHookUrl", // End notification form }; diff --git a/src/languages/zh-CN.js b/src/languages/zh-CN.js index a7f81950..1028d577 100644 --- a/src/languages/zh-CN.js +++ b/src/languages/zh-CN.js @@ -198,4 +198,5 @@ export default { pushbullet: "Pushbullet", line: "Line Messenger", mattermost: "Mattermost", + "Feishu WebHookUrl": "飞书 WebHook 地址", };