Files
certd/packages/ui/certd-server/src/plugins/plugin-notification/slack/index.ts
T

57 lines
1.3 KiB
TypeScript
Raw Normal View History

2026-05-31 01:41:33 +08:00
import { BaseNotification, IsNotification, NotificationBody, NotificationInput } from "@certd/pipeline";
@IsNotification({
2026-05-31 01:41:33 +08:00
name: "slack",
title: "Slack通知",
desc: "Slack消息推送通知",
2024-11-30 01:57:09 +08:00
needPlus: true,
})
export class SlackNotification extends BaseNotification {
@NotificationInput({
2026-05-31 01:41:33 +08:00
title: "webhook地址",
component: {
2026-05-31 01:41:33 +08:00
placeholder: "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
},
2026-05-31 01:41:33 +08:00
helper: "[APPS](https://api.slack.com/apps/)->进入APP->incoming-webhooks->Add New Webhook to Workspace",
required: true,
})
2026-05-31 01:41:33 +08:00
webhook = "";
2024-12-02 14:06:55 +08:00
@NotificationInput({
2026-05-31 01:41:33 +08:00
title: "代理",
2024-12-02 14:06:55 +08:00
component: {
2026-05-31 01:41:33 +08:00
placeholder: "http://xxxxx:xx",
2024-12-02 14:06:55 +08:00
},
2026-05-31 01:41:33 +08:00
helper: "使用https_proxy",
2024-12-02 14:06:55 +08:00
required: false,
})
2026-05-31 01:41:33 +08:00
httpsProxy = "";
2024-12-02 14:06:55 +08:00
@NotificationInput({
2026-05-31 01:41:33 +08:00
title: "忽略证书校验",
2024-12-02 14:06:55 +08:00
value: false,
component: {
2026-05-31 01:41:33 +08:00
name: "a-switch",
vModel: "checked",
2024-12-02 14:06:55 +08:00
},
required: false,
})
skipSslVerify: boolean;
async send(body: NotificationBody) {
if (!this.webhook) {
2026-05-31 01:41:33 +08:00
throw new Error("token不能为空");
}
await this.http.request({
url: this.webhook,
2026-05-31 01:41:33 +08:00
method: "POST",
data: {
2024-12-03 10:32:47 +08:00
text: `${body.title}\n${body.content}\n\n[查看详情](${body.url})`,
},
2024-12-02 14:06:55 +08:00
httpProxy: this.httpsProxy,
skipSslVerify: this.skipSslVerify,
});
}
}