fix: 飞书卡片消息格式修正 - msg_type=interactive需用content传card JSON
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
CI / lint-and-typecheck (push) Has been cancelled

This commit is contained in:
2026-04-12 02:02:20 +08:00
parent 61ed9e9dc3
commit 28340b23c1

View File

@@ -190,6 +190,26 @@ export function buildDecisionCard(card: DecisionCardOptions): Record<string, unk
export async function sendDecisionCard(card: DecisionCardOptions, receiveId: string, receiveIdType: 'open_id' | 'user_id' = 'open_id'): Promise<{ ok: boolean; code: number; msg: string }> {
const token = await getTenantToken();
const url = `https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=${receiveIdType}`;
const cardContent = {
header: {
title: { tag: 'plain_text', content: card.title },
template: 'blue',
},
elements: [
{ tag: 'div', text: { tag: 'plain_text', content: card.description } },
{
tag: 'action',
actions: card.options.map((opt) => ({
tag: 'button',
text: { tag: 'plain_text', content: opt.label },
type: opt.style === 'danger' ? 'danger' : opt.style === 'primary' ? 'primary' : 'default',
value: { action: opt.key },
})),
},
],
};
const res = await fetch(url, {
method: 'POST',
headers: {
@@ -199,7 +219,7 @@ export async function sendDecisionCard(card: DecisionCardOptions, receiveId: str
body: JSON.stringify({
receive_id: receiveId,
msg_type: 'interactive',
card: buildDecisionCard(card),
content: JSON.stringify(cardContent),
}),
});
const data = await res.json();