|
|
@@ -368,28 +368,52 @@ async def handle_text_async(request: Request,token_id,app_id, wxid,msg_data,from |
|
|
|
''' |
|
|
|
私聊文本消息 |
|
|
|
''' |
|
|
|
msg_content=msg_data["Content"]["string"] |
|
|
|
|
|
|
|
config=await request.app.state.gewe_service.get_wxchat_config_from_cache_async(wxid) |
|
|
|
validated_config = AgentConfig.model_validate(config) |
|
|
|
|
|
|
|
if not validated_config.privateGroupChatEnabled: |
|
|
|
logger.warning(f"微信号 {wxid} 关闭好友和群自动回复功能,{handle_text_async.__name__} 不回复消息") |
|
|
|
return |
|
|
|
|
|
|
|
# 判断是否转人工处理功能 |
|
|
|
is_human_handle_msg= await request.app.state.gewe_service.is_human_handle_msg_with_contact_wxid_async(wxid,from_wxid) |
|
|
|
if is_human_handle_msg: |
|
|
|
logger.warning(f'微信号 {wxid} 发送到微信号{to_wxid} 暂时工人接管30分钟中') |
|
|
|
return |
|
|
|
is_human_handle_msg_with_contact_wxid_key=await request.app.state.gewe_service.is_human_handle_msg_with_contact_wxid_key_word_async(wxid,from_wxid) |
|
|
|
if is_human_handle_msg or is_human_handle_msg_with_contact_wxid_key: |
|
|
|
#logger.warning(f'微信号 {wxid} 发送到微信号{to_wxid} 暂时工人接管30分钟中') |
|
|
|
if is_human_handle_msg: |
|
|
|
logger.warning(f'微信号 {wxid} 之前收到手动发送内容到微信号 {to_wxid} 暂时工人接管30分钟中') |
|
|
|
|
|
|
|
|
|
|
|
if is_human_handle_msg_with_contact_wxid_key: |
|
|
|
logger.warning(f'微信号 {wxid} 的好友微信号 {to_wxid} 触发关键词, 暂时工人接管30分钟中') |
|
|
|
human_handle_expire_time=is_human_handle_msg or is_human_handle_msg_with_contact_wxid_key |
|
|
|
|
|
|
|
msg_content=msg_data["Content"]["string"] |
|
|
|
expire_time=int(human_handle_expire_time)-int(time.time()) |
|
|
|
await request.app.state.gewe_service.set_human_handle_msg_last_msg_content(wxid,from_wxid,msg_content,expire_time) |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if wxid == from_wxid: #手动发送消息 |
|
|
|
logger.info(f"{wxid} 手动发送消息") |
|
|
|
|
|
|
|
await request.app.state.gewe_service.save_contacts_brief_to_cache_async(token_id,app_id,wxid,[to_wxid]) |
|
|
|
callback_to_user=msg_data["ToUserName"]["string"] |
|
|
|
human_handle_msg_last_msg_content=await request.app.state.gewe_service.get_human_handle_msg_last_msg_content(wxid,from_wxid) |
|
|
|
# 恢复 AI 回答 |
|
|
|
if '#AI' in msg_content and human_handle_msg_last_msg_content: |
|
|
|
# 删除标记缓存 |
|
|
|
await request.app.state.gewe_service.del_human_handle_msg_with_contact_wxid_async(wxid,to_wxid) |
|
|
|
await request.app.state.gewe_service.del_human_handle_msg_with_contact_wxid_key_word_async(wxid,to_wxid) |
|
|
|
await request.app.state.gewe_service.del_human_handle_msg_last_msg_content_async(wxid,to_wxid) |
|
|
|
|
|
|
|
await ai_chat_text_async(request,token_id, app_id, wxid, msg_data, msg_content) |
|
|
|
return |
|
|
|
# 转人工处理功能 |
|
|
|
await request.app.state.gewe_service.set_human_handle_msg_with_contact_wxid_async(wxid,to_wxid,60*30) |
|
|
|
else: |
|
|
|
await request.app.state.gewe_service.set_human_handle_msg_with_contact_wxid_async(wxid,to_wxid,60*30) |
|
|
|
|
|
|
|
# 推送到kafka |
|
|
|
input_wx_content_dialogue_message=[{"type": "text", "text": msg_content}] |
|
|
@@ -456,7 +480,6 @@ async def handle_text_async(request: Request,token_id,app_id, wxid,msg_data,from |
|
|
|
is_human_handle_msg_with_contact_wxid= await request.app.state.gewe_service.is_human_handle_msg_with_contact_wxid_key_word_async(wxid,callback_to_user) |
|
|
|
if is_human_handle_msg_with_contact_wxid: |
|
|
|
logger.warning(f'微信号 {wxid} 与 {callback_to_user} 有关键字匹配,暂时工人接管30分钟中,请查看长服AI商机提醒助理') |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
request.app.state.message_lock[app_id]= asyncio.Lock() |
|
|
|