fix(wecom): add media attachment support to send_message tool#43493
fix(wecom): add media attachment support to send_message tool#43493liuhao1024 wants to merge 1 commit into
Conversation
WeCom's `_send_to_platform()` had no media branch — media files were silently dropped with a warning. Add a dedicated WeCom media path that uploads each file via the adapter's `_send_media_source()` pipeline before delivering the text message. Fixes NousResearch#37364
austinpickett
left a comment
There was a problem hiding this comment.
✅ APPROVE — genuine bug fix, not net-new capability
Bug or new capability? This is a genuine bug fix. The WeCom adapter already implements a full media pipeline: _send_media_source, send_image, send_image_file, send_document, send_voice, send_video — all backed by _prepare_outbound_media + _upload_media_bytes. However, the _send_wecom function in send_message_tool.py only called adapter.send() (text only), so even when media_files was passed to _send_to_platform for a WeCom target, it fell through to the generic "unsupported platform for media" error path. The adapter capability existed; the tool-layer wire-up did not. This is a broken-delivery bug.
Error handling on upload failure. _send_media_source wraps the upload in a try/except for both asyncio.TimeoutError and generic Exception, returns SendResult(success=False, error=...) on failure. The tool-layer code logs a warning on media failure but does not abort — it continues to send the text message. This is intentionally lenient (best-effort media delivery). For a P2 bug fix this is acceptable, though a stricter "fail on media error" option could be a follow-up.
File size limits. The adapter enforces WeCom's documented limits via _apply_file_size_limits:
- Images: 10 MB (downgrades to file on exceed, not rejected)
- Video: 10 MB (downgrades to file)
- Voice: 2 MB
- Files: 20 MB hard limit (rejected with error message)
- Absolute max: 20 MB
These match WeCom's documented API constraints. No hard-coded limits in the new tool-layer code; it defers entirely to the adapter.
Media type coverage. _send_media_source handles images, video, voice (audio), and documents (files) via _prepare_outbound_media, which detects content type from magic bytes / extension. The _is_voice flag from media_files tuples is not forwarded to _send_media_source (the adapter auto-detects). This is consistent with how other platform adapters in send_message_tool handle the flag (many ignore it and let type detection win). Not a regression.
File-not-found handling. The tool checks os.path.exists(media_path) before calling the adapter and logs+skips missing files while still delivering the text. This prevents silent crashes on stale temp paths.
Backward compatibility. _send_wecom signature adds media_files=None — fully backward compatible. The "only supported for …" error strings are updated to include wecom.
Tests. Five tests: with media, without media (backward compat), media-only (no text), file-not-found skip, and platform routing with media_files. All key paths covered.
What does this PR do?
Adds native media attachment support to the WeCom
send_messagetool path. Previously,MEDIA:<file_path>directives targeting WeCom were silently dropped — only text was delivered.Related Issue
Fixes #37364
Type of Change
Changes Made
tools/send_message_tool.py: Added a WeCom media branch in_send_to_platform()before the "Non-media platforms" catch-all, routing media files throughadapter._send_media_source(). Updated_send_wecom()to accept optionalmedia_filesparameter. Updated warning messages to include "wecom" in the supported platform list.tests/tools/test_send_message_tool.py: AddedTestSendWecomMediaclass with 5 tests covering media+text, text-only, media-only, missing-file, and routing integration.How to Test
pytest tests/tools/test_send_message_tool.py::TestSendWecomMedia -xvs— all 5 tests should passpytest tests/tools/test_send_message_tool.py -x— all existing tests should still pass (138 total)send_messagewithtarget="wecom"and aMEDIA:/path/to/image.pngdirective — the image should be uploaded and delivered before the text messageChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
tools/send_message_tool.py::_send_to_platform,tools/send_message_tool.py::_send_wecom,gateway/platforms/wecom.py::_send_media_source