新增拼多多(Pinduoduo)渠道扩展,支持在 Yuxi 平台中集成拼多多电商客服渠道。 包含以下功能模块: - client: 拼多多 API 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - pairing: 用户配对与绑定 - security: 安全校验 - signature: 请求签名验证 - token: Token 管理 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - tools: Agent 工具集成 - window: 窗口管理 - types: 类型定义
47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
import logging
|
|
import time
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
_WINDOW_SECONDS = 48 * 3600
|
|
|
|
|
|
class PinduoduoWindowTracker:
|
|
|
|
def __init__(self):
|
|
self._last_msg_time: dict[str, float] = {}
|
|
|
|
def record(self, buyer_id: str) -> None:
|
|
self._last_msg_time[buyer_id] = time.time()
|
|
|
|
def can_reply(self, buyer_id: str) -> bool:
|
|
last = self._last_msg_time.get(buyer_id, 0)
|
|
now = time.time()
|
|
if now - last > _WINDOW_SECONDS:
|
|
logger.info(
|
|
"拼多多 48h 互动窗口已过期,用户 %s,最后消息时间戳=%s",
|
|
buyer_id,
|
|
last,
|
|
)
|
|
return False
|
|
|
|
return True
|
|
|
|
def remaining_seconds(self, buyer_id: str) -> float:
|
|
last = self._last_msg_time.get(buyer_id, 0)
|
|
if last == 0:
|
|
return 0
|
|
elapsed = time.time() - last
|
|
remaining = _WINDOW_SECONDS - elapsed
|
|
return max(0.0, remaining)
|
|
|
|
def cleanup(self) -> None:
|
|
now = time.time()
|
|
expired = [
|
|
k for k, ts in self._last_msg_time.items()
|
|
if now - ts > _WINDOW_SECONDS
|
|
]
|
|
for k in expired:
|
|
del self._last_msg_time[k]
|