feat: feishu add markdown syntax support

This commit is contained in:
moonrailgun 2024-08-31 00:13:57 +08:00
parent 9fcc6dda60
commit 33de808f3e
2 changed files with 28 additions and 7 deletions

View File

@ -0,0 +1,22 @@
import { describe, test } from 'vitest';
import { token } from '../../token/index.js';
import { feishu } from '../feishu.js';
describe.runIf(!!process.env.TEST_FEISHU_URL)('feishu', () => {
test('apprise should be work', async () => {
await feishu.send(
{
payload: {
webhookUrl: process.env.TEST_FEISHU_URL,
},
} as any,
'test title',
[
token.title('test title', 1),
token.text('list'),
token.newline(),
token.list([token.text('A'), token.text('B')]),
]
);
});
});

View File

@ -1,5 +1,5 @@
import { NotificationProvider } from './type.js';
import { baseContentTokenizer } from '../token/index.js';
import { markdownContentTokenizer } from '../token/index.js';
import axios from 'axios';
interface FeishuPayload {
@ -17,18 +17,16 @@ export const feishu: NotificationProvider = {
throw new Error('Is not a valid feishu webhook url');
}
const content = baseContentTokenizer.parse(message);
const content = markdownContentTokenizer.parse(message);
// Document: https://open.larksuite.com/document/common-capabilities/message-card/message-cards-content/using-markdown-tags
await axios.post(webhookUrl, {
msg_type: 'interactive',
card: {
elements: [
{
tag: 'div',
text: {
tag: 'markdown',
content,
tag: 'plain_text',
},
},
],
header: {
@ -36,6 +34,7 @@ export const feishu: NotificationProvider = {
content: title,
tag: 'plain_text',
},
template: 'blue',
},
},
});