ForcePilot/backend/package/yuxi/channels/adapters/zalo_oa/probe.py
Kris 30dd9e16f4 feat(zalo-oa): 实现完整的 Zalo OA 渠道适配器模块
新增 Zalo OA 官方账号完整集成能力,包含:
1. 基础通信能力:消息编解码、目标归一化、文本分块
2. 安全与校验:Webhook 签名验证、DM 策略管理、配对流程
3. 辅助工具:重复事件去重、请求限流、异常告警
4. 管理功能:账号多实例管理、配置验证、健康诊断
5. 扩展能力:媒体托管、视觉识别、TTS 语音合成
6. 运维支持:审计日志、状态监控、目录同步
2026-05-12 00:52:47 +08:00

52 lines
1.8 KiB
Python

from __future__ import annotations
import asyncio
import time
from typing import Any
from yuxi.channels.adapters.zalo_oa.client import ZaloOAClient
async def probe_zalo_oa(
app_id: str, secret_key: str, config: dict[str, Any] | None = None, timeout_ms: int = 2500
) -> dict:
async with ZaloOAClient(app_id, secret_key, config) as client:
start = time.monotonic()
try:
await asyncio.wait_for(client.fetch_access_token(), timeout=timeout_ms / 1000)
except TimeoutError:
return {
"status": "error",
"message": f"Token fetch timed out after {timeout_ms}ms",
"elapsed_ms": (time.monotonic() - start) * 1000,
}
except Exception as e:
return {
"status": "error",
"message": f"Failed to get access token: {e}",
"elapsed_ms": (time.monotonic() - start) * 1000,
}
try:
profile = await asyncio.wait_for(client.get_oa_profile(), timeout=timeout_ms / 1000)
except TimeoutError:
return {
"status": "error",
"message": f"Profile fetch timed out after {timeout_ms}ms",
"elapsed_ms": (time.monotonic() - start) * 1000,
}
except Exception as e:
return {
"status": "error",
"message": f"Failed to get OA profile: {e}",
"elapsed_ms": (time.monotonic() - start) * 1000,
}
return {
"status": "ok",
"oa_id": profile.get("oa_id", ""),
"name": profile.get("name", ""),
"follower_count": profile.get("follower_count", 0),
"elapsed_ms": (time.monotonic() - start) * 1000,
}