新增 Google Chat 对接的全套工具模块,包括: - 会话线程管理、消息解析与格式化 - Pub/Sub 消息解码、提及和命令识别 - 权限审批、目录管理和审计日志 - 消息缓存、媒体上传下载和 SSFR 防护 - 策略配置、卡片构建和流式回复支持
26 lines
815 B
Python
26 lines
815 B
Python
from __future__ import annotations
|
|
|
|
from yuxi.channels.models import MentionsInfo
|
|
|
|
|
|
def parse_mentions(message: dict, bot_user: str = "") -> MentionsInfo:
|
|
annotations = message.get("annotations", [])
|
|
mentioned_ids = [
|
|
a.get("userMention", {}).get("user", {}).get("name", "") for a in annotations if a.get("type") == "USER_MENTION"
|
|
]
|
|
is_at_bot = False
|
|
for a in annotations:
|
|
if a.get("type") != "USER_MENTION":
|
|
continue
|
|
um = a.get("userMention", {})
|
|
if um.get("type") == "BOT":
|
|
is_at_bot = True
|
|
break
|
|
if bot_user and um.get("user", {}).get("name", "") == bot_user:
|
|
is_at_bot = True
|
|
break
|
|
return MentionsInfo(
|
|
mentioned_user_ids=mentioned_ids,
|
|
is_bot_mentioned=is_at_bot,
|
|
)
|