Skip to content

feat(feishu): auto-convert markdown tables to native table component - #41980

Closed
UniGood wants to merge 1 commit into
NousResearch:mainfrom
UniGood:unigood/feishu-table-to-card
Closed

feat(feishu): auto-convert markdown tables to native table component#41980
UniGood wants to merge 1 commit into
NousResearch:mainfrom
UniGood:unigood/feishu-table-to-card

Conversation

@UniGood

@UniGood UniGood commented Jun 8, 2026

Copy link
Copy Markdown

Problem

Feishu's post-type md elements cannot render markdown tables. When the adapter detects a table in outbound content, it falls back to plain text — the user sees raw pipe characters like | Name | Age | instead of a proper table.

Solution

Intercept markdown tables in _build_outbound_payload() and convert them to Feishu card v2 interactive cards using the native table component. The card renders tables as proper interactive tables with columns, rows, and pagination.

No LLM involved — pure regex detection + string parsing, zero additional latency.

Changes

gateway/platforms/feishu.py

  • _build_table_card_payload(content) — Parses markdown table content and builds a Feishu card v2 JSON with native table component. Returns None on failure (caller falls back to plain text).
  • _build_feishu_table_element(seg) — Builds a Feishu card v2 table component dict from a parsed table segment (columns + rows).
  • _parse_table_segments(content) — Splits content into alternating text/table segments. Tables are parsed into header + rows dicts.
  • _TABLE_MAX_ROWS = 50 — Truncation threshold; large tables get a warning note.
  • Modified _build_outbound_payload() — Tries card conversion first when table detected; falls back to plain text on failure.

tests/gateway/test_feishu.py

  • 11 tests in TestBuildTableCardPayload covering:
    • Single table → card with native table component
    • Mixed text + table
    • Multiple tables in one message
    • Large table truncation (>50 rows)
    • Malformed input handling
    • Empty/whitespace input
    • Alignment markers stripped
    • Integration with _build_outbound_payload()

Behavior

  • Message with table: Before = Plain text (raw pipes), After = Card v2 with native table component
  • Mixed text + table: Before = Plain text, After = Card with markdown text + table elements
  • Table 50+ rows: Before = Plain text (full), After = Card (truncated + warning)
  • Parse failure: Before = Plain text, After = Plain text (unchanged fallback)

Testing

All 216 tests pass: python -m pytest tests/gateway/test_feishu.py -x -q

Feishu post-type 'md' elements cannot render markdown tables. When the
adapter detects a table in outbound content, it now converts it to a
Feishu card v2 interactive card using the native 'table' component
instead of falling back to plain text with raw pipe characters.

No LLM involved — pure regex detection + string parsing, zero additional
latency.

Changes:
- _build_table_card_payload(): Parses markdown tables and builds a Feishu
  card v2 JSON with native table component (columns + rows).
- _build_feishu_table_element(): Builds the table element dict.
- _parse_table_segments(): Splits content into text/table segments.
- _TABLE_MAX_ROWS = 50: Truncation threshold for large tables.
- Modified _build_outbound_payload() to try card conversion first.
- 11 new tests covering single table, mixed text+table, multiple tables,
  large table truncation, malformed input, and alignment marker stripping.
@alt-glitch alt-glitch added type/feature New feature or request comp/gateway Gateway runner, session dispatch, delivery platform/feishu Feishu / Lark adapter P3 Low — cosmetic, nice to have labels Jun 8, 2026
@UniGood UniGood closed this Jun 11, 2026
@UniGood
UniGood deleted the unigood/feishu-table-to-card branch June 11, 2026 00:46
@UniGood
UniGood restored the unigood/feishu-table-to-card branch June 11, 2026 01:01
@UniGood UniGood reopened this Jun 11, 2026
@UniGood UniGood closed this Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have platform/feishu Feishu / Lark adapter type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants