ForcePilot/backend/package/yuxi/channel/extensions/ringcentral/formatting.py
Kris 7a9031ea53 feat(channel): 添加 RingCentral 渠道扩展
新增 RingCentral 渠道扩展,支持在 Yuxi 平台中集成 RingCentral 统一通信平台。

包含以下功能模块:
- sdk: RingCentral SDK 封装
- config: 渠道配置管理
- gateway: SSE/WebSocket 网关接入
- webhook: Webhook 事件处理
- subscription: 事件订阅
- outbound: 外发消息管理
- streaming: 流式消息处理
- pairing: 用户配对与绑定
- security: 安全校验
- dedupe: 消息去重
- monitor: 渠道状态监控
- status: 会话状态管理
- session: 会话管理
- events: 事件处理
- adaptive_cards: 自适应卡片
- formatting: 格式化
- media: 媒体资源处理
- mentions: @提及
- notes: 笔记功能
- reactions: 表情反应
- tasks: 任务管理
- teams: 团队管理
- types: 类型定义
2026-05-21 11:37:49 +08:00

35 lines
927 B
Python

from __future__ import annotations
import re
_CONTROL_CHAR_PATTERN = re.compile(r"[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]")
_MULTI_NEWLINE_PATTERN = re.compile(r"\n{3,}")
def sanitize_text(text: str) -> str:
cleaned = _CONTROL_CHAR_PATTERN.sub("", text)
cleaned = _MULTI_NEWLINE_PATTERN.sub("\n\n", cleaned)
return cleaned.strip()
def chunk_text(text: str, limit: int = 1000) -> list[str]:
if len(text) <= limit:
return [text]
chunks = []
remaining = text
while remaining:
if len(remaining) <= limit:
chunks.append(remaining)
break
split_at = remaining.rfind("\n", 0, limit)
if split_at == -1 or split_at < limit // 2:
split_at = remaining.rfind(" ", 0, limit)
if split_at == -1:
split_at = limit
chunks.append(remaining[:split_at])
remaining = remaining[split_at:].lstrip()
return chunks