mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-24 23:57:37 +08:00
增加自定义hook通知
This commit is contained in:
parent
4d9bbcfd3f
commit
931638b687
|
@ -1,3 +1,5 @@
|
||||||
|
import { IncomingHttpHeaders } from 'http';
|
||||||
|
|
||||||
export enum NotificationMode {
|
export enum NotificationMode {
|
||||||
'gotify' = 'gotify',
|
'gotify' = 'gotify',
|
||||||
'goCqHttpBot' = 'goCqHttpBot',
|
'goCqHttpBot' = 'goCqHttpBot',
|
||||||
|
@ -12,6 +14,7 @@ export enum NotificationMode {
|
||||||
'iGot' = 'iGot',
|
'iGot' = 'iGot',
|
||||||
'pushPlus' = 'pushPlus',
|
'pushPlus' = 'pushPlus',
|
||||||
'email' = 'email',
|
'email' = 'email',
|
||||||
|
'webhook' = 'webhook',
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class NotificationBaseInfo {
|
abstract class NotificationBaseInfo {
|
||||||
|
@ -87,6 +90,13 @@ export class EmailNotification extends NotificationBaseInfo {
|
||||||
public emailPass: string = '';
|
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
|
export interface NotificationInfo
|
||||||
extends GoCqHttpBotNotification,
|
extends GoCqHttpBotNotification,
|
||||||
GotifyNotification,
|
GotifyNotification,
|
||||||
|
@ -100,4 +110,5 @@ export interface NotificationInfo
|
||||||
WeWorkAppNotification,
|
WeWorkAppNotification,
|
||||||
IGotNotification,
|
IGotNotification,
|
||||||
PushPlusNotification,
|
PushPlusNotification,
|
||||||
EmailNotification {}
|
EmailNotification,
|
||||||
|
WebhookNotification {}
|
||||||
|
|
|
@ -26,6 +26,7 @@ export default class NotificationService {
|
||||||
['iGot', this.iGot],
|
['iGot', this.iGot],
|
||||||
['pushPlus', this.pushPlus],
|
['pushPlus', this.pushPlus],
|
||||||
['email', this.email],
|
['email', this.email],
|
||||||
|
['webhook', this.webhook],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
private timeout = 10000;
|
private timeout = 10000;
|
||||||
|
@ -383,4 +384,19 @@ export default class NotificationService {
|
||||||
|
|
||||||
return !!info.messageId;
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,9 @@ const NotificationSetting = ({ data }: any) => {
|
||||||
>
|
>
|
||||||
<Select onChange={notificationModeChange}>
|
<Select onChange={notificationModeChange}>
|
||||||
{config.notificationModes.map((x) => (
|
{config.notificationModes.map((x) => (
|
||||||
<Option value={x.value}>{x.label}</Option>
|
<Option key={x.value} value={x.value}>
|
||||||
|
{x.label}
|
||||||
|
</Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
@ -71,7 +73,10 @@ const NotificationSetting = ({ data }: any) => {
|
||||||
rules={[{ required: x.required }]}
|
rules={[{ required: x.required }]}
|
||||||
style={{ maxWidth: 400 }}
|
style={{ maxWidth: 400 }}
|
||||||
>
|
>
|
||||||
<Input.TextArea autoSize={true} placeholder={`请输入${x.label}`} />
|
<Input.TextArea
|
||||||
|
autoSize={true}
|
||||||
|
placeholder={x.placeholder || `请输入${x.label}`}
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
))}
|
))}
|
||||||
<Button type="primary" htmlType="submit">
|
<Button type="primary" htmlType="submit">
|
||||||
|
|
|
@ -92,6 +92,7 @@ export default {
|
||||||
{ value: 'pushPlus', label: 'PushPlus' },
|
{ value: 'pushPlus', label: 'PushPlus' },
|
||||||
{ value: 'chat', label: '群辉chat' },
|
{ value: 'chat', label: '群辉chat' },
|
||||||
{ value: 'email', label: '邮箱' },
|
{ value: 'email', label: '邮箱' },
|
||||||
|
{ value: 'webhook', label: '自定义通知' },
|
||||||
{ value: 'closed', label: '已关闭' },
|
{ value: 'closed', label: '已关闭' },
|
||||||
],
|
],
|
||||||
notificationModeMap: {
|
notificationModeMap: {
|
||||||
|
@ -222,6 +223,30 @@ export default {
|
||||||
{ label: 'emailUser', tip: '邮箱地址', required: true },
|
{ label: 'emailUser', tip: '邮箱地址', required: true },
|
||||||
{ label: 'emailPass', tip: '邮箱SMTP授权码', required: true },
|
{ label: 'emailPass', tip: '邮箱SMTP授权码', required: true },
|
||||||
],
|
],
|
||||||
|
webhook: [
|
||||||
|
{
|
||||||
|
label: 'webhookMethod',
|
||||||
|
tip: '请求方法',
|
||||||
|
required: true,
|
||||||
|
placeholder: '请输入 GET/POST/PUT',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'webhookUrl',
|
||||||
|
tip: '请求链接',
|
||||||
|
required: true,
|
||||||
|
placeholder: 'https://xxx.cn/api?query=xxx',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'webhookHeaders',
|
||||||
|
tip: '请求头',
|
||||||
|
placeholder: '{"Custom-Header": "$Header"}',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'webhookBody',
|
||||||
|
tip: '请求体',
|
||||||
|
placeholder: '{"status": "$STATUS"}',
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
documentTitleMap: {
|
documentTitleMap: {
|
||||||
'/login': '登录',
|
'/login': '登录',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user