Skip to content

Feat/feishu card parsing#1534

Open
yangwenjie1231 wants to merge 8 commits intosipeed:mainfrom
yangwenjie1231:feat/feishu-card-parsing
Open

Feat/feishu card parsing#1534
yangwenjie1231 wants to merge 8 commits intosipeed:mainfrom
yangwenjie1231:feat/feishu-card-parsing

Conversation

@yangwenjie1231
Copy link

@yangwenjie1231 yangwenjie1231 commented Mar 14, 2026

📝 Description

#1516 | File tool that exposes local file paths to the agent (non-image media)
This PR support Feishu card message parsing + image extraction
#1516 resolves the issue of the "media://" protocol, enabling the agent to directly access file paths.
This PR is to enable Feishu card messages to be correctly parsed, which is a feature not covered by #1516.

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated (100% AI, 0% Human)
  • 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

🔗 Related Issue

📚 Technical Context (Skip for Docs)

  • Reference URL:
  • Reasoning:

🧪 Test Environment

  • Hardware: PC
  • OS: windows10
  • Model/Provider: GLM-5
  • Channels: Feishu

📸 Evidence (Optional)

Click to view Logs/Screenshots image

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

@sipeed-bot sipeed-bot bot added type: enhancement New feature or request domain: channel go Pull requests that update go code labels Mar 14, 2026
@yangwenjie1231 yangwenjie1231 force-pushed the feat/feishu-card-parsing branch from 5855449 to d6b3cee Compare March 14, 2026 14:15
@yangwenjie1231
Copy link
Author

yangwenjie1231 commented Mar 15, 2026

已修复,本地cl都 pass 了

@yangwenjie1231
Copy link
Author

已修复,之前未加 -shadow
cl提示non-canonical header "api-key", instead use: "Api-Key" (canonicalheader)
是更新cl版本了吗?
像是之前的问题

Add support for parsing inbound Feishu interactive card messages.
When a user sends a card message, the text content is now extracted
and passed to the LLM for processing.

- Add extractCardText() to recursively extract text from card JSON
- Support both JSON 1.0 (legacy) and JSON 2.0 schema formats
- Handle nested elements: header, body, actions, columns
- Extract text from markdown, lark_md, and plain_text elements
- Add comprehensive unit tests for card parsing

Fixes #<issue_number>

💘 Generated with Crush

Assisted-by: GLM-5 via Crush <crush@charm.land>
When receiving interactive card messages, extract embedded images
(img_key, src, icon_key) and download them for LLM processing.

- Add extractCardImageKeys() to recursively extract image keys from card JSON
- Support img elements (img_key, src) and icon elements (icon_key)
- Update downloadInboundMedia() to handle MsgTypeInteractive
- Add comprehensive unit tests for image extraction

Images are downloaded and stored via MediaStore, then appended to
the message content as [image: photo] tags for LLM visibility.

💘 Generated with Crush

Assisted-by: GLM-5 via Crush <crush@charm.land>
Address review feedback: text extraction cannot exhaustively handle all
card formats (i18n_elements, div.fields, etc.). Pass raw JSON to LLM
instead - same approach as MsgTypePost. Only image extraction remains
as images must be downloaded for LLM to process.

- Remove extractCardText() and helper functions
- extractContent() now returns raw JSON for MsgTypeInteractive
- Keep extractCardImageKeys() for downloading embedded images
- Update tests to expect raw JSON for interactive cards
Appending media tags like "[attachment]" to raw JSON content produces
invalid JSON format. For interactive cards, the JSON already contains
image information and media refs are downloaded separately.

- Skip appendMediaTags for MsgTypeInteractive to preserve valid JSON
- Add test case for interactive card with images
Only Feishu-hosted image keys (img_xxx, icon_xxx) can be downloaded via
the Feishu API. External URLs in src field (https://...) should be
filtered out to avoid download failures.

- Add isFeishuImageKey() to detect Feishu-hosted keys vs external URLs
- Update extractImageKeysRecursive to skip external URLs in src field
- Add tests for external URL filtering and mixed scenarios
Previously only Feishu-hosted images (img_key, icon_key) could be
downloaded. Now external URLs in src field are also downloaded via
HTTP and made available to the LLM.

- extractCardImageKeys now returns two slices: Feishu keys and external URLs
- Add downloadExternalImage to download images from HTTP URLs
- Update downloadInboundMedia to handle both Feishu API and HTTP downloads
- Update tests for new function signature
Replaced http.DefaultClient with a client that has a 30-second timeout
to prevent hanging on unresponsive external URLs.

Generated with Crush

Assisted-by: GLM-5 via Crush <crush@charm.land>
- Rename err variables to avoid shadowing in downloadExternalImage
- Fix struct field alignment in TestExtractCardImageKeys

Generated with Crush

Assisted-by: GLM-5 via Crush <crush@charm.land>
@yangwenjie1231 yangwenjie1231 force-pushed the feat/feishu-card-parsing branch from dd7cbc5 to c58c3fe Compare March 15, 2026 05:20
@yangwenjie1231
Copy link
Author

已同步#1583的更新

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: channel go Pull requests that update go code type: enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants