fix(feishu): pass quoted message media to Hermes when replying - #37262
fix(feishu): pass quoted message media to Hermes when replying#37262wengxiaoxiong wants to merge 2 commits into
Conversation
When a user replies to an image/file message and @mentions Hermes, the quoted message's media was silently dropped — Hermes only saw the reply text, never the original image or file. Root cause: _fetch_message_text() only extracted text from the quoted message, ignoring any media attachments. Fix: - Add _fetch_parent_message_with_media() which fetches the quoted message and also downloads its images/files via the existing _download_feishu_message_resources() helper, returning (text, media_urls, media_types). - Call _fetch_parent_message_with_media() instead of _fetch_message_text() in the inbound message handler. - Merge parent media_urls/media_types into the current message's media lists so they are forwarded to the agent. - If the current message is plain text but the parent has media, upgrade inbound_type to the parent's media type (e.g. PHOTO) so downstream handlers treat it as a media message.
Also fix a bug where MessageType enum was called with an unsupported 'default' keyword argument — use try/except ValueError instead. Tests cover: - text message returns text + empty media lists - image message returns text + populated media lists - cache hit skips API call and returns empty media - API failure returns (None, [], []) - no client returns (None, [], []) - _process_inbound_message merges parent media into the event
teknium1
left a comment
There was a problem hiding this comment.
Thanks for addressing a real Feishu reply-context gap. Current main still fetches only parent text at plugins/platforms/feishu/adapter.py:3259, while the existing resource helper at :3771-3800 can hydrate the parent attachments.
Problems
gateway/platforms/feishu.py:4018-4020returns empty media on a text-cache hit. After one reply to a quoted image/file, every subsequent reply to that same parent loses the attachment again;tests/gateway/test_feishu.py:5007-5020currently expects that loss.gateway/platforms/feishu.py:3082-3084passes MIME strings such asimage/jpegtoMessageType; these are not enum values, so all parent media falls back toPHOTO. On current main, PHOTO enters Feishu media batching (plugins/platforms/feishu/adapter.py:3307-3324), changing the semantics of a text reply and misclassifying audio/document/video parents.- The implementation path was relocated to
plugins/platforms/feishu/adapter.pyby560010547.
Suggested changes
- Port this to the bundled Feishu plugin, preserve the triggering reply as
MessageType.TEXT, and merge parent media only. - Store media with the cached parent context (or bypass the text-only cache), then cover repeated replies and image/audio/video/document parents.
Automated hermes-sweeper review.
| # If the current message is plain text but the quoted message has media, upgrade type | ||
| if inbound_type == MessageType.TEXT and parent_media_types: | ||
| try: | ||
| inbound_type = MessageType(parent_media_types[0]) |
There was a problem hiding this comment.
parent_media_types[0] is a MIME value (for example image/jpeg), not a MessageType value (photo, audio, etc.), so this always falls into the PHOTO fallback. Please keep the triggering reply as TEXT and let the existing per-attachment MIME routing handle the merged parent media.
| if not self._client or not message_id: | ||
| return None, [], [] | ||
| # Text-only result may already be cached; re-use it (media already empty for pure-text). | ||
| if message_id in self._message_text_cache: |
There was a problem hiding this comment.
This cache hit drops media for every later reply to the same quoted image/file. Cache the complete parent context including media paths and MIME types, or bypass the text-only cache for this lookup; add a repeated-reply regression test.
Problem
When a user replies to an image or file message in Feishu and @mentions Hermes, the quoted message's media was silently dropped — Hermes only saw the reply text, never the original image or file.
Root Cause
_fetch_message_text()only extracted text from the quoted (parent) message and ignored any media attachments.Fix
_fetch_parent_message_with_media()which fetches the quoted message and also downloads its images/files via the existing_download_feishu_message_resources()helper, returning(text, media_urls, media_types)._fetch_message_text()call in_process_inbound_message()with the new method.media_urls/media_typesinto the current message's media lists so they are forwarded to the agent.inbound_typeto the parent's media type (falls back toPHOTOon unknown types).How to Test
Testing
tests/gateway/test_feishu.py(TestFeishuFetchParentMessageWithMedia): text message, image message, cache hit, API failure, no-client guard, and end-to-end inbound merge.Platform
Tested on Linux. This change is Feishu-platform-specific (no file I/O, no process management, no cross-platform concerns).