feat(feishu): send GFM tables via Schema 2.0 interactive card - #35781
feat(feishu): send GFM tables via Schema 2.0 interactive card#35781unstoppablesssss wants to merge 4 commits into
Conversation
Feishu post-type 'md' elements do not render GFM tables. Previously, _build_outbound_payload detected tables and forced a plain-text fallback, which lost ALL markdown formatting (headings, bold, links, etc.). Now _convert_gfm_tables_to_list() runs in send() and edit_message() BEFORE the outbound payload is built, converting GFM tables to bullet-list items: - Header row: - **col1** · **col2** - Data rows: - **col1** val1 · **col2** val2 Tables inside fenced code blocks are left untouched. After conversion, _MARKDOWN_TABLE_RE no longer matches, so the message goes through the normal post (md) pipeline with all formatting preserved.
The post-type 'md' renderer does not support GFM tables. Previously the adapter detected tables and force-downgraded the whole message to plain text (losing all formatting). Now _build_outbound_payload returns msg_type='interactive' with a Schema 2.0 interactive card payload when GFM tables are detected. The JSON 2.0 tag:markdown component renders CommonMark tables natively, preserving surrounding formatting.
|
Duplicate of #33310 (and part of the saturated Feishu markdown rendering cluster: #23861, #32488, #27469, #12114). Same approach: Schema 2.0 interactive card with |
teknium1
left a comment
There was a problem hiding this comment.
Thanks for addressing a real Feishu formatting limitation. Current main still sends detected tables as plain text at plugins/platforms/feishu/adapter.py:4524-4534, but this PR needs substantial salvage before it can be evaluated on current code.
Problems
- The changed adapter path was moved to
plugins/platforms/feishu/adapter.pyby5600105478ffde29d7566b45421b100eaa29c4ef;gateway/platforms/feishu.pyis no longer present on current main. gateway/platforms/feishu.py:212splits content into multiple elements of one card. The related #33310 discussion reports a five-table limit per card, so this does not handle messages with more tables.gateway/platforms/feishu.py:4365routes tointeractive, but current equivalent fallback handling only coverspostfailures atplugins/platforms/feishu/adapter.py:1913-1936and:1963-1971.- No Feishu tests are included. The diff also contains unrelated cua-driver proxy logic plus
state.dbandweb/package-lock.json, matching @alt-glitch's earlier note.
Suggested changes
- Port the focused implementation to the bundled plugin, handle card-limit splitting and interactive-to-text fallback for send and edit, and add focused regression tests.
- Remove the unrelated files from the salvage.
This is an automated hermes-sweeper review.
| }, | ||
| "body": { | ||
| "elements": [ | ||
| {"tag": "markdown", "content": seg} for seg in segments |
There was a problem hiding this comment.
This creates several markdown elements in one card, but it never splits into multiple cards. The related #33310 discussion records that Feishu rejects a card with more than five tables even when the tables are in separate elements; please enforce the per-card limit and return multiple outbound messages.
| if _MARKDOWN_TABLE_RE.search(content): | ||
| text_payload = {"text": content} | ||
| return "text", json.dumps(text_payload, ensure_ascii=False) | ||
| return "interactive", _build_interactive_card_payload(content) |
There was a problem hiding this comment.
Routing tables to interactive also needs an interactive-to-text fallback. The existing send/edit fallbacks only recognize rejected post payloads, so a card-permission or schema rejection would now fail delivery where this path previously sent visible plain text.
| # internal curl downloads go through it. GitHub Releases via a proxy | ||
| # is dramatically more reliable than a direct connection on this network. | ||
| env = os.environ.copy() | ||
| proxy = "http://127.0.0.1:7897" |
There was a problem hiding this comment.
This hard-coded local proxy probe is unrelated to Feishu table rendering and changes cua-driver installation behavior for every user. Please remove it from this PR and submit it separately if it is independently needed.
Problem
Feishu post-type
mdelements do not render GFM tables. Previously,_build_outbound_payloaddetected tables and force-downgraded the entire message to plain text, losing all markdown formatting (headings, bold, links, code blocks).Solution
When GFM tables are detected, send a Schema 2.0 interactive card (
msg_type="interactive") instead. The JSON 2.0tag: markdowncomponent supports CommonMark tables natively, preserving all surrounding formatting.Changes
_build_interactive_card_payload(content)— builds a Schema 2.0 card with header + body.elements_build_outbound_payload()— returns("interactive", card_payload)when tables are detected, instead of force-texttag: markdownelements (~4K chars each) with newline-aware breaksTesting
Verified with
uv run python -c '...':_MARKDOWN_TABLE_RE.search(content)matches correctly"schema": "2.0"and correctbody.elementsstructurehermes sendto Feishu — table renders natively in Schema 2.0 card