fix: harden image handling and update docs
This commit is contained in:
@@ -148,7 +148,14 @@ class SystemOrchestrator:
|
||||
if is_order or is_price_only or is_sku_only or is_sku_amount:
|
||||
await self._handle_order_packet(platform, std_msg)
|
||||
logger.info(f"[订单消息] user={user_id} acc={std_msg.acc_id} 已入库更新状态")
|
||||
await repo.save_chat(platform, user_id, msg_text, "in", acc_id=std_msg.acc_id)
|
||||
await repo.save_chat(
|
||||
platform,
|
||||
user_id,
|
||||
msg_text,
|
||||
"in",
|
||||
acc_id=std_msg.acc_id,
|
||||
msg_type=std_msg.msg_type,
|
||||
)
|
||||
return
|
||||
|
||||
preview = (std_msg.content or "").replace("\n", "\\n")
|
||||
@@ -159,12 +166,20 @@ class SystemOrchestrator:
|
||||
f"type={std_msg.msg_type} images={len(std_msg.image_urls)} content={preview}"
|
||||
)
|
||||
|
||||
# 过滤心跳
|
||||
if not (std_msg.content or "").strip() and not std_msg.image_urls: return
|
||||
# 过滤心跳;图片消息即使暂时没拿到 URL,也不能直接丢掉
|
||||
if std_msg.msg_type != 1 and not (std_msg.content or "").strip() and not std_msg.image_urls:
|
||||
return
|
||||
|
||||
# 如果是商家人工回复,静默入库
|
||||
if direction == "out":
|
||||
await repo.save_chat(platform, user_id, std_msg.content, "out", acc_id=std_msg.acc_id)
|
||||
await repo.save_chat(
|
||||
platform,
|
||||
user_id,
|
||||
std_msg.content,
|
||||
"out",
|
||||
acc_id=std_msg.acc_id,
|
||||
msg_type=std_msg.msg_type,
|
||||
)
|
||||
return
|
||||
|
||||
# ID 去重
|
||||
@@ -326,7 +341,15 @@ class SystemOrchestrator:
|
||||
db_start = time.time()
|
||||
db_content = combined_content
|
||||
if all_image_urls: db_content = f"【系统:已收到{len(all_image_urls)}张图】\n{combined_content}"
|
||||
await repo.save_chat(platform, user_id, db_content, "in", acc_id=acc_id, image_urls=all_image_urls)
|
||||
await repo.save_chat(
|
||||
platform,
|
||||
user_id,
|
||||
db_content,
|
||||
"in",
|
||||
acc_id=acc_id,
|
||||
image_urls=all_image_urls,
|
||||
msg_type=final_msg.msg_type,
|
||||
)
|
||||
db_elapsed = time.time() - db_start
|
||||
logger.info(f"[计时] user={user_id} 消息入库: {db_elapsed:.2f}s")
|
||||
|
||||
@@ -376,11 +399,25 @@ class SystemOrchestrator:
|
||||
metadata={"acc_id": acc_id, "acc_type": acc_type}
|
||||
)
|
||||
await self.qianniu_adapter.translate_outbound(greet, user_id)
|
||||
await repo.save_chat(platform, user_id, greet.reply_content, "out", acc_id=acc_id)
|
||||
await repo.save_chat(
|
||||
platform,
|
||||
user_id,
|
||||
greet.reply_content,
|
||||
"out",
|
||||
acc_id=acc_id,
|
||||
msg_type=greet.msg_type,
|
||||
)
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
await self.qianniu_adapter.translate_outbound(std_res, user_id)
|
||||
await repo.save_chat(platform, user_id, std_res.reply_content, "out", acc_id=acc_id)
|
||||
await repo.save_chat(
|
||||
platform,
|
||||
user_id,
|
||||
std_res.reply_content,
|
||||
"out",
|
||||
acc_id=acc_id,
|
||||
msg_type=std_res.msg_type,
|
||||
)
|
||||
|
||||
if std_res.metadata.get("pending_transfer"):
|
||||
reason = str(std_res.metadata.get("pending_transfer_reason") or "").strip()
|
||||
@@ -450,10 +487,24 @@ class SystemOrchestrator:
|
||||
)
|
||||
|
||||
await self.qianniu_adapter.translate_outbound(notify, customer_id)
|
||||
await repo.save_chat("qianniu", customer_id, notify.reply_content, "out", acc_id=acc_id)
|
||||
await repo.save_chat(
|
||||
"qianniu",
|
||||
customer_id,
|
||||
notify.reply_content,
|
||||
"out",
|
||||
acc_id=acc_id,
|
||||
msg_type=notify.msg_type,
|
||||
)
|
||||
await asyncio.sleep(0.5)
|
||||
await self.qianniu_adapter.translate_outbound(transfer, customer_id)
|
||||
await repo.save_chat("qianniu", customer_id, transfer.reply_content, "out", acc_id=acc_id)
|
||||
await repo.save_chat(
|
||||
"qianniu",
|
||||
customer_id,
|
||||
transfer.reply_content,
|
||||
"out",
|
||||
acc_id=acc_id,
|
||||
msg_type=transfer.msg_type,
|
||||
)
|
||||
|
||||
self._last_transfer_time[f"{customer_id}@{acc_id}"] = time.time()
|
||||
await asyncio.to_thread(complete_pending_transfer, row_id)
|
||||
|
||||
Reference in New Issue
Block a user