添加后端重连后剔除ws功能
This commit is contained in:
@@ -2579,6 +2579,58 @@ class ChatPdd:
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
def should_filter_robot_message(self, message_data):
|
||||
"""专门判断是否为机器人消息需要过滤"""
|
||||
try:
|
||||
message_info = message_data.get("message", {})
|
||||
|
||||
# 1. 基于消息类型过滤机器人特殊消息
|
||||
msg_type = message_info.get("type")
|
||||
if msg_type == 31: # 机器人干预消息(如:机器人已暂停接待)
|
||||
return True
|
||||
|
||||
# 2. 基于模板名称识别机器人消息
|
||||
template_name = message_info.get("template_name", "")
|
||||
robot_templates = [
|
||||
"mall_robot_man_intervention_and_restart", # 机器人暂停接待消息
|
||||
"mall_robot_text_msg", # 机器人自动回复消息
|
||||
# 可根据实际情况添加更多机器人模板
|
||||
]
|
||||
if template_name in robot_templates:
|
||||
return True
|
||||
|
||||
# 3. 基于机器人特殊标志过滤
|
||||
if message_info.get("conv_silent") is True: # 静默会话标志
|
||||
return True
|
||||
|
||||
if message_info.get("no_unreply_hint") == 1: # 无需回复提示标志
|
||||
return True
|
||||
|
||||
# 4. 基于消息内容识别机器人提示消息
|
||||
content = message_info.get("content", "")
|
||||
robot_content_patterns = [
|
||||
"机器人未找到对应的回复",
|
||||
"机器人已暂停接待",
|
||||
">>点此【立即恢复接待】<<",
|
||||
"点击添加",
|
||||
"[当前用户来自",
|
||||
]
|
||||
|
||||
if any(pattern in content for pattern in robot_content_patterns):
|
||||
return True
|
||||
|
||||
# 5. 基于biz_context中的机器人标识
|
||||
biz_context = message_info.get("biz_context", {})
|
||||
if biz_context.get("robot_msg_id"): # 有机器人消息ID
|
||||
return True
|
||||
|
||||
# 不是机器人消息,不过滤
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
self._log(f"判断机器人消息时出错: {e}", "DEBUG")
|
||||
return False # 出错时不过滤,保持原有行为
|
||||
|
||||
async def handle_customer_message(self, message_data):
|
||||
"""处理来自后端的客服消息"""
|
||||
self._log("收到来自后端的客服消息", "INFO")
|
||||
@@ -2601,6 +2653,11 @@ class ChatPdd:
|
||||
async def process_incoming_message(self, message_data, wss, store):
|
||||
"""处理接收到的消息"""
|
||||
try:
|
||||
# 🔥 过滤机器人消息
|
||||
if self.should_filter_robot_message(message_data):
|
||||
self._log("🤖 检测到机器人消息,已过滤不发送给后端", "DEBUG")
|
||||
return
|
||||
|
||||
message_info = message_data.get("message", {})
|
||||
if not message_info:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user