ForcePilot/backend/package/yuxi/channel/extensions/rocketchat/reactions.py
Kris 043e75d787 feat(channel): 添加 RocketChat 渠道扩展
新增 RocketChat 渠道扩展,支持在 Yuxi 平台中集成 RocketChat 团队协作平台。

包含以下功能模块:
- client: RocketChat API 客户端封装
- config: 渠道配置管理
- gateway: SSE/WebSocket 网关接入
- websocket: WebSocket 实时连接
- webhook: Webhook 事件处理
- outbound: 外发消息管理
- streaming: 流式消息处理
- pairing: 用户配对与绑定
- security: 安全校验
- dedup: 消息去重
- monitor: 渠道状态监控
- status: 会话状态管理
- session: 会话管理
- gating: 门控管理
- threading: 线程管理
- reactions: 表情反应
- types: 类型定义
2026-05-21 11:39:24 +08:00

38 lines
1.2 KiB
Python

from __future__ import annotations
import logging
from yuxi.channel.extensions.rocketchat.client import RocketChatClient
from yuxi.channel.extensions.rocketchat.errors import RocketChatError
logger = logging.getLogger(__name__)
class RocketChatReactionsAdapter:
def __init__(self, client: RocketChatClient, account_id: str = ""):
self.client = client
self.account_id = account_id
async def add_reaction(self, msg_id: str, emoji: str) -> dict | None:
try:
return await self.client.add_reaction(msg_id, emoji)
except RocketChatError as e:
logger.error("Failed to add reaction %s to %s: %s", emoji, msg_id, e)
return None
async def remove_reaction(self, msg_id: str, emoji: str) -> bool:
# The Rocket.Chat react API is a toggle; calling with the same emoji removes the reaction.
try:
await self.client.add_reaction(msg_id, emoji)
return True
except RocketChatError:
return False
def parse_emoji(self, raw: str) -> str:
emoji = raw.strip()
if not emoji.startswith(":"):
emoji = f":{emoji}"
if not emoji.endswith(":"):
emoji = f"{emoji}:"
return emoji