Maybe a fix to ntfy being silly

This commit is contained in:
Christopher Cookman 2024-05-21 19:24:38 -06:00
parent 585c075072
commit e30af0143d
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -349,6 +349,28 @@ xmpp.on("stanza", (stanza) => {
}
}).then((res) => {
if (config.debug >= 1) console.log(`${colors.magenta("[DEBUG]")} NTFY sent for ${config.ntfy.prefix}${fromChannel} with status ${res.status}`);
if (res.status === 429) {// Rate limited, wait 5 seconds then try again
setTimeout(() => {
ntfyBody = {
"topic": `${config.ntfy.prefix}${fromChannel}`,
"message": bodyData.string,
"tags": [`Timestamp: ${product_id.timestamp}`, `Station: ${product_id.station}`, `WMO: ${product_id.wmo}`, `PIL: ${product_id.pil}`, `Channel: ${fromChannel}`],
"priority": evt.priority,
"actions": [{ "action": "view", "label": "Product", "url": bodyData.url }, { "action": "view", "label": "Product Text", "url": `https://mesonet.agron.iastate.edu/api/1/nwstext/${product_id_raw}` }]
}
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}`
}
})
}, 5000)
}
}).catch((err) => {
console.error(err)