|
@@ -35,6 +35,17 @@ class MessagesResource(Resource): |
|
|
|
|
|
|
|
|
wxid = msg.get("Wxid",'') |
|
|
wxid = msg.get("Wxid",'') |
|
|
wx_config = gewe_chat.wxchat.get_wxchat_config_from_cache(wxid) |
|
|
wx_config = gewe_chat.wxchat.get_wxchat_config_from_cache(wxid) |
|
|
|
|
|
|
|
|
|
|
|
# 自发命令 |
|
|
|
|
|
# if type_name=='AddMsg': |
|
|
|
|
|
# from_wxid = msg_data["FromUserName"]["string"] |
|
|
|
|
|
# if wxid=='from_wxid': |
|
|
|
|
|
# pass |
|
|
|
|
|
if type_name == 'AddMsg': |
|
|
|
|
|
handle_self_cmd(wxid,msg) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not bool(wx_config.get("agentEnabled",False)): |
|
|
if not bool(wx_config.get("agentEnabled",False)): |
|
|
logger.info(f'微信ID {wxid} 未托管,不处理') |
|
|
logger.info(f'微信ID {wxid} 未托管,不处理') |
|
|
return jsonify({"message": "收到微信回调消息"}) |
|
|
return jsonify({"message": "收到微信回调消息"}) |
|
@@ -110,9 +121,28 @@ class MessagesResource(Resource): |
|
|
logger.warning(f"未知消息类型") |
|
|
logger.warning(f"未知消息类型") |
|
|
|
|
|
|
|
|
return jsonify({"message": "收到微信回调消息"}) |
|
|
return jsonify({"message": "收到微信回调消息"}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def handle_self_cmd(wxid,msg): |
|
|
|
|
|
msg_data=msg.get("Data") |
|
|
|
|
|
from_wxid=msg_data["FromUserName"]["string"] |
|
|
|
|
|
msg_content=msg_data["Content"]["string"] |
|
|
|
|
|
if wxid == from_wxid: |
|
|
|
|
|
commands = { |
|
|
|
|
|
'启用托管': True, |
|
|
|
|
|
'关闭托管': False |
|
|
|
|
|
} |
|
|
|
|
|
if msg_content in commands: |
|
|
|
|
|
c_dict = gewe_chat.wxchat.get_wxchat_config_from_cache(wxid) |
|
|
|
|
|
if c_dict: |
|
|
|
|
|
from model import Models |
|
|
|
|
|
agent_config=Models.AgentConfig.model_validate(c_dict) |
|
|
|
|
|
agent_config.agentEnabled=commands[msg_content] |
|
|
|
|
|
|
|
|
|
|
|
gewe_chat.wxchat.save_wxchat_config(wxid, agent_config.model_dump()) |
|
|
|
|
|
logger.info(f'{wxid} {"启动" if commands[msg_content] else "关闭"}托管') |
|
|
|
|
|
|
|
|
def handle_text(token_id,app_id, wxid,msg_data,from_wxid, to_wxid): |
|
|
def handle_text(token_id,app_id, wxid,msg_data,from_wxid, to_wxid): |
|
|
|
|
|
|
|
|
''' |
|
|
''' |
|
|
私聊文本消息 |
|
|
私聊文本消息 |
|
|
''' |
|
|
''' |
|
@@ -237,7 +267,7 @@ def handle_text(token_id,app_id, wxid,msg_data,from_wxid, to_wxid): |
|
|
# 取消定时器 |
|
|
# 取消定时器 |
|
|
timeout_timer.cancel() |
|
|
timeout_timer.cancel() |
|
|
|
|
|
|
|
|
def check_timeout( task_thread:threading.Thread, token_id,wxid, app_id, callback_to_user): |
|
|
|
|
|
|
|
|
def check_timeout(task_thread:threading.Thread, token_id,wxid, app_id, callback_to_user): |
|
|
if task_thread.is_alive(): |
|
|
if task_thread.is_alive(): |
|
|
print(f"任务运行时间超过{timeout_duration}秒,token_id={token_id}, app_id={app_id}, callback_to_user={callback_to_user}") |
|
|
print(f"任务运行时间超过{timeout_duration}秒,token_id={token_id}, app_id={app_id}, callback_to_user={callback_to_user}") |
|
|
wx_config = gewe_chat.wxchat.get_wxchat_config_from_cache(wxid) |
|
|
wx_config = gewe_chat.wxchat.get_wxchat_config_from_cache(wxid) |
|
@@ -873,6 +903,9 @@ def check_chatroom(userName): |
|
|
return True |
|
|
return True |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def remove_markdown_symbol(text: str): |
|
|
# def remove_markdown_symbol(text: str): |
|
|
# # 移除markdown格式,目前先移除** |
|
|
# # 移除markdown格式,目前先移除** |
|
|
# if not text or not isinstance(text, str): |
|
|
# if not text or not isinstance(text, str): |
|
|