ForcePilot/backend/package/yuxi/channel/extensions/lazada/security.py
Kris d523babb91 feat(channel): 添加 Lazada 渠道扩展
新增 Lazada 渠道扩展,支持在 Yuxi 平台中集成 Lazada 电商客服渠道。

包含以下功能模块:
- client: Lazada API 客户端封装
- config: 渠道配置管理
- gateway: SSE/WebSocket 网关接入
- webhook: Webhook 事件处理
- outbound: 外发消息管理
- pairing: 用户配对与绑定
- security: 安全校验
- signature: 请求签名验证
- dedupe: 消息去重
- monitor: 渠道状态监控
- status: 会话状态管理
- session: 会话管理
- tools: Agent 工具集成
- tools_config: 工具配置
- types: 类型定义
2026-05-21 11:13:39 +08:00

39 lines
1.2 KiB
Python

from __future__ import annotations
import logging
from yuxi.channel.extensions.lazada.types import LazadaAccount
logger = logging.getLogger(__name__)
class LazadaSecurity:
VALID_POLICIES = {"open", "pairing", "allowlist", "disabled"}
def __init__(self, account: LazadaAccount | None = None):
self._account = account
if account and account.dm_policy in self.VALID_POLICIES:
self._policy = account.dm_policy
else:
self._policy = "open"
self._allowlist: set[str] = set(account.allow_from) if account else set()
def resolve_dm_policy(self) -> str:
return self._policy
async def check_allowlist(self, user_id: str, channel_type: str = "lazada") -> bool:
if self._policy == "open":
return True
if self._policy == "disabled":
return False
if not self._allowlist:
logger.warning("allowlist is empty with policy=%s", self._policy)
return False
return user_id in self._allowlist
def add_to_allowlist(self, user_id: str):
self._allowlist.add(user_id)
def remove_from_allowlist(self, user_id: str):
self._allowlist.discard(user_id)