diff --git a/back/data/notify.ts b/back/data/notify.ts index 7772efa6..271e6348 100644 --- a/back/data/notify.ts +++ b/back/data/notify.ts @@ -1,3 +1,5 @@ +import { IncomingHttpHeaders } from 'http'; + export enum NotificationMode { 'gotify' = 'gotify', 'goCqHttpBot' = 'goCqHttpBot', @@ -12,6 +14,7 @@ export enum NotificationMode { 'iGot' = 'iGot', 'pushPlus' = 'pushPlus', 'email' = 'email', + 'webhook' = 'webhook', } abstract class NotificationBaseInfo { @@ -87,6 +90,13 @@ export class EmailNotification extends NotificationBaseInfo { public emailPass: string = ''; } +export class WebhookNotification extends NotificationBaseInfo { + public webhookHeaders: IncomingHttpHeaders = {}; + public webhookBody: any = {}; + public webhookUrl: string = ''; + public webhookMethod: 'GET' | 'POST' | 'PUT' = 'GET'; +} + export interface NotificationInfo extends GoCqHttpBotNotification, GotifyNotification, @@ -100,4 +110,5 @@ export interface NotificationInfo WeWorkAppNotification, IGotNotification, PushPlusNotification, - EmailNotification {} + EmailNotification, + WebhookNotification {} diff --git a/back/services/notify.ts b/back/services/notify.ts index 0f1c9a1e..daa7d4c6 100644 --- a/back/services/notify.ts +++ b/back/services/notify.ts @@ -26,6 +26,7 @@ export default class NotificationService { ['iGot', this.iGot], ['pushPlus', this.pushPlus], ['email', this.email], + ['webhook', this.webhook], ]); private timeout = 10000; @@ -383,4 +384,19 @@ export default class NotificationService { return !!info.messageId; } + + private async webhook() { + const { webhookUrl, webhookBody, webhookHeaders, webhookMethod } = + this.params; + + const { statusCode } = await got(webhookUrl, { + method: webhookMethod, + headers: webhookHeaders, + body: webhookBody, + timeout: this.timeout, + retry: 0, + }); + + return String(statusCode).includes('20'); + } } diff --git a/src/pages/setting/notification.tsx b/src/pages/setting/notification.tsx index ed5d7816..f98536c6 100644 --- a/src/pages/setting/notification.tsx +++ b/src/pages/setting/notification.tsx @@ -58,7 +58,9 @@ const NotificationSetting = ({ data }: any) => { > @@ -71,7 +73,10 @@ const NotificationSetting = ({ data }: any) => { rules={[{ required: x.required }]} style={{ maxWidth: 400 }} > - + ))}