fix(feishu): route markdown through Card 2.0 interactive cards - #45036
Open
Mr8rock wants to merge 1 commit into
Open
fix(feishu): route markdown through Card 2.0 interactive cards#45036Mr8rock wants to merge 1 commit into
Mr8rock wants to merge 1 commit into
Conversation
Feishu has two markdown renderers and the wrong one was being used for
outbound messages. The 'tag: "md"' post element is a stripped-down
renderer that only handles links and partial bold — every other
markdown element (tables, code blocks, lists, headings, italic,
strikethrough, blockquote) is rendered as literal characters. The
'tag: "markdown"' element inside an interactive card v2.0 is the
full-featured renderer, but it was never used.
As a result, Feishu users were seeing:
- tables rendered as a code block (the workaround) with line
numbers, no borders, no column alignment
- lists, code blocks, blockquotes appearing as literal text
- even bold/italic only working inconsistently
The fix: wrap any message that contains markdown in a Card 2.0
('schema': '2.0') and send it with msg_type 'interactive' using
'tag: "markdown"' in the body. The card's renderer is the
CommonMark-compliant one and renders everything correctly.
This matches the approach used by the OpenClaw Feishu integration
(docs/dist/send-DrvJaWvR.js, buildMarkdownCard) and aligns Hermes
with what the official Feishu plugins do.
Fallback paths updated:
- the invalid-content regex now also matches card rejection
messages ("invalid card content", "invalid content format")
- the post->text fallback also handles interactive->text so a
malformed card doesn't fail the whole send
- the _feishu_send_with_retry inner loop stops retrying on
invalid card content instead of attempting N retries
Tests: 212/212 pass in tests/gateway/test_feishu.py (was 211;
updated 6 pre-existing tests that asserted the old post-row
structure to assert the new card structure, plus added Card 2.0
schema assertions).
Mr8rock
marked this pull request as ready for review
June 12, 2026 16:02
Collaborator
3 tasks
13 tasks
Contributor
|
Thanks for the focused Card 2.0 investigation. The underlying issue is still present on current main: Problems
Suggested changes
This is an automated hermes-sweeper review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes a long-standing bug where Feishu (Lark) outbound messages lose
all markdown formatting except links. The wrong markdown renderer was
being used — the stripped-down
tag: "md"post element instead ofthe full-featured
tag: "markdown"inside a Card 2.0.Symptom
Sending a markdown table from Hermes to a Feishu chat rendered the
table as a code block (with line numbers, no borders, no column
alignment), lists and code blocks appeared as literal text, and
even bold/italic only worked inconsistently.
Root cause
Feishu has two markdown renderers and Hermes was using the wrong one:
tag: "md"tag: "markdown"The code path was sending post elements for most markdown and
tag: "lark_md"(a Card 1.0 element, not v2) wrapped in atag: "div"for tables. Both are partial renderers — Card 1.0 is particularly
incomplete (no real tables, line numbers on code blocks).
Fix
Route all markdown through Card 2.0 (
"schema": "2.0") usingtag: "markdown"inbody.elements, sent withmsg_type: "interactive".This matches the approach used by the OpenClaw Feishu integration
(
buildMarkdownCardindist/send-DrvJaWvR.js) and aligns Hermeswith what the official Feishu plugins do.
{ "msg_type": "interactive", "content": { "schema": "2.0", "config": {"width_mode": "fill"}, "body": { "elements": [{"tag": "markdown", "content": "<original markdown>"}] } } }Fallback path updated
The post→text fallback on
230001 content format … is incorrectalsocovers the new
msg_type: "interactive"path and the regex wasbroadened to match the card variant of the error. The retry loop
stops on invalid content (no point retrying the same broken payload).
Cleanup
The legacy
_build_markdown_post_rowswalker (heading/text/styleconversion, fenced-code →
code_blockpost row, table →code_blockhack) is no longer used by
_build_outbound_payloadand is keptonly because
_build_post_payloadis still referenced by theimage-with-caption path. The dispatch path is now a clean two-way
choice:
textfor plain strings,interactive(Card 2.0) foranything that contains a markdown hint.
Type of Change
Changes Made
gateway/platforms/feishu.py_build_interactive_card_payload(content)helper_build_outbound_payloadsimplified: markdown →("interactive", card);plain text →
("text", {"text": ...})interactiveas well aspost_POST_CONTENT_INVALID_REextended to match card error variants_feishu_send_with_retryno longer retries on invalid contenttests/gateway/test_feishu.pyTestFeishuMarkdownTableRenderingrewritten for Card 2.0 assertionsmsg_type="post"row checks tomsg_type="interactive"card checkslark_mdregression,width_mode=fillconfigHow to Test
a markdown table — it should now render as a real table with
borders, column alignment, and no line numbers.
- item), fenced code blocks (```python), and**bold**/*italic*/~~strike~~should all render correctlyin the same message.
card.
msg_type: "text", not get wrapped in a card.Acknowledgements
Cribbed the Card 2.0 structure from the OpenClaw Feishu integration
(
buildMarkdownCard/sendCardFeishuindist/send-DrvJaWvR.js).That implementation correctly uses the full-featured markdown
renderer; matching it here brings Hermes to parity with the official
Feishu plugin behaviour observed in production.
Checklist
Code
fix(feishu):)pytest tests/gateway/test_feishu.py— 212/212 passDocumentation & Housekeeping
fix is internal to the Feishu adapter and the existing module
docstrings still describe the behavior accurately