from fastapi import APIRouter,Request from pydantic import BaseModel from fastapi import APIRouter, Depends from pydantic import BaseModel, ValidationError from model.models import AgentConfig,validate_wxid,auth_required_time import threading import asyncio groups_router = APIRouter(prefix="/api/groups") class GetChatroomInfoRequest(BaseModel): wxid: str class GetChatroomMenberListRequest(BaseModel): wxid: str chatroomId:str @groups_router.post("/getchatroominfo",response_model=None) async def get_chatroominfo(request: Request, body: GetChatroomInfoRequest): wxid = body.wxid groups= await request.app.state.gewe_service.get_groups_info_from_cache_async(wxid) return groups @groups_router.post("/getmenberlist",response_model=None) async def get_menberlist(request: Request, body: GetChatroomMenberListRequest): wxid = body.wxid chatroom_id=body.chatroomId _,loginfo=await request.app.state.gewe_service.get_login_info_by_wxid_async(wxid) token_id=loginfo.get('tokenId') app_id=loginfo.get('appId') ret, msg, data = await request.app.state.gewe_service.get_group_memberlist_async(token_id, app_id, chatroom_id) if ret != 200: return { 'code': ret, 'message': msg } loop = asyncio.get_event_loop() future = asyncio.run_coroutine_threadsafe( request.app.state.gewe_service.save_groups_members_to_cache_async(token_id, app_id, wxid, [chatroom_id]), loop ) # Optionally, you can wait for the future to complete if needed #future.result() return data