feat(feishu): include replied-to message content in agent context#472
Open
Cigarrr wants to merge 2 commits intochenhg5:mainfrom
Open
feat(feishu): include replied-to message content in agent context#472Cigarrr wants to merge 2 commits intochenhg5:mainfrom
Cigarrr wants to merge 2 commits intochenhg5:mainfrom
Conversation
When a user replies to a specific message in a Lark/Feishu chat, the bot now fetches the parent message content via Im.Message.Get and prepends it as a quoted context block, so the agent can see what the user is referring to. - Add fetchQuotedMessage() that retrieves and formats the parent message content for text, post (rich text), and other message types - Add extractPostPlainText() helper for parsing Lark post JSON (supports both flat and locale-wrapped formats) - Graceful degradation: on any API failure the quote is silently skipped and the user's message is delivered as before - Only triggers when ParentId is non-empty (reply scenario) - Uses the same Im.Message.Get API already used by parseMergeForward Closes chenhg5#470
95e3bf6 to
7953fcb
Compare
chenhg5
approved these changes
Apr 6, 2026
Owner
chenhg5
left a comment
There was a problem hiding this comment.
LGTM! Great feature addition for Feishu reply context.
What I like:
- Clean implementation with graceful degradation — API failures don't block the user's message
- Good test coverage for
extractPostPlainText(flat format, locale-wrapped, empty, non-text tags) - Minimal blast radius — only
platform/feishu/feishu.gomodified - Reuses existing patterns (
Im.Message.Get,resolveUserName)
Edge cases handled:
- Locale-wrapped post content (
{"zh_cn": {...}}) - Non-text message types (image, file →
[image]placeholder) - Missing sender info → "unknown" fallback
Thanks for the contribution!
3 tasks
…messages extractPostPlainText only handled "text" tags, silently dropping link text, code blocks, and horizontal rules from quoted post messages. Add a switch on elem.Tag to also extract "a" (link text), "code_block" (fenced code with language), and "hr" (separator). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
chenhg5
pushed a commit
that referenced
this pull request
Apr 8, 2026
… messages In extractPostPlainText, now handles: - "a" (link) tags: extracts link text alongside regular text - "hr" tags: renders as markdown horizontal rule - "code_block": skips empty language prefix in fence when language is unset Based on work from PR #472 by @Cigarrr. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4 tasks
Owner
|
This PR has merge conflicts with main because the core I've cherry-picked the remaining unique improvements from this PR's second commit (link tag, hr tag, and improved code_block formatting in This PR can be closed once #508 is merged. Thanks @Cigarrr for the contribution! |
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.
Summary
When a user replies to a specific message in a Lark/Feishu chat, the agent currently has no visibility into the quoted message content — it only sees the user's reply text. This PR fixes that by fetching the parent message via
Im.Message.Getand prepending a formatted quote block to the agent's input.Closes #470
Environment
Changes
fetchQuotedMessage(parentID): New method that retrieves the parent message content and formats it as[Quoted message from <sender>]:\n<content>\n\nextractPostPlainText(content): New helper for parsing Lark rich-text (post) JSON into plain text, supporting both flat and locale-wrapped formatsonMessage: CapturesParentIdfrom the incoming event and passes it todispatchMessagedispatchMessage: Fetches quoted content whenparentIDis non-empty, prepends it totextandpostmessage typesDesign decisions
Im.Message.Getcall used byparseMergeForward, sameresolveUserNamefor sender resolutionplatform/feishu/feishu.gomodified; no changes tocore.Messagestruct or other platformstextandpostmessages only (the most common reply scenarios). Image/audio/file replies still work as before, just without the quote prefix.Test plan
go test ./...passes (pre-existing failure incorepackage unrelated to this change)extractPostPlainText: flat format, locale-wrapped, no title, empty content, non-text tags[image]placeholder