ForcePilot/backend/package/yuxi/channel/extensions/matrix/actions.py
Kris 4e9c6dd8ab feat(channel): 添加 Matrix 渠道扩展
新增 Matrix 渠道扩展,支持在 Yuxi 平台中集成 Matrix 去中心化通讯协议。

包含以下功能模块:
- config: 渠道配置管理
- gateway: SSE/WebSocket 网关接入
- outbound: 外发消息管理
- streaming: 流式消息处理
- pairing: 用户配对与绑定
- security: 安全校验
- crypto: 端到端加密
- dedupe: 消息去重
- monitor: 渠道状态监控
- status: 会话状态管理
- session: 会话管理
- room_resolver: 房间解析
- dm_tracker: 私聊追踪
- rate_limiter: 速率限制
- actions: 动作处理
- constants: 常量定义
- utils: 工具函数
- types: 类型定义
2026-05-21 11:18:13 +08:00

64 lines
1.5 KiB
Python

from __future__ import annotations
import logging
logger = logging.getLogger(__name__)
async def react(
outbound,
target_id: str,
message_id: str,
level: str,
account_id: str | None = None,
) -> None:
if level == "off":
return
emoji = _resolve_reaction_emoji(level)
if not emoji:
return
await outbound.send_reaction(target_id, message_id, emoji, account_id=account_id)
async def clear_reaction(
outbound,
target_id: str,
message_id: str,
account_id: str | None = None,
) -> None:
try:
await outbound.send_reaction(target_id, message_id, "", account_id=account_id)
except Exception:
logger.debug("Failed to clear reaction", exc_info=True)
async def send_typing(
outbound,
target_id: str,
thread_id: str | None = None,
account_id: str | None = None,
) -> None:
try:
await outbound.send_typing(target_id, True, account_id=account_id)
except Exception:
logger.debug("Failed to send typing indicator", exc_info=True)
def get_action_whitelist(account: dict) -> list[str]:
actions = ["send", "react", "edit", "delete"]
if not account.get("reactions", True):
actions.remove("react")
if not account.get("edit", True):
actions.remove("edit")
return actions
def _resolve_reaction_emoji(level: str) -> str | None:
emoji_map = {
"ack": "👀",
"minimal": "",
"error": "",
"thinking": "🤔",
}
return emoji_map.get(level)