新增 Zalo OA 官方账号完整集成能力,包含: 1. 基础通信能力:消息编解码、目标归一化、文本分块 2. 安全与校验:Webhook 签名验证、DM 策略管理、配对流程 3. 辅助工具:重复事件去重、请求限流、异常告警 4. 管理功能:账号多实例管理、配置验证、健康诊断 5. 扩展能力:媒体托管、视觉识别、TTS 语音合成 6. 运维支持:审计日志、状态监控、目录同步
54 lines
1.3 KiB
Python
54 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
def resolve_approvers(config: dict[str, Any]) -> list[str]:
|
|
approvers = config.get("approvers", config.get("execApprovers", []))
|
|
if not isinstance(approvers, list):
|
|
approvers = []
|
|
allowlist = config.get("allowFrom", [])
|
|
if not isinstance(allowlist, list):
|
|
allowlist = []
|
|
|
|
if not approvers:
|
|
approvers = list(allowlist)
|
|
|
|
return [normalize_approver_id(str(a)) for a in approvers]
|
|
|
|
|
|
def normalize_approver_id(approver_id: str) -> str:
|
|
prefixes = ("zalo_oa:", "zoa:")
|
|
for prefix in prefixes:
|
|
if approver_id.lower().startswith(prefix):
|
|
return approver_id[len(prefix) :]
|
|
return approver_id
|
|
|
|
|
|
def check_approval_required(
|
|
action: str,
|
|
config: dict[str, Any],
|
|
) -> bool:
|
|
require_approval = config.get("requireExecApproval", False)
|
|
if not require_approval:
|
|
return False
|
|
|
|
exempt_actions = config.get("approvalExemptActions", [])
|
|
if action in exempt_actions:
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
def build_approval_request(
|
|
action: str,
|
|
requester_id: str,
|
|
params: dict[str, Any] | None = None,
|
|
) -> dict[str, Any]:
|
|
return {
|
|
"action": action,
|
|
"requester_id": requester_id,
|
|
"params": params or {},
|
|
"status": "pending",
|
|
}
|