新增 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
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
import secrets
|
|
import time
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
CODE_TTL_SECONDS = 600
|
|
|
|
|
|
class ZoomPairing:
|
|
id_label: str = "zoomUserId"
|
|
|
|
def __init__(self):
|
|
self._pending: dict[str, dict] = {}
|
|
|
|
async def generate_code(self, peer_id: str) -> str:
|
|
code = secrets.randbelow(1_000_000)
|
|
code_str = f"{code:06d}"
|
|
from yuxi.channel.extensions.zoomchat.session import build_dm_session_key
|
|
|
|
key = build_dm_session_key(peer_id, "default")
|
|
self._pending[key] = {
|
|
"code": code_str,
|
|
"created_at": time.time(),
|
|
"peer_id": peer_id,
|
|
}
|
|
logger.info("Zoom pairing code generated: peer=%s, code=%s", peer_id, code_str)
|
|
return code_str
|
|
|
|
async def verify_code(self, peer_id: str, code: str) -> bool:
|
|
from yuxi.channel.extensions.zoomchat.session import build_dm_session_key
|
|
|
|
key = build_dm_session_key(peer_id, "default")
|
|
pending = self._pending.get(key)
|
|
|
|
if not pending:
|
|
logger.warning("Zoom pairing verify: no pending code for peer=%s", peer_id)
|
|
return False
|
|
|
|
now = time.time()
|
|
if now - pending["created_at"] > CODE_TTL_SECONDS:
|
|
logger.info("Zoom pairing code expired for peer=%s", peer_id)
|
|
self._pending.pop(key, None)
|
|
return False
|
|
|
|
if pending["code"] == code:
|
|
self._pending.pop(key, None)
|
|
logger.info("Zoom pairing verified: peer=%s", peer_id)
|
|
return True
|
|
|
|
logger.warning("Zoom pairing code mismatch: peer=%s", peer_id)
|
|
return False
|