新增京东(JD)渠道扩展,支持在 Yuxi 平台中集成京东客服渠道。 包含以下功能模块: - client: 京东 API 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - pairing: 用户配对与绑定 - security: 安全校验 - signature: 请求签名验证 - crypto: 加解密处理 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - session: 会话管理 - business: 业务逻辑处理 - types: 类型定义
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
import logging
|
|
|
|
from yuxi.channel.extensions.jd.types import JDAccount
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class JDSecurity:
|
|
VALID_POLICIES = {"open", "pairing", "allowlist", "disabled"}
|
|
|
|
def __init__(self, account: JDAccount | 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
|
|
|
|
def check_allowlist(self, user_id: str, channel_type: str = "jd") -> 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)
|