Add support for Pushdeer notifications

This commit is contained in:
ngc7331
2022-04-02 14:40:33 +08:00
committed by Louis Lam
parent 2e3414135f
commit fb059f5e91
4 changed files with 75 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { DOWN, UP } = require("../../src/util");
class Pushdeer extends NotificationProvider {
name = "Pushdeer";
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully.";
let pushdeerlink = "https://api2.pushdeer.com/message/push";
let valid = msg != null && monitorJSON != null && heartbeatJSON != null;
let title;
if (valid && heartbeatJSON.status == UP) {
title = "## UptimeKuma: " + monitorJSON.name + " up";
} else if (valid && heartbeatJSON.status == DOWN) {
title = "## UptimeKuma: " + monitorJSON.name + " down";
} else {
title = "## UptimeKuma Message";
}
let data = {
"pushkey": notification.pushdeerKey,
"text": title,
"desp": msg.replace(/\n/g, "\n\n"),
"type": "markdown",
};
try {
let res = await axios.post(pushdeerlink, data);
if ("error" in res.data) {
let error = res.data.error;
this.throwGeneralAxiosError(error);
}
if (res.data.content.result.length === 0) {
let error = "Invalid Pushdeer key";
this.throwGeneralAxiosError(error);
} else if (JSON.parse(res.data.content.result[0]).success != "ok") {
let error = "Unknown error";
this.throwGeneralAxiosError(error);
}
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}
module.exports = Pushdeer;

View File

@@ -32,6 +32,7 @@ const GoogleChat = require("./notification-providers/google-chat");
const Gorush = require("./notification-providers/gorush");
const Alerta = require("./notification-providers/alerta");
const OneBot = require("./notification-providers/onebot");
const Pushdeer = require("./notification-providers/pushdeer");
class Notification {
@@ -75,6 +76,7 @@ class Notification {
new Gorush(),
new Alerta(),
new OneBot(),
new Pushdeer(),
];
for (let item of list) {