fix: 飞书卡片消息格式修正 - msg_type=interactive需用content传card JSON
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user