diff --git a/app/endpoints/pipeline_endpoint.py b/app/endpoints/pipeline_endpoint.py index a2b7a2a..808ca10 100644 --- a/app/endpoints/pipeline_endpoint.py +++ b/app/endpoints/pipeline_endpoint.py @@ -911,8 +911,45 @@ async def handle_voice_async(request: Request,token_id,app_id, wxid,msg_data,fro logger.info((f'{wxid} 向 {callback_to_user} 发送文本【{ai_res_content}】{ret_msg}')) else: - logger.info(f"回复内容包含网址,不发送语音,回复文字内容:{ai_res_content}") - ret,ret_msg,res=await request.app.state.gewe_service.post_text_async(token_id,app_id,callback_to_user,ai_res_content) + # logger.info(f"回复内容包含网址,不发送语音,回复文字内容:{ai_res_content}") + # ret,ret_msg,res=await request.app.state.gewe_service.post_text_async(token_id,app_id,callback_to_user,ai_res_content) + + reply_content=ai_res_content + # 判断图片url + img_urls,reply_content=extract_and_replace_image_urls(reply_content) + if img_urls: + #await request.app.state.gewe_service.post_text_async(token_id, app_id, callback_to_user, reply_content) + async with message_lock: + await ai_post_text_split_async_async(request, token_id, app_id, callback_to_user, reply_content) + await asyncio.sleep(random.uniform(1.5, 3)) + for img_url in img_urls: + await request.app.state.gewe_service.post_image_async(token_id, app_id, callback_to_user, img_url) + await asyncio.sleep(random.uniform(1.5, 3)) + + # 判断视频url + video_urls,reply_content=extract_and_replace_video_urls(reply_content) + if video_urls: + #await request.app.state.gewe_service.post_text_async(token_id, app_id, callback_to_user, reply_content) + async with message_lock: + await ai_post_text_split_async_async(request, token_id, app_id, callback_to_user, reply_content) + await asyncio.sleep(random.uniform(1.5, 3)) + for video_url in video_urls: + parsed_url = urlparse(video_url) + filename = os.path.basename(parsed_url.path) + tmp_file_path = os.path.join(os.getcwd(),'tmp', filename) # 拼接完整路径 + thumbnail_path=tmp_file_path.replace('.mp4','.jpg') + + video_thumb_url,video_duration =download_video_and_get_thumbnail(video_url,thumbnail_path) + logger.info(f'{wxid} 视频缩略图 {video_thumb_url} 时长 {video_duration}') + ret,ret_msg,res = await request.app.state.gewe_service.post_video_async(token_id, app_id, callback_to_user, video_url,video_thumb_url,video_duration) + if ret!=200: + logger.warning(f'{wxid} 发送视频{video_url} 到 {callback_to_user} 失败,{ret_msg}') + await asyncio.sleep(random.uniform(1.5, 3)) + # 发送AI微信回复 + #await request.app.state.gewe_service.post_text_async(token_id, app_id, callback_to_user, reply_content) + if (not video_urls) and (not img_urls): + async with message_lock: + await ai_post_text_split_async_async(request, token_id, app_id, callback_to_user, reply_content) diff --git a/tasks.py b/tasks.py index 75b9ff7..29c31a8 100644 --- a/tasks.py +++ b/tasks.py @@ -714,7 +714,7 @@ def scheduled_task_add_contacts_from_chatrooms(self, redis_config, kafka_config, if ret != 200: logger.warning(f'{nickname}-{wxid} 在 {chatroom_nickname}-{chatroom_id} 群好友 {member_nickname}-{contact_wxid} 邀请失败原因:{ret} {msg} {data}') - if not data and '操作过于频繁' in data.get('msg', ''): + if data and '操作过于频繁' in data.get('msg', ''): await gewe_service.save_wx_expection_async(wxid, "addGroupMemberAsFriend", msg, today_seconds_remaining()) await gewe_service.save_group_add_contacts_history_async(wxid, chatroom_id, contact_wxid, history) logger.warning(f'{nickname}-{wxid} 在 {chatroom_nickname}-{chatroom_id} 群的 {member_nickname}-{contact_wxid} 操作过于频繁,本次群好友邀请任务未完成跳过。当天不再处理该号群好友邀请任务')