fix(dingtalk-platform): extract ASR recognition and file message text from incoming messages - #50014
fix(dingtalk-platform): extract ASR recognition and file message text from incoming messages#50014rayjerrywoo wants to merge 2 commits into
Conversation
0f589ce to
b1af1a3
Compare
… from incoming messages
3 fixes for the dingtalk-platform plugin (plugins/platforms/dingtalk/adapter.py):
1. _extract_text: parse ASR recognition text from voice messages via
extensions['content']['recognition'], fall back to fileName for
file messages ("[文件] xxx")
2. _extract_media: handle audio/file/image msgtype_str with correct
MIME mapping; exclude audio from media_urls to preserve DingTalk's
built-in ASR result (avoids failed whisper re-transcription)
3. _resolve_media_codes: parse downloadCode from extensions['content']
for file/image message types
All tested with live DingTalk group chat: voice → recognition text,
PDF/Markdown file → filename + download.
teknium1
left a comment
There was a problem hiding this comment.
Thanks for targeting the post-plugin-refactor inbound-media gap. The current adapter still lacks handling for extensions.content audio/file/image payloads (plugins/platforms/dingtalk/adapter.py:765-824,1301-1338), so the premise remains valid.
Problems
- The new
msgtype='image'path is grouped with files and unconditionally setsMessageType.DOCUMENTatplugins/platforms/dingtalk/adapter.py:879. Image MIME values map toPHOTOin the normalized adapter contract (plugins/platforms/google_chat/adapter.py:302-316), andPHOTOhas distinct busy-session handling (gateway/platforms/base.py:4763-4769). - Please add regression tests. Existing DingTalk coverage tests rich-text media but not these new
extensions.contentpayload shapes (tests/gateway/test_dingtalk.py:574-623).
Suggested changes
- Split image classification from generic files: retain
DOCUMENTfor files, but emitPHOTOforimage/*attachments. - Cover ASR text, file name/code resolution, and direct-image MIME/type extraction with fixture-like message objects.
Automated hermes-sweeper review.
| mime = EXT_MAP.get(ext, mime) | ||
| media_types.append(mime) | ||
| if msg_type == MessageType.TEXT: | ||
| msg_type = MessageType.DOCUMENT |
There was a problem hiding this comment.
This branch also handles msgtype='image', but it always emits DOCUMENT. Please classify image MIME values as PHOTO; PHOTO has separate busy-session album/queue behavior in gateway/platforms/base.py, while the existing MIME-based adapter mappings also treat image/* as PHOTO.
… card/interactiveCard message handling - Promote EXT_MAP to a module-level constant for reuse - Classify DingTalk image messages and image file attachments as PHOTO - Extract DingTalk card/interactiveCard document link content with defensive parsing - Handle None, empty, JSON, and plain-string card content fields - Add coverage: 8 card + 4 interactiveCard + 5 _extract_media = 17 test cases - Remove a shadowed duplicate TestExtractText class (pytest collected only the later one)
b1af1a3 to
d8f667b
Compare
|
@teknium1 Thanks for the review — the feedback has been addressed in the second commit (d8f667b). Summary of the follow-up changes:
17 new test cases covering all the above scenarios are included in the second commit. Please take another look when you get a chance. |
|
Merged into main via consolidated salvage PR #73515 (merge Your contribution is credited to you in git history. Thank you! Closing this PR as merged-via-salvage. |
Summary
3 fixes for the dingtalk-platform plugin (
plugins/platforms/dingtalk/adapter.py) enabling:All of which were missing after the refactor from
gateway/platforms/dingtalk.pyto the plugin architecture.Changes
_extract_text— Voice ASR and file filenameextensions['content']['recognition']extensions['content']['fileName']for file messages (rendered as[文件] filename)_extract_media— Audio/file/image type detectionmsgtype='audio': setVOICEtype but skip passing media URLs (preserves DingTalk's built-in ASR result, avoids failed whisper re-transcription)msgtype='file'/'image': parse downloadCode, map common file extensions to MIME types_resolve_media_codes— Download code for file/imagedownloadCodefromextensions['content']for file and image message typesNotes
plugins/platforms/dingtalk/adapter.py) — the oldgateway/platforms/dingtalk.pyhas been deleted upstream. Before applying, ensure your Hermes is up to date (post-refactor, commit ≥560010547) and thedingtalk-platformplugin is enabled.