import os from yuxi.channel.extensions.webex.types import WebexAccount class WebexConfigAdapter: def list_account_ids(self, config: dict | None = None) -> list[str]: return ["default"] async def resolve_account(self, account_id: str, snapshot=None) -> WebexAccount: token = os.environ.get("WEBEX_BOT_TOKEN", "") secret = os.environ.get("WEBEX_WEBHOOK_SECRET", "") port_str = os.environ.get("WEBEX_WEBHOOK_PORT", "") port = int(port_str) if port_str else 8086 host = os.environ.get("WEBEX_WEBHOOK_HOST", "0.0.0.0") dm_policy = "open" space_policy = "at_mention" allow_from: list[str] = [] if snapshot and hasattr(snapshot, "config"): channel_cfg = snapshot.config.get("channels", {}).get("webex", {}) or {} accounts = channel_cfg.get("accounts", {}) or {} raw = accounts.get(account_id, accounts.get("default", channel_cfg)) token = raw.get("bot_access_token", "") or token secret = raw.get("webhook_secret", "") or secret port = raw.get("webhook_port", port) host = raw.get("webhook_host", host) dm_policy = raw.get("dm_policy", dm_policy) space_policy = raw.get("space_policy", space_policy) allow_from = raw.get("allow_from", allow_from) or [] return WebexAccount( account_id=account_id, bot_access_token=token, webhook_secret=secret, webhook_host=host, webhook_port=port, dm_policy=dm_policy, space_policy=space_policy, allow_from=allow_from, ) def is_configured(self, account: dict | None = None) -> bool: if account and isinstance(account, dict): return bool(account.get("bot_access_token", "")) return bool(os.environ.get("WEBEX_BOT_TOKEN", "")) def is_enabled(self, account: dict | None = None) -> bool: return True def disabled_reason(self, account: dict | None = None) -> str: return ""