From 33de808f3e4e6a763fc36de96f24e01055907aba Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 31 Aug 2024 00:13:57 +0800 Subject: [PATCH] feat: feishu add markdown syntax support --- .../provider/__tests__/feishu.spec.ts | 22 +++++++++++++++++++ .../model/notification/provider/feishu.ts | 13 +++++------ 2 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 src/server/model/notification/provider/__tests__/feishu.spec.ts diff --git a/src/server/model/notification/provider/__tests__/feishu.spec.ts b/src/server/model/notification/provider/__tests__/feishu.spec.ts new file mode 100644 index 0000000..8ff1dd6 --- /dev/null +++ b/src/server/model/notification/provider/__tests__/feishu.spec.ts @@ -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')]), + ] + ); + }); +}); diff --git a/src/server/model/notification/provider/feishu.ts b/src/server/model/notification/provider/feishu.ts index b35845a..5954e11 100644 --- a/src/server/model/notification/provider/feishu.ts +++ b/src/server/model/notification/provider/feishu.ts @@ -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: { - content, - tag: 'plain_text', - }, + tag: 'markdown', + content, }, ], header: { @@ -36,6 +34,7 @@ export const feishu: NotificationProvider = { content: title, tag: 'plain_text', }, + template: 'blue', }, }, });