From 6d9b71c0547788cbac1b868b249cc02508efb1b9 Mon Sep 17 00:00:00 2001 From: wuwenjing Date: Mon, 11 Oct 2021 17:20:09 +0800 Subject: [PATCH] Add Feishu notification --- server/notification-providers/feishu.js | 87 +++++++++++++++++++++++++ server/notification.js | 2 + src/components/notifications/Feishu.vue | 15 +++++ src/components/notifications/index.js | 2 + src/languages/en.js | 1 + src/languages/zh-CN.js | 1 + 6 files changed, 108 insertions(+) create mode 100644 server/notification-providers/feishu.js create mode 100644 src/components/notifications/Feishu.vue diff --git a/server/notification-providers/feishu.js b/server/notification-providers/feishu.js new file mode 100644 index 000000000..7648f629b --- /dev/null +++ b/server/notification-providers/feishu.js @@ -0,0 +1,87 @@ +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; + + console.log(heartbeatJSON); + try { + if (heartbeatJSON == null) { + let testdata = { + msg_type: "text", + content: { + text: "Testing Successful.", + }, + }; + var t = await axios.post(feishuWebHookUrl, testdata); + console.log(t); + 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 5b104bf8a..41a0063c3 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 000000000..18dc26422 --- /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 7d70eea17..140c1180c 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 119b558e0..d93714f66 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 a7f81950a..1028d577e 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 地址", };