新增 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: 会话状态管理
54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
import os
|
|
|
|
from yuxi.channel.extensions.webex.types import WebexAccount
|
|
|
|
|
|
class WebexConfigAdapter:
|
|
def list_account_ids(self, config: dict | None = None) -> list[str]:
|
|
return ["default"]
|
|
|
|
async def resolve_account(self, account_id: str, snapshot=None) -> WebexAccount:
|
|
token = os.environ.get("WEBEX_BOT_TOKEN", "")
|
|
secret = os.environ.get("WEBEX_WEBHOOK_SECRET", "")
|
|
port_str = os.environ.get("WEBEX_WEBHOOK_PORT", "")
|
|
port = int(port_str) if port_str else 8086
|
|
host = os.environ.get("WEBEX_WEBHOOK_HOST", "0.0.0.0")
|
|
|
|
dm_policy = "open"
|
|
space_policy = "at_mention"
|
|
allow_from: list[str] = []
|
|
|
|
if snapshot and hasattr(snapshot, "config"):
|
|
channel_cfg = snapshot.config.get("channels", {}).get("webex", {}) or {}
|
|
accounts = channel_cfg.get("accounts", {}) or {}
|
|
raw = accounts.get(account_id, accounts.get("default", channel_cfg))
|
|
token = raw.get("bot_access_token", "") or token
|
|
secret = raw.get("webhook_secret", "") or secret
|
|
port = raw.get("webhook_port", port)
|
|
host = raw.get("webhook_host", host)
|
|
dm_policy = raw.get("dm_policy", dm_policy)
|
|
space_policy = raw.get("space_policy", space_policy)
|
|
allow_from = raw.get("allow_from", allow_from) or []
|
|
|
|
return WebexAccount(
|
|
account_id=account_id,
|
|
bot_access_token=token,
|
|
webhook_secret=secret,
|
|
webhook_host=host,
|
|
webhook_port=port,
|
|
dm_policy=dm_policy,
|
|
space_policy=space_policy,
|
|
allow_from=allow_from,
|
|
)
|
|
|
|
def is_configured(self, account: dict | None = None) -> bool:
|
|
if account and isinstance(account, dict):
|
|
return bool(account.get("bot_access_token", ""))
|
|
return bool(os.environ.get("WEBEX_BOT_TOKEN", ""))
|
|
|
|
def is_enabled(self, account: dict | None = None) -> bool:
|
|
return True
|
|
|
|
def disabled_reason(self, account: dict | None = None) -> str:
|
|
return ""
|