"""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