fix: dedupe wechat chat history and avoid duplicate outbound chat logging
This commit is contained in:
@@ -83,11 +83,17 @@ async def push_chat_to_wechat(
|
||||
|
||||
# 附带近期对话,保持连贯
|
||||
recent = _get_recent_conversation(customer_id, acc_id, last_n=8)
|
||||
last_line = None
|
||||
for m in recent:
|
||||
role = customer_id if m.get("direction") == "in" else "客服"
|
||||
msg = _truncate((m.get("message") or "").strip(), 120)
|
||||
if msg:
|
||||
lines.append(f"{role}:{msg}")
|
||||
line = f"{role}:{msg}"
|
||||
# 防止日志中的重复记录在企微里连续刷屏
|
||||
if line == last_line:
|
||||
continue
|
||||
lines.append(line)
|
||||
last_line = line
|
||||
# 当前回复(可能已在 recent 中有客户消息,客服回复是新的)
|
||||
lines.append(f"客服:{reply_msg or '(无回复)'}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user