fix(wecom): read media_id instead of media in send_message() - #2447
fix(wecom): read media_id instead of media in send_message()#2447AmirF194 wants to merge 1 commit into
Conversation
WecomMessageConverter.yiri2target() always emits {'media_id': ...} for
image/voice/file parts (never 'media'), matching the correct usage
already in reply_message(). send_message(), the entry point plugins
use via PluginToRuntimeAction.SEND_MESSAGE, instead read
content['media'], which is never set, so any image/voice/file part
raises KeyError and aborts the send.
Refs langbot-app#1687
Signed-off-by: Amir Fathi <amirfathi.me@gmail.com>
|
All contributors have signed the CLA. ✅ 所有贡献者均已签署 CLA。 |
|
I have read the CLA Document and I hereby sign the CLA |
|
Hi. Please provide screenshots to prove the changes work. |
|
I don't have a live WeCom self-built-app tenant to capture a real screenshot, sorry, that's a real gap in the PR body too. What I do have: a regression test ( |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
概述 / Overview
WecomAdapter.send_message(), the entry point plugins use viaPluginToRuntimeAction.SEND_MESSAGE, raisesKeyError: 'media'for any image, voice, or file message part.WecomMessageConverter.yiri2target()always builds these parts as{'type': 'image'|'voice'|'file', 'media_id': ...}(only evermedia_id), and the sibling methodreply_message()reads that key correctly.send_message()instead readscontent['media'], a key that is never produced, so the call raises before reachingself.bot.send_image/send_voice/send_file.This fixes the
plugin.send_messagesymptom in #1687 (falls back to sending the unprocessed text because the call raises). Theevent_context.replymulti-partmsg_idduplicate symptom in the same issue is a different, unconfirmed mechanism (a WeCom-side same-msg_idreply constraint, not this key mismatch) and is out of scope here.检查清单 / Checklist
PR 作者完成 / For PR author
Verification
tests/unit_tests/platform/test_wecom_send_message.pyfails on unmodified HEAD (KeyError: 'media'for image/voice/file) and passes after the fix; text-only send is covered too.uv run pytest tests/unit_tests/ tests/smoke/(Python 3.12): 2788 passed, 1 skipped.tests/unit_tests/platform/also re-run clean on Python 3.11 and 3.13.uv run ruff check/ruff format --check: clean.msg_id-duplicate symptom in [Bug]: 企业微信图文消息集合只能发送第一个消息后续的消息报错MSG_ID重复 #1687.