落地私聊图片询价:识图当口播复用三线文字流程,图上航线三字码保持原样,避免被改写成中文地名。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-18 15:51:55 +08:00
co-authored by Cursor
parent 982b3a2317
commit 8219dce84b
30 changed files with 2153 additions and 45 deletions
@@ -628,6 +628,42 @@ class WeComAppClient:
self._token_expire_at = time.time() + expires_in
return token
def download_media(self, media_id: str) -> tuple[bytes, str]:
"""
下载企微临时素材(cgi-bin/media/get)。
返回 (字节, 错误码)。失败时字节为空。禁止把 token 写入日志。
调用:Worker 识别槽,禁止回调线程同步下载。
"""
mid = (media_id or "").strip()
if not mid:
return b"", "media_empty"
try:
token = self._get_token()
except Exception:
logger.exception("下载素材取 token 失败")
return b"", "token_failed"
url = f"{self._api_base}/cgi-bin/media/get"
try:
with httpx.Client(timeout=self._timeout) as client:
resp = client.get(url, params={"access_token": token, "media_id": mid})
ctype = (resp.headers.get("content-type") or "").lower()
raw = resp.content or b""
if "application/json" in ctype or raw[:1] in (b"{", b"["):
try:
data = resp.json()
except Exception:
data = {}
if isinstance(data, dict) and int(data.get("errcode") or 0) != 0:
return b"", str(data.get("errmsg") or "media_get_fail")
return b"", "media_json_body"
if len(raw) < 32:
return b"", "media_too_small"
return raw, ""
except Exception:
logger.exception("下载素材失败")
return b"", "media_download_failed"
# 企微侧明确不可重试的错误(IP 白名单、非法 userid 等)
PERMANENT_SEND_ERRORS = frozenset(
+5
View File
@@ -75,6 +75,11 @@ class ChannelRuntime:
from agent.routing.decision import RouteDecision
decision = RouteDecision(intent="ordinary_text_other")
elif (message.msg_type or "text").lower() == "image":
from agent.routing.decision import RouteDecision
# 私聊图片不进 DeepSeek A(正文为空会被判闲聊)。
decision = RouteDecision(intent="image_inquiry", confidence=1.0)
else:
decision = self._router.route_inbound(
text=message.content or "",