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 <noreply@anthropic.com>
This commit is contained in:
dalianmao000 2026-04-11 22:56:37 +08:00 committed by Teknium
parent f4f4078ad9
commit cf53e2676b

View file

@ -636,6 +636,13 @@ class WeComAdapter(BasePlatformAdapter):
if voice_text: if voice_text:
text_parts.append(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 = body.get("quote") if isinstance(body.get("quote"), dict) else {}
quote_type = str(quote.get("msgtype") or "").lower() quote_type = str(quote.get("msgtype") or "").lower()
if quote_type == "text": if quote_type == "text":
@ -668,6 +675,13 @@ class WeComAdapter(BasePlatformAdapter):
refs.append(("image", body["image"])) refs.append(("image", body["image"]))
if msgtype == "file" and isinstance(body.get("file"), dict): if msgtype == "file" and isinstance(body.get("file"), dict):
refs.append(("file", body["file"])) 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 = body.get("quote") if isinstance(body.get("quote"), dict) else {}
quote_type = str(quote.get("msgtype") or "").lower() quote_type = str(quote.get("msgtype") or "").lower()