新增淘宝(Taobao)渠道扩展,支持在 Yuxi 平台中集成淘宝电商客服渠道。 包含以下功能模块: - client: 淘宝 API 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - message: 消息处理 - pairing: 用户配对与绑定 - security: 安全校验 - crypto: 加解密处理 - status: 会话状态管理 - tools: Agent 工具集成 - types: 类型定义
65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
import logging
|
|
|
|
from yuxi.channel.protocols import ChannelAccountSnapshot
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class TaobaoStatus:
|
|
async def probe(self, account: dict) -> bool:
|
|
app_key = account.get("app_key", "")
|
|
app_secret = account.get("app_secret", "")
|
|
if not app_key or not app_secret:
|
|
return False
|
|
|
|
from yuxi.channel.extensions.taobao.client import TaobaoClient
|
|
|
|
client = TaobaoClient(
|
|
app_key=app_key,
|
|
app_secret=app_secret,
|
|
sign_method=account.get("sign_method", "md5"),
|
|
sandbox=account.get("sandbox", False),
|
|
)
|
|
|
|
try:
|
|
resp = await client.execute("taobao.time.get")
|
|
return "time_get_response" in resp
|
|
except Exception as e:
|
|
logger.warning("Taobao probe failed for %s: %s", account.get("account_id", "default"), e)
|
|
return False
|
|
|
|
def build_summary(self, snapshot: object) -> dict:
|
|
if isinstance(snapshot, ChannelAccountSnapshot):
|
|
return {
|
|
"channel": "taobao",
|
|
"account_id": snapshot.account_id,
|
|
"configured": snapshot.configured,
|
|
"connected": snapshot.connected,
|
|
"last_message_at": snapshot.last_message_at,
|
|
"last_error": snapshot.last_error,
|
|
}
|
|
return {}
|
|
|
|
def build_account_snapshot(
|
|
self,
|
|
account: dict,
|
|
config: dict,
|
|
runtime: ChannelAccountSnapshot | None = None,
|
|
probe_result: object | None = None,
|
|
audit: object | None = None,
|
|
) -> ChannelAccountSnapshot:
|
|
acc_id = account.get("account_id", "default")
|
|
configured = bool(account.get("app_key") and account.get("app_secret"))
|
|
|
|
return ChannelAccountSnapshot(
|
|
account_id=acc_id,
|
|
name=account.get("name", account.get("seller_nick", acc_id)),
|
|
enabled=account.get("enabled", True),
|
|
configured=configured,
|
|
connected=probe_result if isinstance(probe_result, bool) else False,
|
|
last_message_at=runtime.last_message_at if runtime else None,
|
|
last_error=getattr(runtime, "last_error", None) if runtime else None,
|
|
dm_policy=account.get("dm_policy", "open"),
|
|
allow_from=account.get("allow_from", []),
|
|
)
|