-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc910b7
commit f6fc210
Showing
5 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/client/components/modals/NotificationInfo/strategies/feishu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
}, | ||
}, | ||
}, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters