ForcePilot/backend/package/yuxi/channel/extensions/googlechat/approval.py
Kris c4e301a5e0 feat(googlechat): 新增Google Chat渠道完整实现
新增Google Chat插件的所有核心功能模块,包括账户配置、消息收发、权限控制、媒体处理、会话管理等完整能力
2026-05-21 10:49:33 +08:00

36 lines
1.3 KiB
Python

from __future__ import annotations
import logging
logger = logging.getLogger(__name__)
class GoogleChatApprovalAuth:
channel_label = "Google Chat"
def resolve_approvers(self, cfg: dict, account_id: str) -> list[str]:
gc_config = cfg.get("channels", {}).get("googlechat", {}) if cfg else {}
allow_from = gc_config.get("dm", {}).get("allowFrom", [])
if not allow_from:
account_cfg = gc_config.get("accounts", {}).get(account_id, {})
allow_from = account_cfg.get("dm", {}).get("allowFrom", [])
else:
account_cfg = gc_config.get("accounts", {}).get(account_id, {})
account_allow_from = account_cfg.get("dm", {}).get("allowFrom", [])
if account_allow_from:
allow_from = account_allow_from
return [a for a in (self._normalize_approver_id(entry) for entry in allow_from) if a]
def _normalize_approver_id(self, value) -> str | None:
if not value:
return None
for prefix in ("googlechat:",):
if value.startswith(prefix):
value = value[len(prefix):]
if value.startswith("users/") and "@" in value:
return None
if value.startswith("users/"):
return value.lower()
return f"users/{value.lower()}"