feat: add webhook notification
This commit is contained in:
parent
ee16e6cd76
commit
90df8e8e36
@ -3,6 +3,7 @@ import { NotificationSMTP } from './smtp';
|
|||||||
import { NotificationTelegram } from './telegram';
|
import { NotificationTelegram } from './telegram';
|
||||||
import { NotificationApprise } from './apprise';
|
import { NotificationApprise } from './apprise';
|
||||||
import { NotificationFeishu } from './feishu';
|
import { NotificationFeishu } from './feishu';
|
||||||
|
import { NotificationWebhook } from './webhook';
|
||||||
|
|
||||||
interface NotificationStrategy {
|
interface NotificationStrategy {
|
||||||
label: string;
|
label: string;
|
||||||
@ -31,4 +32,9 @@ export const notificationStrategies: NotificationStrategy[] = [
|
|||||||
name: 'feishu',
|
name: 'feishu',
|
||||||
form: NotificationFeishu,
|
form: NotificationFeishu,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Webhook',
|
||||||
|
name: 'webhook',
|
||||||
|
form: NotificationWebhook,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
import { Form, Input } from 'antd';
|
||||||
|
import React from 'react';
|
||||||
|
import { useTranslation } from '@i18next-toolkit/react';
|
||||||
|
|
||||||
|
export const NotificationWebhook: React.FC = React.memo(() => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Form.Item
|
||||||
|
label={t('Webhook URL')}
|
||||||
|
name={['payload', 'webhookUrl']}
|
||||||
|
rules={[{ required: true }]}
|
||||||
|
>
|
||||||
|
<Input placeholder={t('For example: https://example.com/callback')} />
|
||||||
|
</Form.Item>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
NotificationWebhook.displayName = 'NotificationWebhook';
|
@ -2,6 +2,7 @@ import { apprise } from './apprise';
|
|||||||
import { feishu } from './feishu';
|
import { feishu } from './feishu';
|
||||||
import { smtp } from './smtp';
|
import { smtp } from './smtp';
|
||||||
import { telegram } from './telegram';
|
import { telegram } from './telegram';
|
||||||
|
import { webhook } from './webhook';
|
||||||
import type { NotificationProvider } from './type';
|
import type { NotificationProvider } from './type';
|
||||||
|
|
||||||
export const notificationProviders: Record<string, NotificationProvider> = {
|
export const notificationProviders: Record<string, NotificationProvider> = {
|
||||||
@ -9,4 +10,5 @@ export const notificationProviders: Record<string, NotificationProvider> = {
|
|||||||
apprise,
|
apprise,
|
||||||
telegram,
|
telegram,
|
||||||
feishu,
|
feishu,
|
||||||
|
webhook,
|
||||||
};
|
};
|
||||||
|
23
src/server/model/notification/provider/webhook.ts
Normal file
23
src/server/model/notification/provider/webhook.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { NotificationProvider } from './type';
|
||||||
|
import { baseContentTokenizer } from '../token';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
interface WebhookPayload {
|
||||||
|
webhookUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fork from https://github.com/louislam/uptime-kuma/blob/HEAD/server/notification-providers/smtp.js
|
||||||
|
export const webhook: NotificationProvider = {
|
||||||
|
send: async (notification, title, message) => {
|
||||||
|
const payload = notification.payload as unknown as WebhookPayload;
|
||||||
|
const webhookUrl = payload.webhookUrl;
|
||||||
|
|
||||||
|
const content = baseContentTokenizer.parse(message);
|
||||||
|
|
||||||
|
await axios.post(webhookUrl, {
|
||||||
|
notification,
|
||||||
|
content,
|
||||||
|
raw: message,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user