From ad42d730f87322d2975b2d6566e175594d6c3413 Mon Sep 17 00:00:00 2001 From: violet Date: Sun, 24 Aug 2025 21:27:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20NTFY=20=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sendNotify.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/sendNotify.js b/sendNotify.js index 6d95426..91b95c4 100644 --- a/sendNotify.js +++ b/sendNotify.js @@ -136,6 +136,15 @@ let GOTIFY_URL = ''; let GOTIFY_TOKEN = ''; let GOTIFY_PRIORITY = 0; +// =======================================ntfy 通知设置区域============================================== +//ntfy_url 填写 ntfy 地址,如https://push.example.de:8080 +//ntfy_token 填写 ntfy 的消息应用token +//ntfy_priority 填写推送消息优先级,默认为0 +let NTFY_URL = ''; +let NTFY_TOKEN = ''; +let NTFY_TOPIC = ''; +let NTFY_PRIORITY = 3; + // =======================================BncrBot通知设置区域============================================== //BncrHost 填写BncrHost地址,如https://192.168.31.192:9090 //BncrToken 填写Bncr的消息应用Token @@ -727,6 +736,18 @@ async function sendNotify(text, desp, params = {}, author = "",strsummary="") { if (process.env["GOTIFY_PRIORITY" + UseGroupNotify]) { GOTIFY_PRIORITY = process.env["GOTIFY_PRIORITY" + UseGroupNotify]; } + if (process.env["NTFY_URL" + UseGroupNotify]) { + NTFY_URL = process.env["NTFY_URL" + UseGroupNotify]; + } + if (process.env["NTFY_TOKEN" + UseGroupNotify]) { + NTFY_TOKEN = process.env["NTFY_TOKEN" + UseGroupNotify]; + } + if (process.env["NTFY_TOPIC" + UseGroupNotify]) { + NTFY_TOPIC = process.env["NTFY_TOPIC" + UseGroupNotify]; + } + if (process.env["NTFY_PRIORITY" + UseGroupNotify]) { + NTFY_PRIORITY = process.env["NTFY_PRIORITY" + UseGroupNotify]; + } if (process.env["BncrHost" + UseGroupNotify]) { BncrHost = process.env["BncrHost" + UseGroupNotify]; } @@ -907,6 +928,7 @@ async function sendNotify(text, desp, params = {}, author = "",strsummary="") { iGotNotify(text, desp, params), //iGot gobotNotify(text, desp), //go-cqhttp gotifyNotify(text, desp), //gotify + ntfyNotify(text, desp), //ntfy bncrNotify(text, desp), //bncr wxpusherNotify(text, desp), // wxpusher PushDeerNotify(text, desp) //pushdeer推送 @@ -1255,6 +1277,53 @@ function gotifyNotify(text, desp) { }); } +function encodeRFC2047(str) { + return `=?UTF-8?B?${Buffer.from(str, 'utf8').toString('base64')}?=`; +} + +function ntfyNotify(text, desp) { + console.log('ntfy发送通知\n'); + console.log('NTFY_URL:', NTFY_URL); + console.log('NTFY_TOKEN:', NTFY_TOKEN); + console.log('NTFY_TOPIC:', NTFY_TOPIC); + return new Promise((resolve) => { + if (NTFY_URL && NTFY_TOKEN && NTFY_TOPIC) { + const options = { + url: `${NTFY_URL}/${NTFY_TOPIC}?auth=${NTFY_TOKEN}`, + body: Buffer.from(desp, 'utf-8').toString(), + headers: { + 'Icon': 'https://user-images.githubusercontent.com/22700758/191449379-f9f56204-0e31-4a16-be5a-331f52696a73.png', + 'Title': encodeRFC2047(text), + 'Priority': `${NTFY_PRIORITY}`, + } + }; + console.log('ntfy options:', options); // 打印 options 内容 + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log('ntfy发送通知调用API失败!!\n'); + console.log(err); + } else { + data = JSON.parse(data); + if (data.id) { + console.log('ntfy发送通知消息成功🎉\n'); + } else { + console.log(`${data.message}\n`); + } + } + } catch (e) { + $.logErr(e, resp); + } + finally { + resolve(); + } + }); + } else { + resolve(); + } + }); +} + function gobotNotify(text, desp, time = 2100) { return new Promise((resolve) => { if (GOBOT_URL) { From 3661cd34bf29621722deb3515184862c133f45ce Mon Sep 17 00:00:00 2001 From: violet Date: Tue, 26 Aug 2025 11:02:36 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20NTFY=20Action=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sendNotify.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sendNotify.js b/sendNotify.js index 91b95c4..24693b2 100644 --- a/sendNotify.js +++ b/sendNotify.js @@ -144,6 +144,7 @@ let NTFY_URL = ''; let NTFY_TOKEN = ''; let NTFY_TOPIC = ''; let NTFY_PRIORITY = 3; +let NTFY_ACTIONS = ''; // =======================================BncrBot通知设置区域============================================== //BncrHost 填写BncrHost地址,如https://192.168.31.192:9090 @@ -748,6 +749,9 @@ async function sendNotify(text, desp, params = {}, author = "",strsummary="") { if (process.env["NTFY_PRIORITY" + UseGroupNotify]) { NTFY_PRIORITY = process.env["NTFY_PRIORITY" + UseGroupNotify]; } + if (process.env["NTFY_ACTIONS" + UseGroupNotify]) { + NTFY_ACTIONS = process.env["NTFY_ACTIONS" + UseGroupNotify]; + } if (process.env["BncrHost" + UseGroupNotify]) { BncrHost = process.env["BncrHost" + UseGroupNotify]; } @@ -1295,6 +1299,7 @@ function ntfyNotify(text, desp) { 'Icon': 'https://user-images.githubusercontent.com/22700758/191449379-f9f56204-0e31-4a16-be5a-331f52696a73.png', 'Title': encodeRFC2047(text), 'Priority': `${NTFY_PRIORITY}`, + 'Actions': `${NTFY_ACTIONS}`, } }; console.log('ntfy options:', options); // 打印 options 内容