新增 Zalo OA、Zoom Chat、Zulip 三个渠道扩展。 Zalo OA 渠道扩展主要模块:sidecar_client, config, gateway, outbound, streaming, pairing, security, auth, dedupe, directory, monitor, status, session, reactions, tools Zoom Chat 渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, crypto, dedupe, actions, media, mentions, monitor, status, session, reactions, threading Zulip 渠道扩展主要模块:client, config, gateway, outbound, streaming, pairing, security, monitor, status
35 lines
987 B
Python
35 lines
987 B
Python
from collections import OrderedDict
|
|
import time
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
DEDUPE_TTL_SECONDS = 3600
|
|
DEDUPE_MAX_ENTRIES = 1000
|
|
|
|
|
|
class ZoomMessageDeduplicator:
|
|
def __init__(self, ttl: int = DEDUPE_TTL_SECONDS, max_entries: int = DEDUPE_MAX_ENTRIES):
|
|
self._ttl = ttl
|
|
self._max = max_entries
|
|
self._seen: OrderedDict[str, float] = OrderedDict()
|
|
|
|
def is_duplicate(self, event_ts: int, message_id: str) -> bool:
|
|
key = f"{event_ts}:{message_id}"
|
|
self._cleanup()
|
|
|
|
if key in self._seen:
|
|
logger.debug("Zoom webhook duplicate event: %s", key)
|
|
return True
|
|
|
|
self._seen[key] = time.time()
|
|
while len(self._seen) > self._max:
|
|
self._seen.popitem(last=False)
|
|
return False
|
|
|
|
def _cleanup(self):
|
|
now = time.time()
|
|
expired = [k for k, v in self._seen.items() if now - v > self._ttl]
|
|
for k in expired:
|
|
self._seen.pop(k, None)
|