diff --git a/back/data/notify.ts b/back/data/notify.ts index ec20bb6a..97eae7c2 100644 --- a/back/data/notify.ts +++ b/back/data/notify.ts @@ -4,6 +4,7 @@ export enum NotificationMode { 'serverChan' = 'serverChan', 'pushDeer' = 'pushDeer', 'bark' = 'bark', + 'chat' = 'chat' 'telegramBot' = 'telegramBot', 'dingtalkBot' = 'dingtalkBot', 'weWorkBot' = 'weWorkBot', @@ -37,6 +38,11 @@ export class PushDeerNotification extends NotificationBaseInfo { public pushDeerKey = ''; } +export class ChatNotification extends NotificationBaseInfo { + public chatUrl = ''; + public chattoken = ''; +} + export class BarkNotification extends NotificationBaseInfo { public barkPush = ''; public barkIcon = 'http://qn.whyour.cn/logo.png'; @@ -86,6 +92,7 @@ export interface NotificationInfo GotifyNotification, ServerChanNotification, PushDeerNotification, + ChatNotification, BarkNotification, TelegramBotNotification, DingtalkBotNotification, diff --git a/back/services/notify.ts b/back/services/notify.ts index fac042be..dcb39c10 100644 --- a/back/services/notify.ts +++ b/back/services/notify.ts @@ -17,6 +17,7 @@ export default class NotificationService { ['goCqHttpBot', this.goCqHttpBot], ['serverChan', this.serverChan], ['pushDeer', this.pushDeer], + ['chat', this.chat], ['bark', this.bark], ['telegramBot', this.telegramBot], ['dingtalkBot', this.dingtalkBot], @@ -135,6 +136,22 @@ export default class NotificationService { ); } + private async chat() { + const { chatUrl, chattoken } = this.params; + const url = `${chatUrl}${chattoken}`; + const res: any = await got + .post(url, { + timeout: this.timeout, + retry: 0, + body: `payload={"text":"${this.title}\n${this.content}"}`, + headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, + }) + .json(); + return ( + res.success + ); + } + private async bark() { let { barkPush, barkIcon, barkSound, barkGroup } = this.params; if (!barkPush.startsWith('http') && !barkPush.startsWith('https')) { diff --git a/sample/config.sample.sh b/sample/config.sample.sh index 6d97051d..066a22e5 100644 --- a/sample/config.sample.sh +++ b/sample/config.sample.sh @@ -137,4 +137,10 @@ export GOTIFY_PRIORITY=0 ## deer_key 填写PushDeer的key export DEER_KEY="" +## 12. Chat +## chat_url 填写synology chat地址,http://IP:PORT/webapi/***token= +## chat_token 填写后面的token +export CHAT_URL="" +export CHAT_TOKEN="" + ## 其他需要的变量,脚本中需要的变量使用 export 变量名= 声明即可 diff --git a/sample/notify.js b/sample/notify.js index fb857392..9f9305cb 100644 --- a/sample/notify.js +++ b/sample/notify.js @@ -39,6 +39,12 @@ let SCKEY = ''; //(环境变量名 DEER_KEY) let PUSHDEER_KEY = ''; +// =======================================Synology Chat通知设置区域=========================================== +//此处填你申请的CHAT_URL与CHAT_TOKEN +//(环境变量名 CHAT_URL CHAT_TOKEN) +let CHAT_URL = ''; +let CHAT_TOKEN = ''; + // =======================================Bark App通知设置区域=========================================== //此处填你BarkAPP的信息(IP/设备码,例如:https://api.day.app/XXXXXXXX) let BARK_PUSH = ''; @@ -133,6 +139,14 @@ if (process.env.DEER_KEY) { PUSHDEER_KEY = process.env.DEER_KEY; } +if (process.env.CHAT_URL) { + CHAT_URL = process.env.CHAT_URL; +} + +if (process.env.CHAT_TOKEN) { + CHAT_TOKEN = process.env.CHAT_TOKEN; +} + if (process.env.QQ_SKEY) { QQ_SKEY = process.env.QQ_SKEY; } @@ -239,6 +253,7 @@ async function sendNotify( iGotNotify(text, desp, params), //iGot gobotNotify(text, desp), //go-cqhttp gotifyNotify(text, desp), //gotify + ChatNotify(text, desp), //synolog chat ]); } @@ -415,6 +430,49 @@ function PushDeerNotify(text, desp, time = 2100) { }); } +function ChatNotify(text, desp, time = 2100) { + return new Promise((resolve) => { + if (CHAT_URL && CHAT_TOKEN ) { + // 对消息内容进行 urlencode + desp = encodeURI(desp); + const options = { + url: `${CHAT_URL}${CHAT_TOKEN}`, + body: `payload={"text":"${text}\n${desp}"}`, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + }; + setTimeout(() => { + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log('发送通知调用API失败!!\n'); + console.log(err); + } else { + data = JSON.parse(data); + if ( + data.success + ) { + console.log('Chat发送通知消息成功🎉\n'); + } else { + console.log( + `Chat发送通知消息异常\n${JSON.stringify(data)}`, + ); + } + } + } catch (e) { + $.logErr(e); + } finally { + resolve(data); + } + }); + }, time); + } else { + resolve(); + } + }); +} + function CoolPush(text, desp) { return new Promise((resolve) => { if (QQ_SKEY) { diff --git a/sample/notify.py b/sample/notify.py index 721703ba..e5d48d5a 100644 --- a/sample/notify.py +++ b/sample/notify.py @@ -61,7 +61,10 @@ push_config = { 'PUSH_KEY': '', # server 酱的 PUSH_KEY,兼容旧版与 Turbo 版 'DEER_KEY': '', # PushDeer 的 PUSHDEER_KEY - + + 'CHAT_URL': '', # synology chat url + 'CHAT_TOKEN': '', # synology chat token + 'PUSH_PLUS_TOKEN': '', # push+ 微信推送的用户令牌 'PUSH_PLUS_USER': '', # push+ 微信推送的群组编码 @@ -279,8 +282,27 @@ def pushdeer(title: str, content: str) -> None: print("PushDeer 推送成功!") else: print("PushDeer 推送失败!错误信息:", response) - + +def chat(title: str, content: str) -> None: + """ + 通过Chat 推送消息 + """ + if not push_config.get("CHAT_URL") or not push_config.get("CHAT_TOKEN"): + print("chat 服务的 CHAT_URL或CHAT_TOKEN 未设置!!\n取消推送") + return + print("chat 服务启动") + data = 'payload=' + json.dumps({'text': title + '\n' + content}) + url = push_config.get("CHAT_URL") + push_config.get("CHAT_TOKEN") + response = requests.post(url, data=data) + + if response.status_code == 200: + print("Chat 推送成功!") + else: + print("Chat 推送失败!错误信息:", response) + + + def pushplus_bot(title: str, content: str) -> None: """ 通过 push+ 推送消息。 @@ -527,6 +549,8 @@ if push_config.get("PUSH_KEY"): notify_function.append(serverJ) if push_config.get("DEER_KEY"): notify_function.append(pushdeer) +if push_config.get("CHAT_URL") and push_config.get("CHAT_TOKEN"): + notify_function.append(chat) if push_config.get("PUSH_PLUS_TOKEN"): notify_function.append(pushplus_bot) if push_config.get("QMSG_KEY") and push_config.get("QMSG_TYPE"): diff --git a/src/utils/config.ts b/src/utils/config.ts index e2d596db..bc545c51 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -90,6 +90,7 @@ export default { { value: 'weWorkApp', label: '企业微信应用' }, { value: 'iGot', label: 'IGot' }, { value: 'pushPlus', label: 'PushPlus' }, + { value: 'chat', label: 'chat' }, { value: 'email', label: '邮箱' }, { value: 'closed', label: '已关闭' }, ], @@ -103,6 +104,14 @@ export default { { label: 'gotifyToken', tip: 'gotify的消息应用token码', required: true }, { label: 'gotifyPriority', tip: '推送消息的优先级' }, ], + chat: [ + { + label: 'chatUrl', + tip: 'chat的url地址', + required: true, + }, + { label: 'chattoken', tip: 'chat的token码', required: true }, + ], goCqHttpBot: [ { label: 'goCqHttpBotUrl',