feat: add feishu notification
This commit is contained in:
parent
cc910b7ee6
commit
f6fc210b65
@ -0,0 +1,33 @@
|
||||
import { Form, Input } from 'antd';
|
||||
import React from 'react';
|
||||
import { useTranslation } from '@i18next-toolkit/react';
|
||||
|
||||
export const NotificationFeishu: 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://open.feishu.cn/open-apis/bot/v2/hook/00000000-0000-0000-0000-000000000000'
|
||||
)}
|
||||
/>
|
||||
</Form.Item>
|
||||
<div className="text-sm opacity-80">
|
||||
{t('Read more')}:{' '}
|
||||
<a
|
||||
href="https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot?lang=en-US"
|
||||
target="_blank"
|
||||
>
|
||||
https://open.feishu.cn/document/client-docs/bot-v3/add-custom-bot?lang=en-US
|
||||
</a>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
});
|
||||
NotificationFeishu.displayName = 'NotificationFeishu';
|
@ -2,6 +2,7 @@ import React from 'react';
|
||||
import { NotificationSMTP } from './smtp';
|
||||
import { NotificationTelegram } from './telegram';
|
||||
import { NotificationApprise } from './apprise';
|
||||
import { NotificationFeishu } from './feishu';
|
||||
|
||||
interface NotificationStrategy {
|
||||
label: string;
|
||||
@ -25,4 +26,9 @@ export const notificationStrategies: NotificationStrategy[] = [
|
||||
name: 'telegram',
|
||||
form: NotificationTelegram,
|
||||
},
|
||||
{
|
||||
label: 'Feishu',
|
||||
name: 'feishu',
|
||||
form: NotificationFeishu,
|
||||
},
|
||||
];
|
||||
|
43
src/server/model/notification/provider/feishu.ts
Normal file
43
src/server/model/notification/provider/feishu.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { NotificationProvider } from './type';
|
||||
import { baseContentTokenizer } from '../token';
|
||||
import axios from 'axios';
|
||||
|
||||
interface FeishuPayload {
|
||||
webhookUrl: string;
|
||||
}
|
||||
|
||||
// Fork from https://github.com/louislam/uptime-kuma/blob/HEAD/server/notification-providers/smtp.js
|
||||
export const feishu: NotificationProvider = {
|
||||
send: async (notification, title, message) => {
|
||||
const payload = notification.payload as unknown as FeishuPayload;
|
||||
const webhookUrl = payload.webhookUrl;
|
||||
if (
|
||||
!webhookUrl.startsWith('https://open.feishu.cn/open-apis/bot/v2/hook')
|
||||
) {
|
||||
throw new Error('Is not a valid feishu webhook url');
|
||||
}
|
||||
|
||||
const content = baseContentTokenizer.parse(message);
|
||||
|
||||
await axios.post(webhookUrl, {
|
||||
msg_type: 'interactive',
|
||||
card: {
|
||||
elements: [
|
||||
{
|
||||
tag: 'div',
|
||||
text: {
|
||||
content,
|
||||
tag: 'plain_text',
|
||||
},
|
||||
},
|
||||
],
|
||||
header: {
|
||||
title: {
|
||||
content: title,
|
||||
tag: 'plain_text',
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
@ -1,4 +1,5 @@
|
||||
import { apprise } from './apprise';
|
||||
import { feishu } from './feishu';
|
||||
import { smtp } from './smtp';
|
||||
import { telegram } from './telegram';
|
||||
import type { NotificationProvider } from './type';
|
||||
@ -7,4 +8,5 @@ export const notificationProviders: Record<string, NotificationProvider> = {
|
||||
smtp,
|
||||
apprise,
|
||||
telegram,
|
||||
feishu,
|
||||
};
|
||||
|
@ -18,11 +18,11 @@ export class BaseContentTokenizer {
|
||||
}
|
||||
|
||||
parseTitle(token: TitleContentToken) {
|
||||
return token.content;
|
||||
return token.content + '\n';
|
||||
}
|
||||
|
||||
parseParagraph(token: ParagraphContentToken) {
|
||||
return token.content;
|
||||
return token.content + '\n';
|
||||
}
|
||||
|
||||
parseNewline(token: NewlineContentToken) {
|
||||
|
Loading…
Reference in New Issue
Block a user