ForcePilot/backend/package/yuxi/channels/adapters/whatsapp/auth_resolve.py
Kris e9b57546ea feat(whatsapp): 新增WhatsApp适配器完整功能模块
新增大量WhatsApp适配器相关代码,包括账号管理、会话处理、消息收发、验证授权、媒体处理、互动命令、审批流程、健康检测等完整功能模块,搭建基础的Baileys协议WhatsApp接入能力
2026-05-12 00:51:58 +08:00

32 lines
1.0 KiB
Python

from __future__ import annotations
import os
from pathlib import Path
from yuxi.utils.logging_config import logger
def resolve_auth_dir(instance_id: str, config: dict, account_id: str | None = None) -> Path:
base = config.get("dataDir", config.get("data_dir", ""))
channel_id = config.get("channelId", config.get("channel_id", instance_id))
if base:
auth_dir = Path(base) / "whatsapp" / channel_id
else:
auth_dir = Path(os.getcwd()) / "data" / "channels" / "whatsapp" / channel_id
if account_id:
auth_dir = auth_dir / "accounts" / account_id
auth_dir.mkdir(parents=True, exist_ok=True)
logger.debug(f"AuthDir resolved: {auth_dir}")
return auth_dir
def ensure_auth_dir(auth_dir: Path) -> Path:
try:
auth_dir.mkdir(parents=True, exist_ok=True)
test_file = auth_dir / ".write_test"
test_file.write_text("ok")
test_file.unlink()
except (OSError, PermissionError) as e:
raise RuntimeError(f"Cannot write to auth_dir {auth_dir}: {e}") from e
return auth_dir