mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 16:54:04 +00:00
feat(*): support WeCom notification
This commit is contained in:
parent
a48176bd48
commit
40b70277c7
4 changed files with 63 additions and 0 deletions
47
server/notification-providers/wecom.js
Normal file
47
server/notification-providers/wecom.js
Normal file
|
@ -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;
|
|
@ -25,6 +25,7 @@ const DingDing = require("./notification-providers/dingding");
|
||||||
const Bark = require("./notification-providers/bark");
|
const Bark = require("./notification-providers/bark");
|
||||||
const SerwerSMS = require("./notification-providers/serwersms");
|
const SerwerSMS = require("./notification-providers/serwersms");
|
||||||
const Stackfield = require("./notification-providers/stackfield");
|
const Stackfield = require("./notification-providers/stackfield");
|
||||||
|
const WeCom = require("./notification-providers/wecom");
|
||||||
|
|
||||||
class Notification {
|
class Notification {
|
||||||
|
|
||||||
|
@ -62,6 +63,7 @@ class Notification {
|
||||||
new Bark(),
|
new Bark(),
|
||||||
new SerwerSMS(),
|
new SerwerSMS(),
|
||||||
new Stackfield(),
|
new Stackfield(),
|
||||||
|
new WeCom(),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let item of list) {
|
for (let item of list) {
|
||||||
|
|
12
src/components/notifications/WeCom.vue
Normal file
12
src/components/notifications/WeCom.vue
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
<template>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="WeCom Bot Key" class="form-label">{{ $t("WeCom Bot Key") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||||
|
<input id="WeCom Bot Key" v-model="$parent.notification.weComBotKey" 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="p" keypath="Read more:">
|
||||||
|
<a href="https://work.weixin.qq.com/api/doc/90000/90136/91770" target="_blank">https://work.weixin.qq.com/api/doc/90000/90136/91770</a>
|
||||||
|
</i18n-t>
|
||||||
|
</div>
|
||||||
|
</template>
|
|
@ -24,6 +24,7 @@ import DingDing from "./DingDing.vue";
|
||||||
import Bark from "./Bark.vue";
|
import Bark from "./Bark.vue";
|
||||||
import SerwerSMS from "./SerwerSMS.vue";
|
import SerwerSMS from "./SerwerSMS.vue";
|
||||||
import Stackfield from './Stackfield.vue';
|
import Stackfield from './Stackfield.vue';
|
||||||
|
import WeCom from "./WeCom.vue";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage all notification form.
|
* Manage all notification form.
|
||||||
|
@ -57,6 +58,7 @@ const NotificationFormList = {
|
||||||
"Bark": Bark,
|
"Bark": Bark,
|
||||||
"serwersms": SerwerSMS,
|
"serwersms": SerwerSMS,
|
||||||
"stackfield": Stackfield,
|
"stackfield": Stackfield,
|
||||||
|
"WeCom": WeCom,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default NotificationFormList
|
export default NotificationFormList
|
||||||
|
|
Loading…
Reference in a new issue