From 931638b687f338e4ebb57191d2526e04973714ed Mon Sep 17 00:00:00 2001 From: whyour Date: Tue, 20 Sep 2022 01:16:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89ho?= =?UTF-8?q?ok=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/data/notify.ts | 13 ++++++++++++- back/services/notify.ts | 16 ++++++++++++++++ src/pages/setting/notification.tsx | 9 +++++++-- src/utils/config.ts | 25 +++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 3 deletions(-) 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 }} > - + ))}