uptime-kuma/server/notification-providers/pushover.js

59 lines
1.8 KiB
JavaScript
Raw Normal View History

const { getMonitorRelativeURL } = require("../../src/util");
const { setting } = require("../util-server");
2021-09-07 10:42:46 -04:00
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
class Pushover extends NotificationProvider {
name = "pushover";
/**
* @inheritdoc
*/
2021-09-07 10:42:46 -04:00
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";
const url = "https://api.pushover.net/1/messages.json";
2021-09-07 10:42:46 -04:00
2022-03-24 00:14:17 -04:00
let data = {
2023-01-21 00:59:11 -05:00
"message": msg,
2022-03-24 00:14:17 -04:00
"user": notification.pushoveruserkey,
"token": notification.pushoverapptoken,
"sound": notification.pushoversounds,
"priority": notification.pushoverpriority,
"title": notification.pushovertitle,
"retry": "30",
"expire": "3600",
"html": 1,
};
const baseURL = await setting("primaryBaseURL");
if (baseURL && monitorJSON) {
data["url"] = baseURL + getMonitorRelativeURL(monitorJSON.id);
data["url_title"] = "Link to Monitor";
}
2022-03-24 00:14:17 -04:00
if (notification.pushoverdevice) {
data.device = notification.pushoverdevice;
}
if (notification.pushoverttl) {
data.ttl = notification.pushoverttl;
}
2022-03-24 00:14:17 -04:00
2021-09-07 10:42:46 -04:00
try {
if (heartbeatJSON == null) {
await axios.post(url, data);
2022-03-24 00:14:17 -04:00
return okMsg;
} else {
data.message += `\n<b>Time (${heartbeatJSON["timezone"]})</b>:${heartbeatJSON["localDateTime"]}`;
await axios.post(url, data);
2021-09-07 10:42:46 -04:00
return okMsg;
}
} catch (error) {
2021-11-29 04:19:55 -05:00
this.throwGeneralAxiosError(error);
2021-09-07 10:42:46 -04:00
}
}
}
module.exports = Pushover;