增加微加机器人消息通道 (#2373)

Co-authored-by: chensiyuan <chensiyuan@pushplus.plus>
This commit is contained in:
陈大人
2024-05-25 00:33:31 +08:00
committed by GitHub
parent b309ac7613
commit e77d4c4337
8 changed files with 198 additions and 14 deletions
+9 -1
View File
@@ -14,6 +14,7 @@ export enum NotificationMode {
'aibotk' = 'aibotk',
'iGot' = 'iGot',
'pushPlus' = 'pushPlus',
'wePlusBot' = 'wePlusBot',
'email' = 'email',
'pushMe' = 'pushMe',
'feishu' = 'feishu',
@@ -100,6 +101,12 @@ export class PushPlusNotification extends NotificationBaseInfo {
public pushPlusUser = '';
}
export class WePlusBotNotification extends NotificationBaseInfo {
public wePlusBotToken = '';
public wePlusBotReceiver = '';
public wePlusBotVersion = '';
}
export class EmailNotification extends NotificationBaseInfo {
public emailService: string = '';
public emailUser: string = '';
@@ -146,9 +153,10 @@ export interface NotificationInfo
AibotkNotification,
IGotNotification,
PushPlusNotification,
WePlusBotNotification,
EmailNotification,
PushMeNotification,
WebhookNotification,
ChronocatNotification,
LarkNotification {}
+37
View File
@@ -27,6 +27,7 @@ export default class NotificationService {
['aibotk', this.aibotk],
['iGot', this.iGot],
['pushPlus', this.pushPlus],
['wePlusBot',this.wePlusBot],
['email', this.email],
['pushMe', this.pushMe],
['webhook', this.webhook],
@@ -513,6 +514,42 @@ export default class NotificationService {
}
}
private async wePlusBot() {
const { wePlusBotToken, wePlusBotReceiver, wePlusBotVersion } = this.params;
let content = this.content;
let template = 'txt';
if(this.content.length>800){
template = 'html';
content = content.replace(/[\n\r]/g, '<br>');
}
const url = `https://www.weplusbot.com/send`;
try {
const res: any = await got
.post(url, {
...this.gotOption,
json: {
token: `${wePlusBotToken}`,
title: `${this.title}`,
template: `${template}`,
content: `${content}`,
receiver: `${wePlusBotReceiver || ''}`,
version: `${wePlusBotVersion || 'pro'}`,
},
})
.json();
if (res.code === 200) {
return true;
} else {
throw new Error(JSON.stringify(res));
}
} catch (error: any) {
throw new Error(error.response ? error.response.body : error);
}
}
private async lark() {
let { larkKey } = this.params;