修复node pushdeer通知

This commit is contained in:
whyour 2022-09-04 18:25:40 +08:00
parent 952cdc0e3f
commit 4da8d8fe1e
4 changed files with 33 additions and 38 deletions

View File

@ -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 {

View File

@ -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() {

View File

@ -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();
}

View File

@ -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: [
{