add: resolve agent for user, check agent health

This commit is contained in:
dantoom 2026-05-26 15:20:58 +03:00
parent b74277a189
commit e50bb8fae5
2 changed files with 25 additions and 0 deletions

View file

@ -81,6 +81,7 @@ class RoutedMaxPlatformClient(PlatformClient):
self._store = chat_store
self._delegates = dict(delegates)
self._default_client = default_client
self.agent_healthy = True
async def get_or_create_user(
self, external_id: str, platform: str, display_name: str | None = None
@ -89,6 +90,14 @@ class RoutedMaxPlatformClient(PlatformClient):
external_id=external_id, platform=platform, display_name=display_name
)
async def _check_agent_health(self):
try:
async with httpx.AsyncClient() as client:
resp = await client.get(f"{self.agent_base_url}/health", timeout=2.0)
self.agent_healthy = resp.status_code == 200
except Exception:
self.agent_healthy = False
async def send_message(self, user_id: str, chat_id: str, text: str, attachments=None):
delegate, platform_chat_id = await self._resolve_delegate(user_id, chat_id)
return await delegate.send_message(user_id, platform_chat_id, text, attachments)