fix(send_message): route WeCom MEDIA through live gateway adapter (#37364)#37380
Closed
alaamohanad169-ship-it wants to merge 1 commit into
Closed
fix(send_message): route WeCom MEDIA through live gateway adapter (#37364)#37380alaamohanad169-ship-it wants to merge 1 commit into
alaamohanad169-ship-it wants to merge 1 commit into
Conversation
…usResearch#37364) WeCom's standalone _send_wecom path opens a fresh WebSocket, which fails with errcode 846609 ("aibot websocket not subscribed") whenever the gateway is already running — WeCom enforces a single WebSocket per bot. Add a Platform.WECOM and media_files branch in _send_to_platform() that routes through a new _send_wecom_via_adapter helper. The helper grabs the live WeComAdapter from the running gateway (via _gateway_runner_ref) and uses its native send_image_file / send_document / send_voice / send_video methods, so the existing WebSocket is reused. Falls back to: * an actionable error when media is requested but no live adapter is reachable (e.g. cron in a separate process), and * the legacy _send_wecom standalone path for text-only sends so the existing text contract is unchanged. Updates the user-facing supported-platforms list to include wecom. Tests: 5 new cases in tests/tools/test_send_message_tool.py covering the routing, the live-adapter dispatch, the no-adapter error path, and the text-only fallback. Full file: 134 passed. WeCom gateway tests: 46 passed.
Collaborator
|
Duplicate of #37370 — both PRs fix #37364 (WeCom |
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
Fixes #37364 —
send_messagewithtarget="wecom"and aMEDIA:directive was silently dropping the attachment. The text message still delivered, but the media fell through to the "Non-media platforms" catch-all and was discarded.Root cause
Two layered problems:
No media branch.
_send_to_platform()intools/send_message_tool.pyhad a dedicatedmedia_filesbranch for Telegram, Weixin, Discord, Matrix, Signal, Yuanbao, and Feishu — but not WeCom. WeCom media hit the generic non-media catch-all (lines ~825-838 pre-fix) and was dropped with a warning.Standalone path can't connect. The fallback text-only
_send_wecom()instantiates its ownWeComAdapterand callsconnect(). WeCom enforces a single WebSocket per bot, so this fails witherrcode 846609: aibot websocket not subscribedwhenever the gateway is already running with the same credentials.Fix
Add a
Platform.WECOM and media_filesbranch in_send_to_platform()that dispatches to a new_send_wecom_via_adapter()helper. The helper:WeComAdapterfrom the running gateway via_gateway_runner_ref()(so the existing WebSocket is reused).adapter.send(chat_id, content).send_image_file,send_document,send_voice, orsend_videobased on file extension (same dispatch logic used by Feishu and Matrix)._send_wecom()for text-only sends, so the existing text contract is unchanged.I deliberately did not touch the standalone text-only path. The issue (#37364) is scoped to media delivery, and the text-only WebSocket conflict is a separate concern — left a note in the docstring for follow-up.
Why not the "clear _last_chat_req_ids" approach suggested in the issue?
The issue proposed clearing
_last_chat_req_ids[chat_id]before the send so the adapter falls through to proactive (aibot_send_msg) mode. I considered it and rejected it: WeCom AI Bots in group chats cannot useAPP_CMD_SENDproactively (seetests/gateway/test_wecom.pylines ~794-833, plus the comment ingateway/platforms/wecom.py:900). In groups, every send MUST be anAPP_CMD_RESPONSEbound to an inboundreq_id. The existing_send_media_source()already does the right thing — if a cached req_id exists for the chat, it replies; otherwise it sends proactively. The helper just calls into that existing logic, so group chats keep working.Tests
TestSendWecomMedia— 2 cases:Platform.WECOM and media_filesnow dispatches to the helper; text-only still hits the legacy path.TestSendWecomViaAdapter— 3 cases: live adapter dispatches image vs. document correctly, no live adapter returns a helpful error for media, no live adapter falls back for text-only.5 new tests pass. Full file: 134 passed. WeCom gateway tests: 46 passed.
Files changed
tools/send_message_tool.py— new helper, new branch, updated user-facing supported-platforms list.tests/tools/test_send_message_tool.py— 5 new tests.Risk
Low. The change is additive: a new
ifbranch that is only entered whenmedia_filesis non-empty AND platform is WeCom. Text-only behavior is byte-identical. The new helper mirrors the dispatch pattern already used for Feishu and Matrix.Related