From 4dbc1a0ace6cbad05d15f4c869211008a50c49f1 Mon Sep 17 00:00:00 2001 From: jjz <3082705704@qq.com> Date: Fri, 26 Sep 2025 14:35:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=8E=E7=AB=AF=E9=87=8D?= =?UTF-8?q?=E8=BF=9E=E5=90=8E=E5=89=94=E9=99=A4ws=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Utils/Pdd/PddUtils.py | 57 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/Utils/Pdd/PddUtils.py b/Utils/Pdd/PddUtils.py index 8820889..5da34a0 100644 --- a/Utils/Pdd/PddUtils.py +++ b/Utils/Pdd/PddUtils.py @@ -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