| | |
| | | from datetime import datetime |
| | | |
| | | import httpx |
| | | |
| | | from app.config.config import settings |
| | |
| | | if response.status_code != 200: |
| | | raise Exception(f"Failed to get public key: {response.text}") |
| | | return response.json().get('data', {}).get('public_key') |
| | | |
| | | async def get_chat_sessions(self, token: str) -> list: |
| | | url = f"{self.base_url}/api/v1/chat/list?page=1&limit=40" |
| | | headers = {'cookie': f"access_token_cookie={token};"} |
| | | async with httpx.AsyncClient() as client: |
| | | response = await client.get(url, headers=headers) |
| | | if response.status_code != 200: |
| | | raise Exception(f"Failed to fetch data from Bisheng API: {response.text}") |
| | | |
| | | data = response.json().get("data", []) |
| | | result = [ |
| | | { |
| | | "id": item["chat_id"], |
| | | "name": item["latest_message"]["message"], |
| | | "updated_time": int(datetime.strptime(item["update_time"], "%Y-%m-%dT%H:%M:%S").timestamp() * 1000) |
| | | } |
| | | for item in data |
| | | ] |
| | | return result |