新增 Mattermost 渠道扩展,支持在 Yuxi 平台中集成 Mattermost 团队协作平台。 包含以下功能模块: - client: Mattermost API 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - websocket: WebSocket 实时连接 - outbound: 外发消息管理 - streaming: 流式消息处理 - pairing: 用户配对与绑定 - security: 安全校验 - dedup: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - session: 会话管理 - interactions: 交互处理 - slash_commands: 斜杠指令 - actions: 动作处理 - approval: 审批流程 - delivery: 消息送达确认 - directory: 目录管理 - threading: 线程管理 - gating: 门控管理 - reconnect: 重连机制 - reactions: 表情反应 - media: 媒体资源处理 - model_picker: 模型选择 - types: 类型定义
60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class MattermostSessionManager:
|
|
def build_session_key(
|
|
self,
|
|
account_id: str,
|
|
channel_type: str,
|
|
channel_id: str,
|
|
root_id: str | None = None,
|
|
) -> str:
|
|
parts = [account_id, channel_type, channel_id]
|
|
if root_id:
|
|
parts.append(f"thread:{root_id}")
|
|
return ":".join(parts)
|
|
|
|
def build_thread_session_key(
|
|
self,
|
|
account_id: str,
|
|
channel_id: str,
|
|
thread_root_id: str,
|
|
) -> str:
|
|
return f"{account_id}:thread:{channel_id}:thread:{thread_root_id}"
|
|
|
|
def extract_from_session_key(self, session_key: str) -> dict:
|
|
parts = session_key.split(":")
|
|
if len(parts) < 3:
|
|
return {"account_id": "", "channel_type": "", "channel_id": ""}
|
|
|
|
result = {
|
|
"account_id": parts[0],
|
|
"channel_type": parts[1],
|
|
"channel_id": parts[2],
|
|
"thread_id": None,
|
|
}
|
|
|
|
if len(parts) >= 5 and parts[3] == "thread":
|
|
result["thread_id"] = parts[4]
|
|
|
|
return result
|
|
|
|
def resolve_parent_session_key(
|
|
self,
|
|
session_key: str,
|
|
chat_type: str,
|
|
) -> str | None:
|
|
if chat_type == "direct":
|
|
return None
|
|
|
|
parts = session_key.split(":")
|
|
if len(parts) >= 5:
|
|
non_thread = ":".join(parts[:3])
|
|
return non_thread
|
|
|
|
return None
|