from __future__ import annotations import logging from yuxi.channel.extensions.ringcentral.types import ResolvedRingCentralAccount logger = logging.getLogger(__name__) class RingCentralStatusAdapter: async def probe(self, account_dict: dict) -> bool: account = account_dict.get("resolved") if not isinstance(account, ResolvedRingCentralAccount): return False from yuxi.channel.plugins.registry import ChannelPluginRegistry plugin = ChannelPluginRegistry.get("ringcentral") if not plugin or not hasattr(plugin, "_gateway"): return False client = plugin._gateway.get_client(account.account_id) if not client or not client.is_logged_in: return False try: await client.get("/restapi/v1.0/account/~/extension/~") return True except Exception: return False def build_summary(self, snapshot) -> dict: return { "channel": "ringcentral", "mode": "webhook", } def build_account_snapshot(self, account_dict: dict) -> dict: return { "account_id": account_dict.get("account_id", "default"), "name": account_dict.get("name", ""), "configured": bool(account_dict.get("client_id") and account_dict.get("jwt_token")), "enabled": account_dict.get("enabled", True), } def collect_status_issues(self, accounts: list[dict]) -> list[dict]: issues = [] for account in accounts: if not account: continue if not account.get("client_id"): issues.append( { "channel": "ringcentral", "account_id": account.get("account_id", "default"), "kind": "client_id_missing", "message": "client_id is not configured.", "fix": "Set channels.ringcentral.client_id.", } ) if not account.get("jwt_token"): issues.append( { "channel": "ringcentral", "account_id": account.get("account_id", "default"), "kind": "jwt_token_missing", "message": "jwt_token is not configured.", "fix": "Set channels.ringcentral.jwt_token.", } ) return issues