新增 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: 类型定义
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from yuxi.channel.extensions.mattermost.client import MattermostClient
|
|
from yuxi.channel.extensions.mattermost.errors import MattermostError
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class MattermostReactionsAdapter:
|
|
def __init__(self, client: MattermostClient, bot_user_id: str = ""):
|
|
self.client = client
|
|
self.bot_user_id = bot_user_id
|
|
|
|
async def add_reaction(self, post_id: str, emoji_name: str) -> bool:
|
|
try:
|
|
await self.client.add_reaction(self.bot_user_id, post_id, emoji_name)
|
|
return True
|
|
except MattermostError as e:
|
|
logger.error("Failed to add reaction %s to post %s: %s", emoji_name, post_id, e)
|
|
return False
|
|
|
|
async def remove_reaction(self, post_id: str, emoji_name: str) -> bool:
|
|
try:
|
|
await self.client.remove_reaction(self.bot_user_id, post_id, emoji_name)
|
|
return True
|
|
except MattermostError as e:
|
|
logger.error("Failed to remove reaction %s from post %s: %s", emoji_name, post_id, e)
|
|
return False
|
|
|
|
EMOJI_STATUS = {
|
|
"processing": "hourglass_flowing_sand",
|
|
"success": "white_check_mark",
|
|
"error": "x",
|
|
"thinking": "thinking",
|
|
"typing": "pencil",
|
|
}
|
|
|
|
async def indicate_status(self, post_id: str, status: str) -> None:
|
|
emoji = self.EMOJI_STATUS.get(status)
|
|
if emoji:
|
|
await self.add_reaction(post_id, emoji)
|
|
|
|
async def clear_status(self, post_id: str, status: str) -> None:
|
|
emoji = self.EMOJI_STATUS.get(status)
|
|
if emoji:
|
|
await self.remove_reaction(post_id, emoji)
|