Skip to content

Commit 7c6a798

Browse files
authored
fix(feishu): preserve unavailable controls in message cards (#130641)
1 parent 7f20bb8 commit 7c6a798

7 files changed

Lines changed: 398 additions & 146 deletions

File tree

‎docs/plugins/message-presentation.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ Current bundled renderers:
597597
| Channel | Native render target | Notes |
598598
| --------------- | ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
599599
| Discord | Components and component containers | Preserves legacy `channelData.discord.components` for existing provider-native payload producers, but new shared sends should use `presentation`. |
600-
| Feishu | Interactive cards | Card header can use `title`; body avoids duplicating that title. |
600+
| Feishu | Interactive cards | Card header uses `title` once. Within native cards, disabled or unsupported buttons retain label-only text; rejected URL targets and opaque callback values are omitted. |
601601
| Matrix | Text fallback plus structured event field | Buttons/selects advertise as supported, but every block currently renders as `renderMessagePresentationFallbackText` output carried in a `com.openclaw.presentation` event field, not native interactive widgets. |
602602
| Mattermost | Text plus interactive props | Selects and dividers are not supported; those blocks degrade to text. |
603603
| Microsoft Teams | Adaptive Cards | Plain `message` text is included with the card when both are provided. Selects, styles, and disabled state are not supported. |

‎extensions/feishu/src/channel.test.ts‎

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,18 +1464,36 @@ describe("feishuPlugin actions", () => {
14641464
).toBe(false);
14651465
});
14661466

1467-
it("does not render callback action buttons as Feishu quick commands", async () => {
1467+
it.each(
1468+
["send", "thread-reply"].flatMap((action) =>
1469+
["alone", "with text", "with native buttons"].map((layout) => ({ action, layout })),
1470+
),
1471+
)("preserves unsupported button labels $layout on $action", async ({ action, layout }) => {
14681472
sendCardFeishuMock.mockResolvedValueOnce({ messageId: "om_card", chatId: "oc_group_1" });
14691473

14701474
await feishuPlugin.actions?.handleAction?.({
1471-
action: "send",
1475+
action,
14721476
params: {
14731477
to: "chat:oc_group_1",
1478+
...(action === "thread-reply" ? { messageId: "om_root" } : {}),
1479+
...(layout === "with text" ? { text: "Choose an action" } : {}),
14741480
presentation: {
14751481
blocks: [
14761482
{
14771483
type: "buttons",
1478-
buttons: [{ label: "Inspect", action: { type: "callback", value: "inspect:123" } }],
1484+
buttons: [
1485+
{ label: "Inspect", action: { type: "callback", value: "inspect:123" } },
1486+
...(layout === "with native buttons"
1487+
? [
1488+
{ label: "Help", action: { type: "command", command: "/help" } },
1489+
{
1490+
label: "Details <one> & more",
1491+
action: { type: "callback", value: "/opaque-details" },
1492+
},
1493+
{ label: "Docs", action: { type: "url", url: "https://example.com" } },
1494+
]
1495+
: []),
1496+
],
14791497
},
14801498
],
14811499
},
@@ -1491,9 +1509,80 @@ describe("feishuPlugin actions", () => {
14911509
);
14921510
const card = requireRecord(sendCardArgs.card, "card");
14931511
const elements = requireArray(requireRecord(card.body, "card body").elements, "card elements");
1494-
expect(elements).toEqual([{ tag: "markdown", content: "- Inspect" }]);
1512+
expect(elements).toEqual([
1513+
...(layout === "with text" ? [{ tag: "markdown", content: "Choose an action" }] : []),
1514+
{ tag: "markdown", content: "- Inspect" },
1515+
...(layout === "with native buttons"
1516+
? [
1517+
expect.objectContaining({
1518+
tag: "button",
1519+
text: { tag: "plain_text", content: "Help" },
1520+
behaviors: [
1521+
{
1522+
type: "callback",
1523+
value: { oc: "ocf1", k: "quick", a: "feishu.payload.button", q: "/help" },
1524+
},
1525+
],
1526+
}),
1527+
{ tag: "markdown", content: "- Details &lt;one&gt; &amp; more" },
1528+
expect.objectContaining({
1529+
tag: "button",
1530+
text: { tag: "plain_text", content: "Docs" },
1531+
behaviors: [{ type: "open_url", default_url: "https://example.com" }],
1532+
}),
1533+
]
1534+
: []),
1535+
]);
14951536
});
14961537

1538+
it.each(["send", "thread-reply"])(
1539+
"keeps disabled command and link buttons non-interactive on %s",
1540+
async (action) => {
1541+
sendCardFeishuMock.mockResolvedValueOnce({ messageId: "om_card", chatId: "oc_group_1" });
1542+
await feishuPlugin.actions?.handleAction?.({
1543+
action,
1544+
params: {
1545+
to: "chat:oc_group_1",
1546+
...(action === "thread-reply" ? { messageId: "om_root" } : {}),
1547+
presentation: {
1548+
blocks: [
1549+
{
1550+
type: "buttons",
1551+
buttons: [
1552+
{
1553+
label: "Unavailable [command](https://example.com/label)",
1554+
disabled: true,
1555+
action: { type: "command", command: "/help" },
1556+
},
1557+
{
1558+
label: "Unavailable link",
1559+
disabled: true,
1560+
action: { type: "url", url: "https://example.com" },
1561+
},
1562+
],
1563+
},
1564+
],
1565+
},
1566+
},
1567+
cfg,
1568+
accountId: undefined,
1569+
toolContext: {},
1570+
} as never);
1571+
const sendCardArgs = requireRecord(
1572+
mockCallArg(sendCardFeishuMock, 0, 0, "sendCardFeishu"),
1573+
"send card args",
1574+
);
1575+
const card = requireRecord(sendCardArgs.card, "card");
1576+
expect(requireRecord(card.body, "card body").elements).toEqual([
1577+
{
1578+
tag: "markdown",
1579+
content: "- Unavailable \\[command\\]\\(https://example.com/label\\)",
1580+
},
1581+
{ tag: "markdown", content: "- Unavailable link" },
1582+
]);
1583+
},
1584+
);
1585+
14971586
it("renders legacy web_app presentation buttons as native Feishu link buttons", async () => {
14981587
sendCardFeishuMock.mockResolvedValueOnce({ messageId: "om_card", chatId: "oc_group_1" });
14991588

‎extensions/feishu/src/comment-dispatcher.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import { createCommentTypingReactionLifecycle } from "./comment-reaction.js";
1010
import type { CommentFileType } from "./comment-target.js";
1111
import { deliverCommentThreadText } from "./drive.js";
1212
import { buildFeishuMediaFallbackText } from "./media-fallback.js";
13-
import {
14-
buildFeishuCommentPresentationFallback,
15-
resolveFeishuRichReply,
16-
} from "./presentation-card.js";
13+
import { buildFeishuPresentationFallback, resolveFeishuRichReply } from "./presentation-card.js";
1714
import {
1815
createFeishuPartialReplyDeliveryError,
1916
createFeishuReplyDeliveryResult,
@@ -83,7 +80,10 @@ export function createFeishuCommentReplyDispatcher(
8380
}
8481
const reply = resolveSendableOutboundReplyParts(payload);
8582
const { presentation } = resolveFeishuRichReply(payload);
86-
let { text } = buildFeishuCommentPresentationFallback({ text: reply.text, presentation });
83+
let { commentText: text } = buildFeishuPresentationFallback({
84+
text: reply.text,
85+
presentation,
86+
});
8787
for (const mediaUrl of reply.mediaUrls) {
8888
text = await buildFeishuMediaFallbackText({ text, mediaUrl, mediaLinkStyle: "plain" });
8989
}

‎extensions/feishu/src/native-card.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function resolveFeishuCardTemplate(template?: string): string | undefined
2828
return normalized;
2929
}
3030

31-
function escapeFeishuCardMarkdownText(text: string): string {
31+
export function escapeFeishuCardMarkdownText(text: string): string {
3232
return text.replace(/[&<>]/g, (char) => {
3333
switch (char) {
3434
case "&":
@@ -43,11 +43,11 @@ function escapeFeishuCardMarkdownText(text: string): string {
4343
});
4444
}
4545

46-
function escapeFeishuCardPlainText(text: string): string {
46+
export function escapeFeishuCardPlainText(text: string): string {
4747
return escapeFeishuCardMarkdownText(text).replace(/([\\`*_{}[\]()#+\-!|>~])/g, "\\$1");
4848
}
4949

50-
function resolveSafeFeishuButtonUrl(url: unknown): string | undefined {
50+
export function resolveSafeFeishuButtonUrl(url: unknown): string | undefined {
5151
const trimmed = typeof url === "string" ? url.trim() : "";
5252
if (!trimmed) {
5353
return undefined;

0 commit comments

Comments
 (0)