ForcePilot/backend/package/yuxi/channel/extensions/yuanbao/commands.py
Kris 5946478772 feat(channel): 添加小红书、XMPP、元宝和 Zalo 渠道扩展
新增小红书、XMPP、元宝、Zalo 四个渠道扩展。

小红书渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, media, status, window

XMPP 渠道扩展主要模块:plugin, config, gateway, outbound, streaming, pairing, security, dedupe, accounts, commands, muc, rate_limiter, stanza_utils, status, monitor

元宝渠道扩展主要模块:plugin, client, config_schema, gateway, outbound(chunk/queue/transport), inbound(dispatcher), streaming, pairing, security, accounts, actions, commands, codec(biz/conn), session, shared, utils

Zalo 渠道扩展主要模块:api, config, gateway, webhook, outbound, pairing, security, session, polling, monitor, status
2026-05-21 12:04:05 +08:00

43 lines
1.4 KiB
Python

import logging
import httpx
logger = logging.getLogger(__name__)
DEFAULT_YUANBAO_COMMANDS = [
{"name": "help", "description": "显示帮助信息"},
{"name": "status", "description": "查看当前状态"},
{"name": "new", "description": "开始新的对话"},
{"name": "stop", "description": "停止当前生成"},
{"name": "compact", "description": "压缩对话上下文"},
{"name": "restart", "description": "重启 Gateway"},
]
def get_default_commands() -> list[dict]:
return DEFAULT_YUANBAO_COMMANDS
async def sync_native_commands(
api_domain: str,
access_token: str,
commands: list[dict] | None = None,
) -> bool:
_cmds = commands or DEFAULT_YUANBAO_COMMANDS
try:
async with httpx.AsyncClient(timeout=httpx.Timeout(10.0)) as client:
resp = await client.post(
f"https://{api_domain}/openapi/v1/bot/commands",
headers={
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
},
json={"commands": _cmds},
)
resp.raise_for_status()
logger.info("Yuanbao native commands synced: %d commands", len(_cmds))
return True
except Exception:
logger.exception("Failed to sync Yuanbao native commands to %s", api_domain)
return False