实现了 Teams 机器人所需的全功能组件,包括: - 基础命令解析与帮助卡片生成 - 租户验证与访问控制 - 自定义 UA 与媒体工具 - 消息分块、批注处理与会话管理 - 防抖、缓存与配置路由能力 - 投票、配对、审计与运行时状态管理 - TTS 语音合成与卡片构建工具 - 群组管理与权限控制逻辑
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
"""Microsoft Teams 会话路由辅助。
|
|
|
|
提供 conversation_id 解析、chat_type 判断和 thread_id 生成规则。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
def determine_chat_type(conversation_type: str) -> str:
|
|
mapping = {
|
|
"personal": "direct",
|
|
"channel": "group",
|
|
"groupChat": "group",
|
|
}
|
|
return mapping.get(conversation_type, "direct")
|
|
|
|
|
|
def resolve_channel_chat_id(
|
|
conversation_type: str,
|
|
conversation_id: str,
|
|
aad_object_id: str = "",
|
|
channel_data: dict | None = None,
|
|
) -> str:
|
|
if conversation_type == "personal":
|
|
return f"personal_{aad_object_id}" if aad_object_id else conversation_id
|
|
if conversation_type == "channel":
|
|
channel_id = ""
|
|
if channel_data:
|
|
channel_id = (channel_data.get("channel") or {}).get("id", "")
|
|
return f"channel_{channel_id}" if channel_id else conversation_id
|
|
if conversation_type == "groupChat":
|
|
return f"group_{conversation_id}"
|
|
return conversation_id
|
|
|
|
|
|
def resolve_thread_id(
|
|
agent_id: str,
|
|
conversation_type: str,
|
|
aad_object_id: str = "",
|
|
channel_data: dict | None = None,
|
|
reply_to_id: str = "",
|
|
) -> str:
|
|
if conversation_type == "personal" and aad_object_id:
|
|
base = f"agent:{agent_id}:msteams:personal:{aad_object_id}"
|
|
elif conversation_type == "channel":
|
|
channel_id = ""
|
|
if channel_data:
|
|
channel_id = (channel_data.get("channel") or {}).get("id", "")
|
|
base = f"agent:{agent_id}:msteams:channel:{channel_id}"
|
|
elif conversation_type == "groupChat":
|
|
base = f"agent:{agent_id}:msteams:group:{aad_object_id or 'unknown'}"
|
|
else:
|
|
base = f"agent:{agent_id}:msteams:unknown"
|
|
|
|
if reply_to_id and conversation_type != "personal":
|
|
return f"{base}:thread:{reply_to_id}"
|
|
return base
|