[patch] 更新PDD过滤消息基础逻辑 过滤部分系统机器人消息
This commit is contained in:
@@ -3353,74 +3353,83 @@ class ChatPdd:
|
||||
return False
|
||||
|
||||
def should_filter_robot_message(self, message_data):
|
||||
"""专门判断是否为机器人消息需要过滤"""
|
||||
"""专门判断是否为机器人消息需要过滤
|
||||
|
||||
🎯 当前过滤规则:仅过滤机器人系统提示消息(type=31, template_name='merchant_robot_system_hint_to_merchant_alone_text')
|
||||
示例:'消费者近期咨询过重要售后问题,机器人担心回答不好,本次会话机器人不再回复,请及时跟进'
|
||||
"""
|
||||
try:
|
||||
message_info = message_data.get("message", {})
|
||||
|
||||
# 1. 基于消息类型过滤机器人特殊消息
|
||||
# ✅ 【保留】1. 过滤机器人系统提示消息(type=31,商家机器人提示类消息)
|
||||
msg_type = message_info.get("type")
|
||||
if msg_type == 31: # 机器人干预消息(如:机器人已暂停接待)
|
||||
return True
|
||||
if msg_type == 8: # 平台系统卡片消息(如:售后提醒、平台通知等)
|
||||
self._log(f"🚫 过滤系统卡片消息(type=8): {message_info.get('content', '')[:50]}", "DEBUG")
|
||||
return True
|
||||
if msg_type == 64: # 🔥 新增:售后卡片消息(如:消费者申请售后)
|
||||
self._log(f"🚫 过滤售后卡片消息(type=64): {message_info.get('content', '')[:50]}", "DEBUG")
|
||||
return True
|
||||
|
||||
# 2. 基于模板名称识别机器人消息
|
||||
template_name = message_info.get("template_name", "")
|
||||
robot_templates = [
|
||||
"mall_robot_man_intervention_and_restart", # 机器人暂停接待消息
|
||||
"mall_robot_text_msg", # 机器人自动回复消息
|
||||
"aftersales_hosting_warning_card", # 售后托管警告卡片
|
||||
"apply_for_consultation_card_new", # 🔥 新增:售后协商申请卡片
|
||||
# 可根据实际情况添加更多机器人模板
|
||||
]
|
||||
if template_name in robot_templates:
|
||||
self._log(f"🚫 过滤模板消息: {template_name}", "DEBUG")
|
||||
return True
|
||||
|
||||
# 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: # 静默会话标志
|
||||
return True
|
||||
|
||||
if message_info.get("no_unreply_hint") == 1: # 无需回复提示标志
|
||||
return True
|
||||
|
||||
# 5. 基于消息内容识别机器人提示消息和平台系统消息
|
||||
# 精确匹配:type=31 且 template_name 包含机器人系统提示
|
||||
if msg_type == 31:
|
||||
# 机器人干预提示消息(如:机器人担心回答不好、机器人已暂停接待等)
|
||||
if template_name == "merchant_robot_system_hint_to_merchant_alone_text":
|
||||
content = message_info.get("content", "")
|
||||
robot_content_patterns = [
|
||||
"机器人未找到对应的回复",
|
||||
"机器人已暂停接待",
|
||||
">>点此【立即恢复接待】<<",
|
||||
"点击添加",
|
||||
"[当前用户来自",
|
||||
"请尽快解决售后问题", # 平台售后提醒
|
||||
"平台介入退款", # 平台售后提醒
|
||||
"请尽快处理售后", # 平台售后提醒
|
||||
"消费者申请售后", # 🔥 新增:售后申请通知
|
||||
"建议先与消费者友好协商", # 🔥 新增:售后协商提示
|
||||
]
|
||||
|
||||
if any(pattern in content for pattern in robot_content_patterns):
|
||||
self._log(f"🚫 过滤系统提示消息: {content[:50]}", "DEBUG")
|
||||
self._log(f"🚫 过滤机器人系统提示消息(type=31): {content[:50]}...", "DEBUG")
|
||||
return True
|
||||
|
||||
# 6. 基于biz_context中的机器人标识
|
||||
biz_context = message_info.get("biz_context", {})
|
||||
if biz_context.get("robot_msg_id"): # 有机器人消息ID
|
||||
return True
|
||||
# ❌ 【暂时注释】其他类型的系统消息过滤(后续如需恢复,取消注释即可)
|
||||
# if msg_type == 8: # 平台系统卡片消息(如:售后提醒、平台通知等)
|
||||
# self._log(f"🚫 过滤系统卡片消息(type=8): {message_info.get('content', '')[:50]}", "DEBUG")
|
||||
# return True
|
||||
# if msg_type == 64: # 售后卡片消息(如:消费者申请售后)
|
||||
# self._log(f"🚫 过滤售后卡片消息(type=64): {message_info.get('content', '')[:50]}", "DEBUG")
|
||||
# return True
|
||||
|
||||
# 不是机器人消息,不过滤
|
||||
# ❌ 【暂时注释】2. 基于模板名称识别其他机器人消息
|
||||
# template_name = message_info.get("template_name", "")
|
||||
# robot_templates = [
|
||||
# "mall_robot_man_intervention_and_restart", # 机器人暂停接待消息
|
||||
# "mall_robot_text_msg", # 机器人自动回复消息
|
||||
# "aftersales_hosting_warning_card", # 售后托管警告卡片
|
||||
# "apply_for_consultation_card_new", # 售后协商申请卡片
|
||||
# ]
|
||||
# if template_name in robot_templates:
|
||||
# self._log(f"🚫 过滤模板消息: {template_name}", "DEBUG")
|
||||
# return True
|
||||
|
||||
# ❌ 【暂时注释】3. 基于info字段识别系统卡片消息
|
||||
# info = message_info.get("info", {})
|
||||
# if info and isinstance(info, dict):
|
||||
# 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: # 静默会话标志
|
||||
# return True
|
||||
# if message_info.get("no_unreply_hint") == 1: # 无需回复提示标志
|
||||
# return True
|
||||
|
||||
# ❌ 【暂时注释】5. 基于消息内容识别机器人提示消息
|
||||
# content = message_info.get("content", "")
|
||||
# robot_content_patterns = [
|
||||
# "机器人未找到对应的回复",
|
||||
# "机器人已暂停接待",
|
||||
# ">>点此【立即恢复接待】<<",
|
||||
# "点击添加",
|
||||
# "[当前用户来自",
|
||||
# "请尽快解决售后问题",
|
||||
# "平台介入退款",
|
||||
# "请尽快处理售后",
|
||||
# "消费者申请售后",
|
||||
# "建议先与消费者友好协商",
|
||||
# ]
|
||||
# if any(pattern in content for pattern in robot_content_patterns):
|
||||
# self._log(f"🚫 过滤系统提示消息: {content[:50]}", "DEBUG")
|
||||
# return True
|
||||
|
||||
# ❌ 【暂时注释】6. 基于biz_context中的机器人标识
|
||||
# biz_context = message_info.get("biz_context", {})
|
||||
# if biz_context.get("robot_msg_id"):
|
||||
# return True
|
||||
|
||||
# 不是需要过滤的消息,放行
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
@@ -3450,9 +3459,9 @@ class ChatPdd:
|
||||
"""处理接收到的消息"""
|
||||
try:
|
||||
# 🔥 过滤机器人消息
|
||||
# if self.should_filter_robot_message(message_data):
|
||||
# self._log("🤖 检测到机器人消息,已过滤不发送给后端", "DEBUG")
|
||||
# return
|
||||
if self.should_filter_robot_message(message_data):
|
||||
self._log("🤖 检测到机器人消息,已过滤不发送给后端", "DEBUG")
|
||||
return
|
||||
|
||||
message_info = message_data.get("message", {})
|
||||
if not message_info:
|
||||
|
||||
Reference in New Issue
Block a user