新增小红书、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
84 lines
3.0 KiB
Python
84 lines
3.0 KiB
Python
import os
|
|
|
|
from yuxi.channel.extensions.xiaohongshu.types import XiaohongshuAccount
|
|
|
|
|
|
class XiaohongshuConfig:
|
|
|
|
ENV_MAP = {
|
|
"app_key": "XIAOHONGSHU_APP_KEY",
|
|
"app_secret": "XIAOHONGSHU_APP_SECRET",
|
|
"dm_policy": "XIAOHONGSHU_DM_POLICY",
|
|
"streaming": "XIAOHONGSHU_STREAMING",
|
|
"remove_markdown": "XIAOHONGSHU_REMOVE_MD",
|
|
"welcome_text": "XIAOHONGSHU_WELCOME_TEXT",
|
|
}
|
|
|
|
def list_account_ids(self, config: dict | None = None) -> list[str]:
|
|
if self._resolve_app_key():
|
|
return ["default"]
|
|
return []
|
|
|
|
def resolve_account(self, account_id: str = "default") -> XiaohongshuAccount:
|
|
return XiaohongshuAccount(
|
|
account_id=account_id,
|
|
app_key=self._resolve_app_key() or "",
|
|
app_secret=self._env_or_config("app_secret") or "",
|
|
dm_policy=self._env_or_config("dm_policy") or "open",
|
|
streaming=self._env_or_config("streaming") != "false",
|
|
remove_markdown=self._env_or_config("remove_markdown") != "false",
|
|
welcome_text=self._env_or_config("welcome_text") or "你好!有什么可以帮助你的?",
|
|
)
|
|
|
|
def is_configured(self, account: dict | None = None) -> bool:
|
|
return bool(self._resolve_app_key() and self._env_or_config("app_secret"))
|
|
|
|
def _resolve_app_key(self) -> str | None:
|
|
return self._env_or_config("app_key")
|
|
|
|
def _env_or_config(self, key: str) -> str | None:
|
|
env_key = self.ENV_MAP.get(key, "")
|
|
if env_key:
|
|
val = os.getenv(env_key)
|
|
if val:
|
|
return val
|
|
return None
|
|
|
|
def config_schema(self) -> dict:
|
|
return {
|
|
"$schema": "https://json-schema.org/draft-07/schema#",
|
|
"type": "object",
|
|
"title": "小红书渠道配置",
|
|
"properties": {
|
|
"app_key": {
|
|
"type": "string",
|
|
"title": "App Key",
|
|
"description": "小红书开放平台应用的 App Key",
|
|
},
|
|
"app_secret": {
|
|
"type": "string",
|
|
"title": "App Secret",
|
|
"x-ui-password": True,
|
|
"description": "小红书开放平台应用的 App Secret",
|
|
},
|
|
"dm_policy": {
|
|
"type": "string",
|
|
"enum": ["open", "pairing", "allowlist", "disabled"],
|
|
"default": "open",
|
|
"title": "DM 策略",
|
|
},
|
|
"streaming": {
|
|
"type": "boolean",
|
|
"default": True,
|
|
"title": "启用流式输出",
|
|
},
|
|
"remove_markdown": {
|
|
"type": "boolean",
|
|
"default": True,
|
|
"title": "移除 Markdown 格式",
|
|
"description": "自动移除 AI 回复中的 Markdown 符号和外部 URL 链接",
|
|
},
|
|
},
|
|
"required": ["app_key", "app_secret"],
|
|
}
|