From f8a27770258214c08eae07d2af938a497030e2da Mon Sep 17 00:00:00 2001 From: H Vs Date: Fri, 14 Feb 2025 16:55:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=89=98=E7=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/messages_resource.py | 49 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/resources/messages_resource.py b/resources/messages_resource.py index b7230a1..67b9951 100644 --- a/resources/messages_resource.py +++ b/resources/messages_resource.py @@ -32,7 +32,12 @@ class MessagesResource(Resource): if token_id=="": logger.warning('找不到登录信息,不处理') return jsonify({"message": "收到微信回调消息"}) - + + wx_config = gewe_chat.wxchat.get_wxchat_config_from_cache(wxid) + if not bool(wx_config.get("agentEnabled",False)): + logger.info('智能体未启用,不处理') + return jsonify({"message": "收到微信回调消息"}) + if type_name=='AddMsg': wxid = msg.get("Wxid") msg_data = msg.get("Data") @@ -41,33 +46,27 @@ class MessagesResource(Resource): to_wxid = msg_data["ToUserName"]["string"] msg_push_content=msg_data.get("PushContent") #群发 - wx_config = gewe_chat.wxchat.get_wxchat_config_from_cache(wxid) - if not bool(wx_config.get("agentEnabled",False)): - logger.warning(f'{wxid} 智能体已关闭') - handlers = { + #wx_config = gewe_chat.wxchat.get_wxchat_config_from_cache(wxid) + + + handlers = { + 1: handle_text, + 3: handle_image, + 34: handle_voice, 49: handle_xml, - 37: handle_add_friend_notice, + 37: handle_add_friend_notice, 10002: handle_10002_msg } - else: - handlers = { - 1: handle_text, - 3: handle_image, - 34: handle_voice, - 49: handle_xml, - 37: handle_add_friend_notice, - 10002: handle_10002_msg - } - # (扫码进群情况)判断受否是群聊,并添加到通信录 - if check_chatroom(from_wxid) or check_chatroom(to_wxid): - logger.info('群信息') - chatroom_id=from_wxid - ret,msg,data=gewe_chat.wxchat.save_contract_list(token_id,app_id,chatroom_id,3) - logger.info(f'保存到通讯录 chatroom_id {chatroom_id} {msg}') - gewe_chat.wxchat.update_groups_info_to_cache(token_id,app_id,wxid,chatroom_id) - handlers[1]=handle_text_group - handlers[3]=handle_image_group - handlers[34]=handle_voice_group + # (扫码进群情况)判断受否是群聊,并添加到通信录 + if check_chatroom(from_wxid) or check_chatroom(to_wxid): + logger.info('群信息') + chatroom_id=from_wxid + ret,msg,data=gewe_chat.wxchat.save_contract_list(token_id,app_id,chatroom_id,3) + logger.info(f'保存到通讯录 chatroom_id {chatroom_id} {msg}') + gewe_chat.wxchat.update_groups_info_to_cache(token_id,app_id,wxid,chatroom_id) + handlers[1]=handle_text_group + handlers[3]=handle_image_group + handlers[34]=handle_voice_group handler = handlers.get(msg_type) if handler: