From 4da8d8fe1eddbf68163350d3fa863f83ca3cb3c7 Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 4 Sep 2022 18:25:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dnode=20pushdeer=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/data/notify.ts | 4 +-- back/services/notify.ts | 8 +++--- sample/notify.js | 55 +++++++++++++++++++---------------------- src/utils/config.ts | 4 +-- 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/back/data/notify.ts b/back/data/notify.ts index 97eae7c2..7772efa6 100644 --- a/back/data/notify.ts +++ b/back/data/notify.ts @@ -4,7 +4,7 @@ export enum NotificationMode { 'serverChan' = 'serverChan', 'pushDeer' = 'pushDeer', 'bark' = 'bark', - 'chat' = 'chat' + 'chat' = 'chat', 'telegramBot' = 'telegramBot', 'dingtalkBot' = 'dingtalkBot', 'weWorkBot' = 'weWorkBot', @@ -40,7 +40,7 @@ export class PushDeerNotification extends NotificationBaseInfo { export class ChatNotification extends NotificationBaseInfo { public chatUrl = ''; - public chattoken = ''; + public chatToken = ''; } export class BarkNotification extends NotificationBaseInfo { diff --git a/back/services/notify.ts b/back/services/notify.ts index dcb39c10..0f1c9a1e 100644 --- a/back/services/notify.ts +++ b/back/services/notify.ts @@ -137,8 +137,8 @@ export default class NotificationService { } private async chat() { - const { chatUrl, chattoken } = this.params; - const url = `${chatUrl}${chattoken}`; + const { chatUrl, chatToken } = this.params; + const url = `${chatUrl}${chatToken}`; const res: any = await got .post(url, { timeout: this.timeout, @@ -147,9 +147,7 @@ export default class NotificationService { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, }) .json(); - return ( - res.success - ); + return res.success; } private async bark() { diff --git a/sample/notify.js b/sample/notify.js index 9f9305cb..6406cdd2 100644 --- a/sample/notify.js +++ b/sample/notify.js @@ -254,6 +254,7 @@ async function sendNotify( gobotNotify(text, desp), //go-cqhttp gotifyNotify(text, desp), //gotify ChatNotify(text, desp), //synolog chat + PushDeerNotify(text, desp), //PushDeer ]); } @@ -384,7 +385,7 @@ function serverNotify(text, desp, time = 2100) { }); } -function PushDeerNotify(text, desp, time = 2100) { +function PushDeerNotify(text, desp) { return new Promise((resolve) => { if (PUSHDEER_KEY) { // PushDeer 建议对消息内容进行 urlencode @@ -397,8 +398,9 @@ function PushDeerNotify(text, desp, time = 2100) { }, timeout, }; - setTimeout(() => { - $.post(options, (err, resp, data) => { + $.post( + options, + (err, resp, data) => { try { if (err) { console.log('发送通知调用API失败!!\n'); @@ -422,17 +424,18 @@ function PushDeerNotify(text, desp, time = 2100) { } finally { resolve(data); } - }); - }, time); + }, + time, + ); } else { resolve(); } }); } -function ChatNotify(text, desp, time = 2100) { +function ChatNotify(text, desp) { return new Promise((resolve) => { - if (CHAT_URL && CHAT_TOKEN ) { + if (CHAT_URL && CHAT_TOKEN) { // 对消息内容进行 urlencode desp = encodeURI(desp); const options = { @@ -442,31 +445,25 @@ function ChatNotify(text, desp, time = 2100) { 'Content-Type': 'application/x-www-form-urlencoded', }, }; - setTimeout(() => { - $.post(options, (err, resp, data) => { - try { - if (err) { - console.log('发送通知调用API失败!!\n'); - console.log(err); + $.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 { - data = JSON.parse(data); - if ( - data.success - ) { - console.log('Chat发送通知消息成功🎉\n'); - } else { - console.log( - `Chat发送通知消息异常\n${JSON.stringify(data)}`, - ); - } + console.log(`Chat发送通知消息异常\n${JSON.stringify(data)}`); } - } catch (e) { - $.logErr(e); - } finally { - resolve(data); } - }); - }, time); + } catch (e) { + $.logErr(e); + } finally { + resolve(data); + } + }); } else { resolve(); } diff --git a/src/utils/config.ts b/src/utils/config.ts index bc545c51..dfbe31c2 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -90,7 +90,7 @@ export default { { value: 'weWorkApp', label: '企业微信应用' }, { value: 'iGot', label: 'IGot' }, { value: 'pushPlus', label: 'PushPlus' }, - { value: 'chat', label: 'chat' }, + { value: 'chat', label: '群辉chat' }, { value: 'email', label: '邮箱' }, { value: 'closed', label: '已关闭' }, ], @@ -110,7 +110,7 @@ export default { tip: 'chat的url地址', required: true, }, - { label: 'chattoken', tip: 'chat的token码', required: true }, + { label: 'chatToken', tip: 'chat的token码', required: true }, ], goCqHttpBot: [ {