Skip to content

Commit 7e5464a

Browse files
committed
Created the pushover.js integration
1 parent f08434a commit 7e5464a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

server/integrations/pushover.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const axios = require("axios");
2+
const {replaceVariables} = require("../util/helpers");
3+
4+
const BASE_URL = "https://api.pushover.net/1";
5+
6+
const defaults = {
7+
finished: "A speedtest is finished:\nPing: %ping% ms\nUpload: %upload% Mbps\nDownload: %download% Mbps",
8+
failed: "A speedtest has failed. Reason: %error%"
9+
}
10+
11+
module.exports = (registerEvent) => {
12+
registerEvent('testFinished', async (integration, data, triggerActivity) => {
13+
if (!integration.data.send_finished) return;
14+
15+
const message = replaceVariables(integration.data.finished_message || defaults.finished, data);
16+
17+
axios.post(`${BASE_URL}/messages.json`, {
18+
token: integration.data.token,
19+
user: integration.data.user_key, message
20+
}).then(() => triggerActivity())
21+
.catch(() => triggerActivity(true));
22+
});
23+
24+
registerEvent('testFailed', async (integration, error, triggerActivity) => {
25+
if (!integration.data.send_failed) return;
26+
27+
const message = replaceVariables(integration.data.error_message || defaults.failed, {error});
28+
29+
axios.post(`${BASE_URL}/messages.json`, {
30+
token: integration.data.token,
31+
user: integration.data.user_key, message
32+
}).then(() => triggerActivity())
33+
.catch(() => triggerActivity(true));
34+
});
35+
36+
return {
37+
icon: "fa-solid fa-pushover",
38+
fields: [
39+
{name: "token", type: "text", required: true, regex: /^[a-z0-9]{30}$/},
40+
{name: "user_key", type: "text", required: true, regex: /^[a-z0-9]{30}$/},
41+
{name: "send_finished", type: "boolean", required: false},
42+
{name: "finished_message", type: "textarea", required: false},
43+
{name: "send_failed", type: "boolean", required: false},
44+
{name: "error_message", type: "textarea", required: false}
45+
]
46+
};
47+
}

0 commit comments

Comments
 (0)