ForcePilot/backend/package/yuxi/channels/protocols/outbound.py
Kris 7a972055b7 feat: 新增渠道服务基础框架与核心工具类
新增大量渠道适配器相关的协议、策略、工具类与基础设施代码,包括:
1.  多协议定义:认证、消息、配置、网关等核心接口
2.  策略模块:上下文、群聊、去重、防抖等业务策略
3.  工具集:重试、去重、文本分块、消息格式化等SDK工具
4.  基础设施:外部进程管理、事件广播、熔断机制等
5.  账户与管道系统:账户管理、消息处理管道实现
6.  运行时服务:状态收集、维护任务、日志等后台服务
2026-05-12 00:53:57 +08:00

50 lines
1.5 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING, Any, Protocol, runtime_checkable
if TYPE_CHECKING:
from yuxi.channels.models import ChannelResponse, DeliveryResult
class OutboundContext:
chat_id: str
content: str
media_url: str | None = None
reply_to_id: str | None = None
@runtime_checkable
class ChannelOutboundProtocol(Protocol):
async def send(self, response: ChannelResponse) -> DeliveryResult: ...
async def send_media(self, chat_id: str, media_type: str, data: Any) -> DeliveryResult: ...
async def edit_message(self, chat_id: str, msg_id: str, content: str) -> DeliveryResult: ...
async def delete_message(self, chat_id: str, msg_id: str) -> DeliveryResult: ...
async def send_reaction(self, chat_id: str, msg_id: str, emoji: str) -> DeliveryResult: ...
def chunker(self, text: str, limit: int) -> list[str]: ...
@property
def chunker_mode(self) -> str: ...
@property
def text_chunk_limit(self) -> int: ...
@property
def delivery_mode(self) -> str: ...
def sanitize_text(self, text: str) -> str: ...
async def send_text(self, ctx: OutboundContext) -> DeliveryResult: ...
async def send_media_url(self, ctx: OutboundContext) -> DeliveryResult: ...
async def send_poll(self, ctx: OutboundContext) -> DeliveryResult: ...
async def pin_message(self, chat_id: str, msg_id: str) -> DeliveryResult: ...
async def unpin_message(self, chat_id: str, msg_id: str) -> DeliveryResult: ...