本次提交新增了完整的多渠道消息网关系统,包括: 1. 支持飞书、钉钉、Web、Hook 四种渠道的适配器与配置 2. 领域模型层:消息、会话、绑定、出箱等核心实体 3. 应用服务层:管道、中间件、DTO 与业务逻辑 4. 基础设施层:持久化、过滤器、队列等端口实现 5. 接口层:REST API、SSE、WebSocket 通信端点 6. 前端页面与路由配置,添加渠道管理菜单 7. 新增相关依赖包与 docker-compose 部署配置
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
from yuxi.channel.channels.hooks.config import HookMapping
|
|
from yuxi.channel.domain.model.message.peer import Peer
|
|
from yuxi.channel.domain.model.message.unified_message import UnifiedMessage
|
|
from yuxi.channel.domain.model.shared.channel_type import ChannelType
|
|
|
|
|
|
class HooksTranslator:
|
|
@staticmethod
|
|
def translate(raw: dict, mapping: HookMapping) -> UnifiedMessage:
|
|
agent_id = raw.get("agent_id", mapping.default_agent_id)
|
|
if not mapping.allowed_agent_ids or agent_id not in mapping.allowed_agent_ids:
|
|
agent_id = mapping.default_agent_id
|
|
|
|
session_key = mapping.default_session_key
|
|
if mapping.allow_request_session_key:
|
|
req_key = raw.get("session_key", "")
|
|
if req_key:
|
|
if not mapping.allowed_session_key_prefixes or any(
|
|
req_key.startswith(p) for p in mapping.allowed_session_key_prefixes
|
|
):
|
|
session_key = req_key
|
|
|
|
strategy = mapping.session_key_strategy
|
|
|
|
return UnifiedMessage(
|
|
message_id=raw.get("id", ""),
|
|
channel_type=ChannelType.HOOKS,
|
|
sender=Peer(id="hooks", name="Hooks", kind="system"),
|
|
content=raw.get("content", raw.get("text", "")),
|
|
metadata={
|
|
"source": "hooks",
|
|
"match_path": mapping.match_path,
|
|
"session_key_strategy": strategy,
|
|
"session_key": session_key,
|
|
"session_key_prefix": mapping.match_path,
|
|
"deliver": mapping.deliver,
|
|
},
|
|
agent_config_id=agent_id,
|
|
raw_payload=raw,
|
|
)
|