Add Feishu notification

This commit is contained in:
wuwenjing 2021-10-11 17:20:09 +08:00
parent 2a1fd93444
commit 6d9b71c054
6 changed files with 108 additions and 0 deletions

View File

@ -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;

View File

@ -18,6 +18,7 @@ const SMTP = require("./notification-providers/smtp");
const Teams = require("./notification-providers/teams"); const Teams = require("./notification-providers/teams");
const Telegram = require("./notification-providers/telegram"); const Telegram = require("./notification-providers/telegram");
const Webhook = require("./notification-providers/webhook"); const Webhook = require("./notification-providers/webhook");
const Feishu = require("./notification-providers/feishu");
class Notification { class Notification {
@ -35,6 +36,7 @@ class Notification {
new Gotify(), new Gotify(),
new Line(), new Line(),
new LunaSea(), new LunaSea(),
new Feishu(),
new Mattermost(), new Mattermost(),
new Matrix(), new Matrix(),
new Octopush(), new Octopush(),

View File

@ -0,0 +1,15 @@
<template>
<div class="mb-3">
<label for="Feishu-WebHookUrl" class="form-label">{{ $t("Feishu WebHookUrl") }}<span style="color: red;"><sup>*</sup></span></label>
<input id="Feishu-WebHookUrl" v-model="$parent.notification.feishuWebHookUrl" type="text" class="form-control" required>
<div class="form-text">
<p><span style="color: red;"><sup>*</sup></span>{{ $t("Required") }}</p>
</div>
<i18n-t tag="div" keypath="wayToGetTeamsURL" class="form-text">
<a
href="https://www.feishu.cn/hc/zh-CN/articles/360024984973"
target="_blank"
>{{ $t("here") }}</a>
</i18n-t>
</div>
</template>

View File

@ -12,6 +12,7 @@ import Pushy from "./Pushy.vue";
import Octopush from "./Octopush.vue"; import Octopush from "./Octopush.vue";
import PromoSMS from "./PromoSMS.vue"; import PromoSMS from "./PromoSMS.vue";
import LunaSea from "./LunaSea.vue"; import LunaSea from "./LunaSea.vue";
import Feishu from "./Feishu.vue";
import Apprise from "./Apprise.vue"; import Apprise from "./Apprise.vue";
import Pushbullet from "./Pushbullet.vue"; import Pushbullet from "./Pushbullet.vue";
import Line from "./Line.vue"; import Line from "./Line.vue";
@ -38,6 +39,7 @@ const NotificationFormList = {
"octopush": Octopush, "octopush": Octopush,
"promosms": PromoSMS, "promosms": PromoSMS,
"lunasea": LunaSea, "lunasea": LunaSea,
"Feishu": Feishu,
"apprise": Apprise, "apprise": Apprise,
"pushbullet": Pushbullet, "pushbullet": Pushbullet,
"line": Line, "line": Line,

View File

@ -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).", 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)", 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", promosmsSMSSender: "SMS Sender Name : Pre-registred name or one of defaults: InfoSMS, SMS Info, MaxSMS, INFO, SMS",
"Feishu WebHookUrl": "Feishu WebHookUrl",
// End notification form // End notification form
}; };

View File

@ -198,4 +198,5 @@ export default {
pushbullet: "Pushbullet", pushbullet: "Pushbullet",
line: "Line Messenger", line: "Line Messenger",
mattermost: "Mattermost", mattermost: "Mattermost",
"Feishu WebHookUrl": "飞书 WebHook 地址",
}; };