from __future__ import annotations import logging import httpx from yuxi.channel.extensions.line.types import LineBotProfile logger = logging.getLogger(__name__) class LineStatusAdapter: async def probe(self, account: dict | None = None) -> bool: if not account: return False token = account.get("channel_access_token", "") if not token: return False try: async with httpx.AsyncClient(timeout=httpx.Timeout(5.0)) as client: resp = await client.get( "https://api.line.me/v2/bot/info", headers={"Authorization": f"Bearer {token}"}, ) if resp.status_code == 200: data = resp.json() return bool(data.get("userId")) logger.warning("LINE probe failed: status=%s", resp.status_code) return False except Exception as e: logger.warning("LINE probe error: %s", e) return False def build_summary(self, snapshot: object) -> dict: account = getattr(snapshot, "account", {}) return { "channel": "line", "mode": "webhook", "account_id": account.get("account_id", "") if isinstance(account, dict) else "", } def resolve_account_state( self, account: dict, config: dict, configured: bool, enabled: bool ) -> str: if not configured: return "unconfigured" if not enabled: return "disabled" return "ok"