新增拼多多(Pinduoduo)渠道扩展,支持在 Yuxi 平台中集成拼多多电商客服渠道。 包含以下功能模块: - client: 拼多多 API 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - pairing: 用户配对与绑定 - security: 安全校验 - signature: 请求签名验证 - token: Token 管理 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - tools: Agent 工具集成 - window: 窗口管理 - types: 类型定义
69 lines
1.8 KiB
Python
69 lines
1.8 KiB
Python
from __future__ import annotations
|
||
|
||
import logging
|
||
import time
|
||
from dataclasses import dataclass, field
|
||
|
||
from yuxi.channel.extensions.pinduoduo.token import PddTokenManager
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
|
||
@dataclass
|
||
class PinduoduoStatus:
|
||
account_id: str
|
||
mall_id: str
|
||
connected: bool = False
|
||
running: bool = False
|
||
last_error: str | None = None
|
||
last_probe_time: float = field(default_factory=time.time)
|
||
poll_count: int = 0
|
||
outbound_count: int = 0
|
||
|
||
def snapshot(self) -> dict:
|
||
return {
|
||
"channel": "pinduoduo",
|
||
"account_id": self.account_id,
|
||
"mall_id": self.mall_id,
|
||
"connected": self.connected,
|
||
"running": self.running,
|
||
"poll_count": self.poll_count,
|
||
"outbound_sent": self.outbound_count,
|
||
"last_error": self.last_error,
|
||
"last_probe": self.last_probe_time,
|
||
}
|
||
|
||
|
||
async def probe_pinduoduo(
|
||
client_id: str,
|
||
client_secret: str,
|
||
mall_id: str,
|
||
refresh_token: str | None = None,
|
||
access_token: str | None = None,
|
||
) -> dict:
|
||
try:
|
||
token_mgr = PddTokenManager(
|
||
client_id=client_id,
|
||
client_secret=client_secret,
|
||
mall_id=mall_id,
|
||
refresh_token=refresh_token,
|
||
access_token=access_token,
|
||
)
|
||
token = await token_mgr.get_token()
|
||
await token_mgr.close()
|
||
|
||
return {
|
||
"status": "ok",
|
||
"connected": True,
|
||
"message": "Token 有效,API 连通正常",
|
||
"token_obtained": bool(token),
|
||
"mall_id": mall_id,
|
||
}
|
||
except Exception as e:
|
||
return {
|
||
"status": "error",
|
||
"connected": False,
|
||
"message": str(e),
|
||
"mall_id": mall_id,
|
||
}
|