瀏覽代碼

群聊视频处理

develop
H Vs 2 天之前
父節點
當前提交
a1e4831cc2
共有 1 個檔案被更改,包括 29 行新增0 行删除
  1. +29
    -0
      app/endpoints/pipeline_endpoint.py

+ 29
- 0
app/endpoints/pipeline_endpoint.py 查看文件

@@ -207,6 +207,7 @@ async def handle_add_messages_async(request: Request,token_id,msg,wxid):
handlers[1]=handle_text_group_async
handlers[3]=handle_image_group_async
handlers[34]=handle_voice_group_async
handlers[43]=handle_video_group_async

handler = handlers.get(msg_type)

@@ -1038,7 +1039,35 @@ async def handle_video_async(request: Request,token_id,app_id, wxid,msg_data,fro
except Exception as e:
logger.error(f"出现错误: {e}")

async def handle_video_group_async(request: Request,token_id,app_id, wxid,msg_data,from_wxid, to_wxid):
logger.info('群聊视频消息')
try:
msg_content=msg_data["Content"]["string"]
xml_match = re.search(r'<\?xml.*</msg>', msg_content, re.DOTALL)
if not xml_match:
logger.info(f'找不到视频地址')
return
msg_content_xml=xml_match.group(0)
wx_video_url=await request.app.state.gewe_service.download_video_msg_async(token_id,app_id,msg_content_xml)
if not wx_video_url:
logger.warning(f'处理微信视频消息异常')
return
callback_to_user=from_wxid
print(wx_video_url)

file_url=url_file_to_oss(wx_video_url)
if not file_url:
logger.warning(f'处理微信视频上传到oss异常')
return
reply_content = re.sub(r'<\?xml.*', f'{file_url}', msg_content, flags=re.DOTALL)
input_wx_content_dialogue_message=[{"type": "text", "text": reply_content}]
k_message=dialogue_message(callback_to_user,wxid,input_wx_content_dialogue_message,False)
await request.app.state.kafka_service.send_message_async(k_message)
logger.info("发送对话 %s",k_message)
except Exception as e:
logger.error(f"出现错误: {e}")

async def handle_xml_async(request: Request,token_id,app_id, wxid,msg_data,from_wxid, to_wxid):
'''


Loading…
取消
儲存