新增 Google Chat 对接的全套工具模块,包括: - 会话线程管理、消息解析与格式化 - Pub/Sub 消息解码、提及和命令识别 - 权限审批、目录管理和审计日志 - 消息缓存、媒体上传下载和 SSFR 防护 - 策略配置、卡片构建和流式回复支持
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
def list_peers(allow_from: list[str]) -> list[dict[str, Any]]:
|
|
peers: list[dict[str, Any]] = []
|
|
for entry in allow_from:
|
|
if entry == "*":
|
|
continue
|
|
normalized = normalize_id(entry)
|
|
peers.append({"id": normalized, "raw": entry, "type": "user"})
|
|
return peers
|
|
|
|
|
|
def list_groups(groups_config: dict[str, Any]) -> list[dict[str, Any]]:
|
|
groups: list[dict[str, Any]] = []
|
|
for space_name, cfg in groups_config.items():
|
|
if not isinstance(cfg, dict):
|
|
continue
|
|
groups.append(
|
|
{
|
|
"id": space_name,
|
|
"type": "space",
|
|
"name": cfg.get("name", space_name),
|
|
"enabled": cfg.get("enabled", True),
|
|
"requires_mention": cfg.get("require_mention", cfg.get("requireMention", False)),
|
|
}
|
|
)
|
|
return groups
|
|
|
|
|
|
def normalize_id(raw: str) -> str:
|
|
if not raw:
|
|
return ""
|
|
raw = raw.strip()
|
|
if raw.startswith("spaces/"):
|
|
return raw
|
|
if raw.startswith("users/"):
|
|
return raw
|
|
if raw.startswith("user:"):
|
|
return raw.replace("user:", "users/", 1)
|
|
if "@" in raw:
|
|
return f"users/{raw}"
|
|
return f"users/{raw}"
|