[patch] PDD售后消息的过滤处理逻辑优化

This commit is contained in:
2025-10-15 09:28:54 +08:00
parent bdd3e125a0
commit 10cefc3c11
2 changed files with 25 additions and 8 deletions

View File

@@ -2564,25 +2564,38 @@ class ChatPdd:
msg_type = message_info.get("type") msg_type = message_info.get("type")
if msg_type == 31: # 机器人干预消息(如:机器人已暂停接待) if msg_type == 31: # 机器人干预消息(如:机器人已暂停接待)
return True return True
if msg_type == 8: # 平台系统卡片消息(如:售后提醒、平台通知等)
self._log(f"🚫 过滤系统卡片消息(type=8): {message_info.get('content', '')[:50]}", "DEBUG")
return True
# 2. 基于模板名称识别机器人消息 # 2. 基于模板名称识别机器人消息
template_name = message_info.get("template_name", "") template_name = message_info.get("template_name", "")
robot_templates = [ robot_templates = [
"mall_robot_man_intervention_and_restart", # 机器人暂停接待消息 "mall_robot_man_intervention_and_restart", # 机器人暂停接待消息
"mall_robot_text_msg", # 机器人自动回复消息 "mall_robot_text_msg", # 机器人自动回复消息
"aftersales_hosting_warning_card", # 售后托管警告卡片
# 可根据实际情况添加更多机器人模板 # 可根据实际情况添加更多机器人模板
] ]
if template_name in robot_templates: if template_name in robot_templates:
self._log(f"🚫 过滤模板消息: {template_name}", "DEBUG")
return True return True
# 3. 基于机器人特殊标志过滤 # 3. 基于info字段识别系统卡片消息售后提醒、订单提醒等
info = message_info.get("info", {})
if info and isinstance(info, dict):
# 如果info中包含mbtn_list按钮列表通常是系统卡片
if info.get("mbtn_list") or info.get("text_list"):
self._log(f"🚫 过滤系统卡片消息(含info.mbtn_list): {message_info.get('content', '')[:50]}", "DEBUG")
return True
# 4. 基于机器人特殊标志过滤
if message_info.get("conv_silent") is True: # 静默会话标志 if message_info.get("conv_silent") is True: # 静默会话标志
return True return True
if message_info.get("no_unreply_hint") == 1: # 无需回复提示标志 if message_info.get("no_unreply_hint") == 1: # 无需回复提示标志
return True return True
# 4. 基于消息内容识别机器人提示消息 # 5. 基于消息内容识别机器人提示消息和平台系统消息
content = message_info.get("content", "") content = message_info.get("content", "")
robot_content_patterns = [ robot_content_patterns = [
"机器人未找到对应的回复", "机器人未找到对应的回复",
@@ -2590,12 +2603,16 @@ class ChatPdd:
">>点此【立即恢复接待】<<", ">>点此【立即恢复接待】<<",
"点击添加", "点击添加",
"[当前用户来自", "[当前用户来自",
"请尽快解决售后问题", # 平台售后提醒
"平台介入退款", # 平台售后提醒
"请尽快处理售后", # 平台售后提醒
] ]
if any(pattern in content for pattern in robot_content_patterns): if any(pattern in content for pattern in robot_content_patterns):
self._log(f"🚫 过滤系统提示消息: {content[:50]}", "DEBUG")
return True return True
# 5. 基于biz_context中的机器人标识 # 6. 基于biz_context中的机器人标识
biz_context = message_info.get("biz_context", {}) biz_context = message_info.get("biz_context", {})
if biz_context.get("robot_msg_id"): # 有机器人消息ID if biz_context.get("robot_msg_id"): # 有机器人消息ID
return True return True
@@ -2643,11 +2660,11 @@ class ChatPdd:
goods_info = message_info.get("info", {}) goods_info = message_info.get("info", {})
from_info = message_info.get("from", {}) from_info = message_info.get("from", {})
uid = from_info.get("uid") uid = from_info.get("uid")
role = from_info.get("role") # role = from_info.get("role")
if role != "user": # if role != "user":
self._log(f"过滤非用户消息 (role={role})", "DEBUG") # self._log(f"过滤非用户消息 (role={role})", "DEBUG")
return # return
if nickname and content and uid: if nickname and content and uid:
self._log(f"用户消息 - {nickname}: {content}", "INFO") self._log(f"用户消息 - {nickname}: {content}", "INFO")

View File

@@ -9,7 +9,7 @@ import json # 用于将令牌保存为 JSON 格式
# 后端服务器配置 # 后端服务器配置
# BACKEND_HOST = "192.168.5.233" # BACKEND_HOST = "192.168.5.233"
BACKEND_HOST = "192.168.5.106" BACKEND_HOST = "192.168.5.12"
# BACKEND_HOST = "shuidrop.com" # BACKEND_HOST = "shuidrop.com"
# BACKEND_HOST = "test.shuidrop.com" # BACKEND_HOST = "test.shuidrop.com"
BACKEND_PORT = "8000" BACKEND_PORT = "8000"