Skip to content

fix(feishu): parse interactive card post-format fallback content - #60383

Closed
lskun wants to merge 1 commit into
openclaw:mainfrom
lskun:fix/feishu-interactive-card-fallback-parsing
Closed

lskun wants to merge 1 commit into
openclaw:mainfrom
lskun:fix/feishu-interactive-card-fallback-parsing

Conversation

@lskun

@lskun lskun commented Apr 3, 2026

Copy link
Copy Markdown

Summary

Fix parseInteractiveCardContent() to handle Feishu API post-format fallback content for interactive card messages.

Fixes #60380
Related: #41609 #48281

Problem

When reading card messages via GET /im/v1/messages/{message_id}, Feishu returns body.content in a post-style fallback format — nested arrays with tag:"text" elements — instead of the original card template JSON. The existing parser only handled card template format (div/markdown tags), causing all fallback content to silently return "[Interactive Card]".

Before: Any message(action=read) on a card → "[Interactive Card]"
After: Extracts title + text content from both card template and post-format fallback

Example

API returns this for a card message:

{
  "title": "🤖 clawdbot",
  "elements": [[
    {"tag": "img", "image_key": "img_v3_02ad_..."},
    {"tag": "text", "text": "Daily report summary"},
    {"tag": "text", "text": "13 people missing reports"}
  ]]
}
  • Before: "[Interactive Card]"
  • After: "🤖 clawdbot\nDaily report summary\n13 people missing reports"

Changes

extensions/feishu/src/send.ts

  • Handle nested arrays in elements (post-format fallback [[...]])
  • Extract tag:"text" and tag:"a" elements from fallback content
  • Extract card title from header.title.content (template) or top-level title (fallback)
  • Support tag:"plain_text" elements
  • Return title even when elements array is missing

extensions/feishu/src/send.test.ts

  • Add test: post-format fallback with nested arrays and title
  • Add test: card template with header.title.content
  • Add test: link extraction from tag:"a" elements with href

Testing

  • Verified with real Feishu API responses from production bot
  • Existing card template format tests still pass (div/markdown)
  • 3 new test cases covering fallback scenarios

@openclaw-barnacle openclaw-barnacle Bot added channel: feishu Channel integration: feishu size: S labels Apr 3, 2026
@greptile-apps

greptile-apps Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extends parseInteractiveCardContent() in the Feishu extension to handle the post-format fallback that the Feishu API returns when reading interactive card messages via GET /im/v1/messages/{message_id}. The logic correctly detects nested arrays ([[...]]), extracts tag:"text" / tag:"a" elements, picks up the top-level title string for fallback cards, and falls through gracefully to "[Interactive Card]" when nothing is extractable.

  • Trailing-whitespace test/code mismatch: The anchor-tag test provides { tag: "text", text: "See: " } (trailing space) but asserts the output contains "See:" (no space). The production code pushes node.text without trimming, so the joined string will be "See: ..." not "See: ...". This test will fail at runtime; the fix is to call .trim() before pushing each tag:"text" node text.
  • The rest of the logic — nested-array flattening, header/title extraction, and tag:"a" href formatting — looks correct and the other two new tests (post-format fallback and header.title.content) are consistent with the implementation.

Confidence Score: 3/5

Safe to merge after fixing the trailing-whitespace bug in the anchor-tag test; the core parsing logic is sound.

The PR logic is correct for all described scenarios, but there is a concrete test failure in the anchor-tag test: input text "See: " (trailing space) will not match the asserted "See:" because individual texts are pushed untrimmed. The PR's stated test coverage is not actually green.

extensions/feishu/src/send.ts line 220-221 — tag:"text" node text should be trimmed before pushing. extensions/feishu/src/send.test.ts line 257/275 — input and expected value are inconsistent.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: extensions/feishu/src/send.test.ts
Line: 257-275

Comment:
**Test/code mismatch — trailing whitespace in text causes assertion failure**

The test input at line 257 has `{ tag: "text", text: "See: " }` — note the trailing space. The production code in `send.ts` pushes `node.text` directly (not trimmed):

```typescript
if (node.tag === "text" && typeof node.text === "string" && node.text.trim()) {
  texts.push(node.text);  // pushes "See: " with the trailing space intact
}
```

After `texts.join("\n")`, the result is `"Report\nSee: \nWeekly Report (...)"` — but the assertion expects `"Report\nSee:\nWeekly Report (...)"` (no trailing space). The `.trim()` call at the end only strips the leading/trailing edges of the whole string, not interior segments.

This test will fail as written. The fix is to trim the individual text value before pushing in `send.ts`:
```suggestion
                if (node.tag === "text" && typeof node.text === "string" && node.text.trim()) {
                  texts.push(node.text.trim());
                }
```
This is also better UX — stray trailing spaces in card text are noise and shouldn't appear in the extracted content.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(feishu): parse interactive card post..." | Re-trigger Greptile

Comment on lines +257 to +275
{ tag: "text", text: "See: " },
{ tag: "a", text: "Weekly Report", href: "https://example.com/report" },
],
],
}),
},
},
],
},
});

const result = await getMessageFeishu({
cfg: {} as ClawdbotConfig,
messageId: "om_card_links",
});

expect(result).toEqual(
expect.objectContaining({
content: "Report\nSee:\nWeekly Report (https://example.com/report)",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Test/code mismatch — trailing whitespace in text causes assertion failure

The test input at line 257 has { tag: "text", text: "See: " } — note the trailing space. The production code in send.ts pushes node.text directly (not trimmed):

if (node.tag === "text" && typeof node.text === "string" && node.text.trim()) {
  texts.push(node.text);  // pushes "See: " with the trailing space intact
}

After texts.join("\n"), the result is "Report\nSee: \nWeekly Report (...)" — but the assertion expects "Report\nSee:\nWeekly Report (...)" (no trailing space). The .trim() call at the end only strips the leading/trailing edges of the whole string, not interior segments.

This test will fail as written. The fix is to trim the individual text value before pushing in send.ts:

Suggested change
{ tag: "text", text: "See: " },
{ tag: "a", text: "Weekly Report", href: "https://example.com/report" },
],
],
}),
},
},
],
},
});
const result = await getMessageFeishu({
cfg: {} as ClawdbotConfig,
messageId: "om_card_links",
});
expect(result).toEqual(
expect.objectContaining({
content: "Report\nSee:\nWeekly Report (https://example.com/report)",
if (node.tag === "text" && typeof node.text === "string" && node.text.trim()) {
texts.push(node.text.trim());
}

This is also better UX — stray trailing spaces in card text are noise and shouldn't appear in the extracted content.

Prompt To Fix With AI
This is a comment left during a code review.
Path: extensions/feishu/src/send.test.ts
Line: 257-275

Comment:
**Test/code mismatch — trailing whitespace in text causes assertion failure**

The test input at line 257 has `{ tag: "text", text: "See: " }` — note the trailing space. The production code in `send.ts` pushes `node.text` directly (not trimmed):

```typescript
if (node.tag === "text" && typeof node.text === "string" && node.text.trim()) {
  texts.push(node.text);  // pushes "See: " with the trailing space intact
}
```

After `texts.join("\n")`, the result is `"Report\nSee: \nWeekly Report (...)"` — but the assertion expects `"Report\nSee:\nWeekly Report (...)"` (no trailing space). The `.trim()` call at the end only strips the leading/trailing edges of the whole string, not interior segments.

This test will fail as written. The fix is to trim the individual text value before pushing in `send.ts`:
```suggestion
                if (node.tag === "text" && typeof node.text === "string" && node.text.trim()) {
                  texts.push(node.text.trim());
                }
```
This is also better UX — stray trailing spaces in card text are noise and shouldn't appear in the extracted content.

How can I resolve this? If you propose a fix, please make it concise.

@clawsweeper

clawsweeper Bot commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I did a careful shell check against current main, and the useful part of this older PR is already implemented there.

Close: this older PR is no longer the best landing path because current main now solves the central Feishu read-card failure by requesting full card content on both single-message and thread-history reads, while the remaining fallback-parser diff is proof-blocked and carries an external-input recursion risk.

So I’m closing this older PR as already covered on main rather than keeping a mostly-duplicated branch open.

Review details

Best possible solution:

Keep the current-main full-card-content request from #93134 and route broader inbound/card-action parsing decisions through #41609 or narrower follow-ups.

Do we have a high-confidence way to reproduce the issue?

Yes. Source inspection shows the original degraded Feishu card payload fell through the parser, while current main now avoids that read path by requesting full card JSON on both get and list calls.

Is this the best way to solve the issue?

No, this branch is no longer the best fix. The better current-main solution is to request Feishu's full card content at the API boundary; any remaining degraded-payload parser work should be bounded and separately proven.

Security review:

Security review needs attention: The diff has no supply-chain changes, but it adds unbounded recursive parsing over external Feishu card payloads.

  • [medium] Unbounded recursive parsing of external card arrays — extensions/feishu/src/send.ts:225
    Feishu card content is external message data, and the PR recursively descends nested arrays without explicit depth, node, or output bounds, which can overflow stack or consume excessive CPU during message reads.
    Confidence: 0.86

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • m1heng: The Feishu package metadata describes the Feishu/Lark channel plugin as community maintained by this handle. (role: declared plugin contact; confidence: high; files: extensions/feishu/package.json, extensions/feishu/openclaw.plugin.json)
  • liuhao1024: Authored the first commit in the merged current-main replacement PR that added card_msg_content_type to the Feishu read path. (role: replacement fix author; confidence: high; commits: b1d3f50ae716, 1db8ab373422; files: extensions/feishu/src/send.ts, extensions/feishu/src/send.test.ts)
  • vincentkoc: Authored the current-main completion commit for both Feishu read APIs and earlier merged adjacent interactive-card extraction work. (role: recent parser and replacement-fix contributor; confidence: high; commits: e78f7f8b8ccb, c6cf37068cae; files: extensions/feishu/src/send.ts, extensions/feishu/src/send.test.ts, extensions/feishu/src/post.ts)
  • Brian Qu: Introduced the Feishu thread-context read surface that now also uses the full-card-content request parameter. (role: adjacent thread-history contributor; confidence: medium; commits: 8a607d755333; files: extensions/feishu/src/send.ts, extensions/feishu/src/bot.ts, extensions/feishu/src/send.test.ts)

Codex review notes: model internal, reasoning high; reviewed against da92615816b6; fix evidence: commit 1db8ab373422, main fix timestamp 2026-06-15T12:04:55+08:00.

@lskun
lskun force-pushed the fix/feishu-interactive-card-fallback-parsing branch from db76951 to a380eb1 Compare May 1, 2026 04:35
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels May 19, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 19, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels May 19, 2026
@clawsweeper

clawsweeper Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@RomneyDa

Copy link
Copy Markdown
Member

Heads up: this PR needs to be updated against current main before the new required Dependency Guard check can pass.

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jun 13, 2026
@clawsweeper

clawsweeper Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: feishu Channel integration: feishu merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Feishu: parseInteractiveCardContent fails on fallback post-format content

2 participants