mirror of
https://github.com/louislam/uptime-kuma.git
synced 2026-08-07 10:14:59 +00:00
feat: Add WxPusher SPT (WxPusher simple push token) notification provider (#7569)
Co-authored-by: wxpusher <foroutmoney@gmail.com>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
const NotificationProvider = require("./notification-provider");
|
||||
const axios = require("axios");
|
||||
const { DOWN, UP } = require("../../src/util");
|
||||
|
||||
class WxPusher extends NotificationProvider {
|
||||
name = "WxPusher";
|
||||
|
||||
// WxPusher's simple-push accepts at most 10 SPTs per request.
|
||||
static SPT_PER_REQUEST = 10;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
const okMsg = "Sent Successfully.";
|
||||
|
||||
// Accept one or multiple SPTs, comma-separated.
|
||||
const sptList = String(notification.wxpusherSPT || "")
|
||||
.split(",")
|
||||
.map((spt) => spt.trim())
|
||||
.filter((spt) => spt.length > 0);
|
||||
|
||||
try {
|
||||
if (sptList.length === 0) {
|
||||
throw new Error("No WxPusher SPT is configured");
|
||||
}
|
||||
|
||||
const summary = this.checkStatus(heartbeatJSON, monitorJSON).slice(0, 100);
|
||||
const config = this.getAxiosConfigWithProxy({});
|
||||
|
||||
// Send in batches so more than 10 SPTs are all delivered, never silently dropped.
|
||||
for (let i = 0; i < sptList.length; i += WxPusher.SPT_PER_REQUEST) {
|
||||
const context = {
|
||||
content: msg,
|
||||
summary,
|
||||
contentType: 1,
|
||||
sptList: sptList.slice(i, i + WxPusher.SPT_PER_REQUEST),
|
||||
};
|
||||
const result = await axios.post(
|
||||
"https://wxpusher.zjiecode.com/api/send/message/simple-push",
|
||||
context,
|
||||
config
|
||||
);
|
||||
if (result.data.code !== 1000) {
|
||||
throw result.data.msg;
|
||||
}
|
||||
}
|
||||
|
||||
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 = WxPusher;
|
||||
@@ -82,6 +82,7 @@ const GtxMessaging = require("./notification-providers/gtx-messaging");
|
||||
const Cellsynt = require("./notification-providers/cellsynt");
|
||||
const Onesender = require("./notification-providers/onesender");
|
||||
const Wpush = require("./notification-providers/wpush");
|
||||
const WxPusher = require("./notification-providers/wxpusher");
|
||||
const SendGrid = require("./notification-providers/send-grid");
|
||||
const Brevo = require("./notification-providers/brevo");
|
||||
const Resend = require("./notification-providers/resend");
|
||||
@@ -193,6 +194,7 @@ class Notification {
|
||||
new GtxMessaging(),
|
||||
new Cellsynt(),
|
||||
new Wpush(),
|
||||
new WxPusher(),
|
||||
new Brevo(),
|
||||
new Resend(),
|
||||
new YZJ(),
|
||||
|
||||
Reference in New Issue
Block a user