From cf53e2676b64e94e1f027e426f70f8a6cecc0949 Mon Sep 17 00:00:00 2001 From: dalianmao000 Date: Sat, 11 Apr 2026 22:56:37 +0800 Subject: [PATCH] fix(wecom): handle appmsg attachments (PDF/Word/Excel) from WeCom AI Bot WeCom AI Bot sends file attachments with msgtype="appmsg", not msgtype="file". Previously only file content was discarded while the text title reached the agent. Changes: - _extract_text(): Extract appmsg title (filename) for display - _extract_media(): Handle appmsg type with file/image content Fixes #7750 Co-Authored-By: Claude Opus 4.6 --- gateway/platforms/wecom.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/gateway/platforms/wecom.py b/gateway/platforms/wecom.py index 6fde73927..aa07dc6a9 100644 --- a/gateway/platforms/wecom.py +++ b/gateway/platforms/wecom.py @@ -636,6 +636,13 @@ class WeComAdapter(BasePlatformAdapter): if voice_text: text_parts.append(voice_text) + # Extract appmsg title (filename) for WeCom AI Bot attachments + if msgtype == "appmsg": + appmsg = body.get("appmsg") if isinstance(body.get("appmsg"), dict) else {} + title = str(appmsg.get("title") or "").strip() + if title: + text_parts.append(title) + quote = body.get("quote") if isinstance(body.get("quote"), dict) else {} quote_type = str(quote.get("msgtype") or "").lower() if quote_type == "text": @@ -668,6 +675,13 @@ class WeComAdapter(BasePlatformAdapter): refs.append(("image", body["image"])) if msgtype == "file" and isinstance(body.get("file"), dict): refs.append(("file", body["file"])) + # Handle appmsg (WeCom AI Bot attachments with PDF/Word/Excel) + if msgtype == "appmsg" and isinstance(body.get("appmsg"), dict): + appmsg = body["appmsg"] + if isinstance(appmsg.get("file"), dict): + refs.append(("file", appmsg["file"])) + elif isinstance(appmsg.get("image"), dict): + refs.append(("image", appmsg["image"])) quote = body.get("quote") if isinstance(body.get("quote"), dict) else {} quote_type = str(quote.get("msgtype") or "").lower()