ForcePilot/backend/package/yuxi/channel/extensions/wechat_miniprogram/config.py
Kris 7b5d1e5c69 feat(channel): 添加 Webex、微信 iLink 和微信小程序渠道扩展
新增 Webex、微信 iLink、微信小程序三个渠道扩展。

Webex 渠道扩展功能模块:
- config: 渠道配置管理
- gateway: SSE/WebSocket 网关接入
- webhook: Webhook 事件处理
- outbound: 外发消息管理
- streaming: 流式消息处理
- pairing: 用户配对与绑定
- security: 安全校验
- dedupe: 消息去重
- monitor: 渠道状态监控
- status: 会话状态管理
- media: 媒体资源处理

微信 iLink 渠道扩展功能模块:
- config: 渠道配置管理
- gateway: SSE/WebSocket 网关接入
- outbound: 外发消息管理
- streaming: 流式消息处理
- pairing: 用户配对与绑定
- security: 安全校验
- dedupe: 消息去重
- monitor: 渠道状态监控
- status: 会话状态管理
- context_store: 上下文存储
- aes_ecb: AES-ECB 加解密
- media: 媒体资源处理
- typing: 输入状态

微信小程序渠道扩展功能模块:
- config: 渠道配置管理
- gateway: SSE/WebSocket 网关接入
- webhook: Webhook 事件处理
- outbound: 外发消息管理
- streaming: 流式消息处理
- pairing: 用户配对与绑定
- security: 安全校验
- crypto: 加解密处理
- dedupe: 消息去重
- message: 消息处理
- passive_reply: 被动回复
- media: 媒体资源处理
- status: 会话状态管理
2026-05-21 11:59:04 +08:00

114 lines
4.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
from yuxi.channel.extensions.wechat_miniprogram.types import MiniProgramAccount
class MiniProgramConfig:
ENV_MAP = {
"app_id": "WECHAT_MINIPROGRAM_APP_ID",
"app_secret": "WECHAT_MINIPROGRAM_APP_SECRET",
"token": "WECHAT_MINIPROGRAM_TOKEN",
"encoding_aes_key": "WECHAT_MINIPROGRAM_ENCODING_AES_KEY",
"reply_mode": "WECHAT_MINIPROGRAM_REPLY_MODE",
"subscribe_msg": "WECHAT_MINIPROGRAM_SUBSCRIBE_MSG",
"remove_markdown": "WECHAT_MINIPROGRAM_REMOVE_MD",
"dm_policy": "WECHAT_MINIPROGRAM_DM_POLICY",
}
def list_account_ids(self, config: dict | None = None) -> list[str]:
if self._resolve_app_id():
return ["default"]
return []
def resolve_account(self, account_id: str = "default") -> MiniProgramAccount:
app_id = self._resolve_app_id()
return MiniProgramAccount(
account_id=account_id,
app_id=app_id or "",
app_secret=self._env_or_config("app_secret") or "",
token=self._env_or_config("token") or "",
encoding_aes_key=self._env_or_config("encoding_aes_key") or "",
dm_policy=self._env_or_config("dm_policy") or "open",
reply_mode=self._env_or_config("reply_mode") or "active",
subscribe_msg=self._env_or_config("subscribe_msg") or "",
remove_markdown=self._env_or_config("remove_markdown") != "false",
)
def is_configured(self, account: dict | None = None) -> bool:
return bool(
self._resolve_app_id()
and self._env_or_config("app_secret")
and self._env_or_config("token")
and self._env_or_config("encoding_aes_key")
)
def is_enabled(self, account: dict | None = None) -> bool:
return os.getenv("WECHAT_MINIPROGRAM_ENABLED", "true").lower() != "false"
def _resolve_app_id(self) -> str | None:
return self._env_or_config("app_id")
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_id": {
"type": "string",
"title": "小程序 AppID",
"description": "微信小程序的 AppID小程序 ID",
},
"app_secret": {
"type": "string",
"title": "小程序 AppSecret",
"x-ui-password": True,
"description": "微信小程序的 AppSecret小程序密钥",
},
"token": {
"type": "string",
"title": "消息签名 Token",
"description": "小程序后台配置的消息推送 Token",
},
"encoding_aes_key": {
"type": "string",
"title": "EncodingAESKey",
"x-ui-password": True,
"description": "小程序后台配置的 43 字符 EncodingAESKey",
},
"dm_policy": {
"type": "string",
"enum": ["open", "pairing", "allowlist", "disabled"],
"default": "open",
"title": "DM 策略",
},
"reply_mode": {
"type": "string",
"enum": ["passive", "active"],
"default": "active",
"title": "回复模式",
"description": "active=客服消息 API 主动推送, passive=被动回复 XML5s 内同步返回)",
},
"subscribe_msg": {
"type": "string",
"title": "进入客服会话欢迎语",
"description": "用户首次进入客服会话时自动回复的消息",
},
"remove_markdown": {
"type": "boolean",
"default": True,
"title": "移除 Markdown 格式",
"description": "自动移除 AI 回复中的 Markdown 符号",
},
},
"required": ["app_id", "app_secret", "token", "encoding_aes_key"],
}