mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 08:44:04 +00:00
Add WPush Notification Provider (#5049)
Signed-off-by: Alone88 <anhaoyl@qq.com>
This commit is contained in:
parent
dc3ad88fe1
commit
b059c19069
5 changed files with 87 additions and 0 deletions
51
server/notification-providers/wpush.js
Normal file
51
server/notification-providers/wpush.js
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
const { DOWN, UP } = require("../../src/util");
|
||||||
|
|
||||||
|
class WPush extends NotificationProvider {
|
||||||
|
name = "WPush";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||||
|
const okMsg = "Sent Successfully.";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const context = {
|
||||||
|
"title": this.checkStatus(heartbeatJSON, monitorJSON),
|
||||||
|
"content": msg,
|
||||||
|
"apikey": notification.wpushAPIkey,
|
||||||
|
"channel": notification.wpushChannel
|
||||||
|
};
|
||||||
|
const result = await axios.post("https://api.wpush.cn/api/v1/send", context);
|
||||||
|
if (result.data.code !== 0) {
|
||||||
|
throw result.data.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return okMsg;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the formatted title for message
|
||||||
|
* @param {?object} heartbeatJSON Heartbeat details (For Up/Down only)
|
||||||
|
* @param {?object} monitorJSON Monitor details (For Up/Down only)
|
||||||
|
* @returns {string} Formatted title
|
||||||
|
*/
|
||||||
|
checkStatus(heartbeatJSON, monitorJSON) {
|
||||||
|
let title = "UptimeKuma Message";
|
||||||
|
if (heartbeatJSON != null && heartbeatJSON["status"] === UP) {
|
||||||
|
title = "UptimeKuma Monitor Up " + monitorJSON["name"];
|
||||||
|
}
|
||||||
|
if (heartbeatJSON != null && heartbeatJSON["status"] === DOWN) {
|
||||||
|
title = "UptimeKuma Monitor Down " + monitorJSON["name"];
|
||||||
|
}
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = WPush;
|
|
@ -65,6 +65,7 @@ const Whapi = require("./notification-providers/whapi");
|
||||||
const GtxMessaging = require("./notification-providers/gtx-messaging");
|
const GtxMessaging = require("./notification-providers/gtx-messaging");
|
||||||
const Cellsynt = require("./notification-providers/cellsynt");
|
const Cellsynt = require("./notification-providers/cellsynt");
|
||||||
const Onesender = require("./notification-providers/onesender");
|
const Onesender = require("./notification-providers/onesender");
|
||||||
|
const Wpush = require("./notification-providers/wpush");
|
||||||
|
|
||||||
class Notification {
|
class Notification {
|
||||||
|
|
||||||
|
@ -147,6 +148,7 @@ class Notification {
|
||||||
new Whapi(),
|
new Whapi(),
|
||||||
new GtxMessaging(),
|
new GtxMessaging(),
|
||||||
new Cellsynt(),
|
new Cellsynt(),
|
||||||
|
new Wpush(),
|
||||||
];
|
];
|
||||||
for (let item of list) {
|
for (let item of list) {
|
||||||
if (! item.name) {
|
if (! item.name) {
|
||||||
|
|
|
@ -179,6 +179,7 @@ export default {
|
||||||
"WeCom": "WeCom (企业微信群机器人)",
|
"WeCom": "WeCom (企业微信群机器人)",
|
||||||
"ServerChan": "ServerChan (Server酱)",
|
"ServerChan": "ServerChan (Server酱)",
|
||||||
"smsc": "SMSC",
|
"smsc": "SMSC",
|
||||||
|
"WPush": "WPush(wpush.cn)",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sort by notification name
|
// Sort by notification name
|
||||||
|
|
31
src/components/notifications/WPush.vue
Normal file
31
src/components/notifications/WPush.vue
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<template>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="wpush-apikey" class="form-label">WPush {{ $t("API Key") }}</label>
|
||||||
|
<HiddenInput id="wpush-apikey" v-model="$parent.notification.wpushAPIkey" :required="true" autocomplete="new-password" placeholder="WPushxxxxx"></HiddenInput>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="wpush-channel" class="form-label">发送通道</label>
|
||||||
|
<select id="wpush-channel" v-model="$parent.notification.wpushChannel" class="form-select" required>
|
||||||
|
<option value="wechat">微信</option>
|
||||||
|
<option value="sms">短信</option>
|
||||||
|
<option value="mail">邮件</option>
|
||||||
|
<option value="feishu">飞书</option>
|
||||||
|
<option value="dingtalk">钉钉</option>
|
||||||
|
<option value="wechat_work">企业微信</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<i18n-t tag="p" keypath="More info on:">
|
||||||
|
<a href="https://wpush.cn/" rel="noopener noreferrer" target="_blank">https://wpush.cn/</a>
|
||||||
|
</i18n-t>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import HiddenInput from "../HiddenInput.vue";
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
HiddenInput,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
|
@ -63,6 +63,7 @@ import Splunk from "./Splunk.vue";
|
||||||
import SevenIO from "./SevenIO.vue";
|
import SevenIO from "./SevenIO.vue";
|
||||||
import Whapi from "./Whapi.vue";
|
import Whapi from "./Whapi.vue";
|
||||||
import Cellsynt from "./Cellsynt.vue";
|
import Cellsynt from "./Cellsynt.vue";
|
||||||
|
import WPush from "./WPush.vue";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage all notification form.
|
* Manage all notification form.
|
||||||
|
@ -134,6 +135,7 @@ const NotificationFormList = {
|
||||||
"whapi": Whapi,
|
"whapi": Whapi,
|
||||||
"gtxmessaging": GtxMessaging,
|
"gtxmessaging": GtxMessaging,
|
||||||
"Cellsynt": Cellsynt,
|
"Cellsynt": Cellsynt,
|
||||||
|
"WPush": WPush
|
||||||
};
|
};
|
||||||
|
|
||||||
export default NotificationFormList;
|
export default NotificationFormList;
|
||||||
|
|
Loading…
Reference in a new issue