ForcePilot/backend/package/yuxi/channel/extensions/pinduoduo/format.py
Kris 1476e82ef0 feat(channel): 添加拼多多渠道扩展
新增拼多多(Pinduoduo)渠道扩展,支持在 Yuxi 平台中集成拼多多电商客服渠道。

包含以下功能模块:
- client: 拼多多 API 客户端封装
- config: 渠道配置管理
- gateway: SSE/WebSocket 网关接入
- webhook: Webhook 事件处理
- outbound: 外发消息管理
- pairing: 用户配对与绑定
- security: 安全校验
- signature: 请求签名验证
- token: Token 管理
- dedupe: 消息去重
- monitor: 渠道状态监控
- status: 会话状态管理
- tools: Agent 工具集成
- window: 窗口管理
- types: 类型定义
2026-05-21 11:33:31 +08:00

44 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import re
MAX_TEXT_LENGTH = 2000
def pdd_truncate_text(content: str, max_length: int = MAX_TEXT_LENGTH) -> str:
if len(content) <= max_length:
return content
return content[: max_length - 3] + "..."
def pdd_split_long_text(content: str, max_length: int = MAX_TEXT_LENGTH) -> list[str]:
chunks = []
remaining = content
while remaining:
if len(remaining) <= max_length:
chunks.append(remaining)
break
split_at = max_length
for punct in ("\n", "", "", "", "", ".", "!", "?", ";"):
pos = remaining[:max_length].rfind(punct)
if pos > max_length // 2:
split_at = pos + 1
break
chunks.append(remaining[:split_at])
remaining = remaining[split_at:]
return chunks
def pdd_strip_markdown(content: str) -> str:
content = re.sub(r"\[([^\]]+)\]\([^)]+\)", r"\1", content)
content = re.sub(r"\*\*([^*]+)\*\*", r"\1", content)
content = re.sub(r"\*([^*]+)\*", r"\1", content)
content = re.sub(r"`([^`]+)`", r"\1", content)
content = re.sub(r"^#{1,6}\s+", "", content, flags=re.MULTILINE)
content = re.sub(r"^\s*[-*+]\s+", "", content, flags=re.MULTILINE)
content = re.sub(r"^\s*\d+\.\s+", "", content, flags=re.MULTILINE)
content = re.sub(r"\n{3,}", "\n\n", content)
return content.strip()
def pdd_format_order_card(order_sn: str) -> str:
return f"📦 订单编号: {order_sn}\n点击查看详情"