ForcePilot/backend/package/yuxi/channel/extensions/lazada/status.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

87 lines
3.1 KiB
Python

from __future__ import annotations
import logging
from yuxi.channel.protocols import ChannelAccountSnapshot
logger = logging.getLogger(__name__)
class LazadaStatus:
def __init__(self, gateway=None):
self._gateway = gateway
async def probe(self, account: dict | None = None) -> bool:
gateway = self._gateway
if gateway is None:
return False
token = gateway.get_token("default")
if not token:
return False
return await gateway.probe()
def build_summary(self, snapshot: object) -> dict:
if not isinstance(snapshot, ChannelAccountSnapshot):
return {}
return {
"account_id": snapshot.account_id,
"running": snapshot.running,
"connected": snapshot.connected,
"health_state": snapshot.health_state,
}
def build_account_snapshot(
self,
account: dict,
config: dict,
runtime: ChannelAccountSnapshot | None = None,
probe_result: object | None = None,
audit: object | None = None,
) -> ChannelAccountSnapshot:
gateway = self._gateway
token = gateway.get_token("default") if gateway else None
site_code = account.get("site_code", "SG")
seller_id = account.get("seller_id", "")
display = f"lazada-{site_code}-{seller_id}" if seller_id else f"lazada-{site_code}"
return ChannelAccountSnapshot(
account_id=account.get("account_id", "default"),
name=account.get("name", display),
enabled=account.get("enabled", True),
configured=bool(account.get("app_key") and account.get("app_secret")),
status_state="linked" if token else "not-linked",
running=getattr(runtime, "running", False) if runtime else False,
connected=bool(token),
last_message_at=getattr(runtime, "last_message_at", None) if runtime else None,
health_state="ok" if probe_result else "unknown",
dm_policy=account.get("dm_policy", "open"),
)
def collect_status_issues(self, accounts: list[ChannelAccountSnapshot]) -> list:
issues = []
for acc in accounts:
if not acc.configured:
issues.append(
{
"channel": "lazada",
"account_id": acc.account_id,
"kind": "not-configured",
"message": "Lazada credentials not configured",
"fix": "Set LAZADA_APP_KEY, LAZADA_APP_SECRET environment variables",
}
)
elif not acc.connected:
issues.append(
{
"channel": "lazada",
"account_id": acc.account_id,
"kind": "not-connected",
"message": "Lazada gateway token not available",
"fix": "Check Lazada OAuth token configuration and gateway status",
}
)
return issues