新增拼多多(Pinduoduo)渠道扩展,支持在 Yuxi 平台中集成拼多多电商客服渠道。 包含以下功能模块: - client: 拼多多 API 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - pairing: 用户配对与绑定 - security: 安全校验 - signature: 请求签名验证 - token: Token 管理 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - tools: Agent 工具集成 - window: 窗口管理 - types: 类型定义
36 lines
973 B
Python
36 lines
973 B
Python
from __future__ import annotations
|
|
|
|
import time
|
|
from collections import OrderedDict
|
|
|
|
MAX_ENTRIES = 10000
|
|
TTL_SECONDS = 300
|
|
|
|
|
|
class PddMessageDeduplicator:
|
|
def __init__(self, max_entries: int = MAX_ENTRIES, ttl: int = TTL_SECONDS):
|
|
self._store: OrderedDict[str, float] = OrderedDict()
|
|
self._max = max_entries
|
|
self._ttl = ttl
|
|
|
|
def is_duplicate(self, msg_id: str) -> bool:
|
|
self._evict_expired()
|
|
if msg_id in self._store:
|
|
return True
|
|
self._store[msg_id] = time.time()
|
|
self._evict_oldest()
|
|
return False
|
|
|
|
def _evict_expired(self) -> None:
|
|
now = time.time()
|
|
expired = [k for k, ts in self._store.items() if now - ts > self._ttl]
|
|
for k in expired:
|
|
self._store.pop(k, None)
|
|
|
|
def _evict_oldest(self) -> None:
|
|
while len(self._store) > self._max:
|
|
self._store.popitem(last=False)
|
|
|
|
def reset(self) -> None:
|
|
self._store.clear()
|