Skip to content

fix(wecom): read media_id instead of media in send_message() - #2447

Open
AmirF194 wants to merge 1 commit into
langbot-app:masterfrom
AmirF194:fix/1687-wecom-send-message-media-key
Open

fix(wecom): read media_id instead of media in send_message()#2447
AmirF194 wants to merge 1 commit into
langbot-app:masterfrom
AmirF194:fix/1687-wecom-send-message-media-key

Conversation

@AmirF194

Copy link
Copy Markdown

概述 / Overview

WecomAdapter.send_message(), the entry point plugins use via PluginToRuntimeAction.SEND_MESSAGE, raises KeyError: 'media' for any image, voice, or file message part.

WecomMessageConverter.yiri2target() always builds these parts as {'type': 'image'|'voice'|'file', 'media_id': ...} (only ever media_id), and the sibling method reply_message() reads that key correctly. send_message() instead reads content['media'], a key that is never produced, so the call raises before reaching self.bot.send_image/send_voice/send_file.

This fixes the plugin.send_message symptom in #1687 (falls back to sending the unprocessed text because the call raises). The event_context.reply multi-part msg_id duplicate symptom in the same issue is a different, unconfirmed mechanism (a WeCom-side same-msg_id reply constraint, not this key mismatch) and is out of scope here.

检查清单 / Checklist

PR 作者完成 / For PR author

  • 阅读仓库贡献指引了吗? / Have you read the contribution guide?
  • 我已签署或将在机器人提示后签署 CLA。 / I have signed, or will sign when prompted by the bot, the CLA.
  • 与项目所有者沟通过了吗? / Have you communicated with the project maintainer?
  • 我确定已自行测试所作的更改,确保功能符合预期。 / I have tested the changes and ensured they work as expected.

Verification

  • New test tests/unit_tests/platform/test_wecom_send_message.py fails 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.
  • Not verified: an actual WeCom self-built-app account (no test tenant available here), and the separate msg_id-duplicate symptom in [Bug]: 企业微信图文消息集合只能发送第一个消息后续的消息报错MSG_ID重复 #1687.

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>
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 17, 2026
@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA. ✅ 所有贡献者均已签署 CLA。
Posted by the CLA Assistant Lite bot.

@AmirF194

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

@dosubot dosubot Bot added IM: wecom 企业微信 适配器相关 / WeCom and WeComCS adapter related m: Platform 机器人管理相关 / Bots management labels Aug 17, 2026
dadachann added a commit to langbot-app/cla that referenced this pull request Aug 17, 2026
@RockChinQ

Copy link
Copy Markdown
Member

Hi. Please provide screenshots to prove the changes work.

@AmirF194

Copy link
Copy Markdown
Author

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 (tests/unit_tests/platform/test_wecom_send_message.py) that reproduces the exact KeyError: 'media' on unmodified HEAD for image/voice/file sends, and passes after the one-line key fix (content['media'] -> content['media_id']), covering text-only sends too. If a screenshot from an actual tenant is a hard requirement here, I understand holding the PR until someone with WeCom access can confirm it.

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

IM: wecom 企业微信 适配器相关 / WeCom and WeComCS adapter related m: Platform 机器人管理相关 / Bots management size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants