perf: 通知管理

This commit is contained in:
xiaojunnuo
2024-11-22 17:12:39 +08:00
parent 131ed13df1
commit d9a00eeaf7
30 changed files with 1031 additions and 30 deletions
@@ -0,0 +1,30 @@
import { BaseNotification, IsNotification, NotificationBody, NotificationInput } from '@certd/pipeline';
@IsNotification({
name: 'email',
title: '电子邮件',
desc: '电子邮件通知',
})
export class EmailNotification extends BaseNotification {
@NotificationInput({
title: '收件人邮箱',
component: {
name: 'a-select',
vModel: 'value',
mode: 'tags',
open: false,
},
required: true,
helper: '可以填写多个,填写一个按回车键再填写下一个',
})
receivers!: string[];
async send(body: NotificationBody) {
await this.ctx.emailService.send({
userId: body.userId,
subject: body.title,
content: body.content,
receivers: this.receivers,
});
}
}
@@ -0,0 +1,2 @@
export * from './qywx/index.js';
export * from './email/index.js';
@@ -0,0 +1,54 @@
import { BaseNotification, IsNotification, NotificationBody, NotificationInput } from '@certd/pipeline';
@IsNotification({
name: 'qywx',
title: '企业微信通知',
desc: '企业微信群聊机器人通知',
})
export class QywxNotification extends BaseNotification {
@NotificationInput({
title: 'webhook地址',
component: {
placeholder: 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxx',
},
required: true,
})
webhook = '';
@NotificationInput({
title: '提醒指定成员',
component: {
name: 'a-select',
vModel: 'value',
mode: 'tags',
open: false,
},
required: false,
helper: '填写成员名字,@all 为提醒所有人',
})
mentionedList!: string[];
async send(body: NotificationBody) {
console.log('send qywx');
/**
*
* "msgtype": "text",
* "text": {
* "content": "hello world"
* }
* }
*/
await this.http.request({
url: this.webhook,
data: {
msgtype: 'markdown',
text: {
content: `# ${body.title}\n\n${body.content}\n[查看详情](${body.url})`,
mentioned_list: this.mentionedList,
},
},
});
}
}