ForcePilot/backend/package/yuxi/channel/interfaces/rest/router/sse.py
Kris 9a8a27bf36 feat(channel): 新增渠道网关模块完整实现
本次提交新增了完整的多渠道消息网关系统,包括:
1. 支持飞书、钉钉、Web、Hook 四种渠道的适配器与配置
2. 领域模型层:消息、会话、绑定、出箱等核心实体
3. 应用服务层:管道、中间件、DTO 与业务逻辑
4. 基础设施层:持久化、过滤器、队列等端口实现
5. 接口层:REST API、SSE、WebSocket 通信端点
6. 前端页面与路由配置,添加渠道管理菜单
7. 新增相关依赖包与 docker-compose 部署配置
2026-05-30 21:53:09 +08:00

36 lines
1012 B
Python

from __future__ import annotations
import logging
import re
from fastapi import APIRouter, Depends, Query, Request
from yuxi.channel.container import ChannelContainer, get_channel
from yuxi.channel.interfaces.rest.auth.depends import channel_auth_depends
logger = logging.getLogger(__name__)
router = APIRouter()
_SESSION_ID_PATTERN = re.compile(r"^[a-zA-Z0-9\-_]{1,128}$")
@router.get("/channel/sse")
async def subscribe_sse(
request: Request,
session_id: str = Query(..., min_length=1),
channel: ChannelContainer = Depends(get_channel),
_: bool = Depends(channel_auth_depends),
):
if not _SESSION_ID_PATTERN.match(session_id):
from fastapi import HTTPException
raise HTTPException(status_code=400, detail="invalid session_id format")
if not channel.sse_endpoint:
from fastapi import HTTPException
raise HTTPException(status_code=503, detail="sse endpoint not initialized")
return await channel.sse_endpoint.subscribe(session_id, request)