From e30af0143d1aee923de5499bd8446edaed3c50d7 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Tue, 21 May 2024 19:24:38 -0600 Subject: [PATCH] Maybe a fix to ntfy being silly --- index.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/index.js b/index.js index df3687c..f4434d8 100644 --- a/index.js +++ b/index.js @@ -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)