新增快手(Kuaishou)渠道扩展,支持在 Yuxi 平台中集成快手客服渠道。 包含以下功能模块: - api: 快手 API 客户端封装 - accounts: 账户管理 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - streaming: 流式消息处理 - pairing: 用户配对与绑定 - security: 安全校验 - signature: 请求签名验证 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - media: 媒体资源处理 - types: 类型定义
30 lines
860 B
Python
30 lines
860 B
Python
from __future__ import annotations
|
|
|
|
import time
|
|
from collections import OrderedDict
|
|
|
|
|
|
class KuaishouDedupeStore:
|
|
def __init__(self, max_size: int = 10000, ttl_seconds: int = 3600):
|
|
self._store: OrderedDict[str, float] = OrderedDict()
|
|
self._max_size = max_size
|
|
self._ttl = ttl_seconds
|
|
|
|
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_overflow()
|
|
return False
|
|
|
|
def _evict_expired(self):
|
|
now = time.time()
|
|
expired = [k for k, v in self._store.items() if now - v > self._ttl]
|
|
for k in expired:
|
|
del self._store[k]
|
|
|
|
def _evict_overflow(self):
|
|
while len(self._store) > self._max_size:
|
|
self._store.popitem(last=False)
|