新增京东(JD)渠道扩展,支持在 Yuxi 平台中集成京东客服渠道。 包含以下功能模块: - client: 京东 API 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - pairing: 用户配对与绑定 - security: 安全校验 - signature: 请求签名验证 - crypto: 加解密处理 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - session: 会话管理 - business: 业务逻辑处理 - types: 类型定义
20 lines
625 B
Python
20 lines
625 B
Python
import re
|
|
|
|
from yuxi.channel.extensions.jd.types import JD_TEXT_MAX_LENGTH
|
|
|
|
|
|
def remove_markdown(text: str) -> str:
|
|
text = re.sub(r"\*\*(.+?)\*\*", r"\1", text)
|
|
text = re.sub(r"\*(.+?)\*", r"\1", text)
|
|
text = re.sub(r"`(.+?)`", r"\1", text)
|
|
text = re.sub(r"\[(.+?)\]\(.+?\)", r"\1", text)
|
|
text = re.sub(r"^\s*[-*+]\s+", "• ", text, flags=re.MULTILINE)
|
|
text = re.sub(r"^\s*\d+\.\s+", "", text, flags=re.MULTILINE)
|
|
return text.strip()
|
|
|
|
|
|
def truncate(text: str, max_chars: int = JD_TEXT_MAX_LENGTH) -> str:
|
|
if len(text) > max_chars:
|
|
return text[: max_chars - 3] + "..."
|
|
return text
|