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

46 lines
1.3 KiB
Python

from __future__ import annotations
def normalize_googlechat_target(raw: str) -> str | None:
if not raw:
return None
t = raw.strip()
for prefix in ("googlechat:", "google-chat:", "gchat:"):
if t.lower().startswith(prefix):
t = t[len(prefix):]
t = t.strip()
break
if t.lower().startswith("user:users/"):
t = t[5:]
elif t.lower().startswith("space:spaces/"):
t = t[6:]
if "@" in t and not t.startswith("users/") and not t.startswith("spaces/"):
t = f"users/{t.lower()}"
return t
def strip_message_suffix(target: str) -> str:
idx = target.find("/messages/")
return target[:idx] if idx != -1 else target
async def resolve_outbound_space(account, target: str) -> str | None:
from yuxi.channel.extensions.googlechat.api import find_direct_message
normalized = normalize_googlechat_target(target)
if not normalized:
return None
base = strip_message_suffix(normalized)
if base.startswith("spaces/"):
return base
if base.startswith("users/"):
return await find_direct_message(account, base)
return None
def is_space_target(target: str) -> bool:
return target.startswith("spaces/")
def is_user_target(target: str) -> bool:
return target.startswith("users/")