forked from ChrisChrome/weather-bot
Add NTFY push support
This commit is contained in:
parent
2d80073a56
commit
5cb0ff6cd9
33
index.js
33
index.js
|
@ -90,7 +90,7 @@ xmpp.on("offline", () => {
|
||||||
|
|
||||||
|
|
||||||
xmpp.on("stanza", (stanza) => {
|
xmpp.on("stanza", (stanza) => {
|
||||||
if(config.debug) console.log(stanza.toString());
|
if (config.debug >= 2) console.log(stanza.toString());
|
||||||
// Stops spam from getting old messages
|
// Stops spam from getting old messages
|
||||||
if (startup) return;
|
if (startup) return;
|
||||||
// Get new messages and log them, ignore old messages
|
// Get new messages and log them, ignore old messages
|
||||||
|
@ -110,6 +110,37 @@ xmpp.on("stanza", (stanza) => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const diff = (now - product_id.timestamp) / 1000 / 60;
|
const diff = (now - product_id.timestamp) / 1000 / 60;
|
||||||
if (diff > 3) return;
|
if (diff > 3) return;
|
||||||
|
if (config.debug >= 1) console.log(`New message from ${fromChannel}`);
|
||||||
|
// Handle NTFY
|
||||||
|
if (config.ntfy.enabled) {
|
||||||
|
if(config.debug >= 1) console.log(`Sending NTFY for ${config.ntfy.prefix}${fromChannel}`)
|
||||||
|
ntfyBody = {
|
||||||
|
"topic": `${config.ntfy.prefix}${fromChannel}`,
|
||||||
|
"message": body,
|
||||||
|
"title": "New Alert",
|
||||||
|
"tags": [`Timestamp: ${product_id.timestamp}`, `Station: ${product_id.station}`, `WMO: ${product_id.wmo}`, `PIL: ${product_id.pil}`, `Channel: ${fromChannel}`],
|
||||||
|
"priority": 3,
|
||||||
|
|
||||||
|
}
|
||||||
|
if (stanza.getChild("x").attrs.twitter_media) {
|
||||||
|
ntfyBody.attach = stanza.getChild("x").attrs.twitter_media;
|
||||||
|
}
|
||||||
|
fetch(config.ntfy.server, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(ntfyBody),
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${config.ntfy.token}`
|
||||||
|
}
|
||||||
|
}).then((res) => {
|
||||||
|
if (config.debug >= 1) console.log(res.status)
|
||||||
|
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error(err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Send discord msg
|
||||||
let embed = {
|
let embed = {
|
||||||
title: "New Alert",
|
title: "New Alert",
|
||||||
description: body,
|
description: body,
|
||||||
|
|
Loading…
Reference in a new issue