新增 RingCentral 渠道扩展,支持在 Yuxi 平台中集成 RingCentral 统一通信平台。 包含以下功能模块: - sdk: RingCentral SDK 封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - subscription: 事件订阅 - outbound: 外发消息管理 - streaming: 流式消息处理 - pairing: 用户配对与绑定 - security: 安全校验 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - session: 会话管理 - events: 事件处理 - adaptive_cards: 自适应卡片 - formatting: 格式化 - media: 媒体资源处理 - mentions: @提及 - notes: 笔记功能 - reactions: 表情反应 - tasks: 任务管理 - teams: 团队管理 - types: 类型定义
75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from yuxi.channel.extensions.ringcentral.types import ResolvedRingCentralAccount
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class RingCentralStatusAdapter:
|
|
async def probe(self, account_dict: dict) -> bool:
|
|
account = account_dict.get("resolved")
|
|
if not isinstance(account, ResolvedRingCentralAccount):
|
|
return False
|
|
|
|
from yuxi.channel.plugins.registry import ChannelPluginRegistry
|
|
|
|
plugin = ChannelPluginRegistry.get("ringcentral")
|
|
if not plugin or not hasattr(plugin, "_gateway"):
|
|
return False
|
|
|
|
client = plugin._gateway.get_client(account.account_id)
|
|
if not client or not client.is_logged_in:
|
|
return False
|
|
|
|
try:
|
|
await client.get("/restapi/v1.0/account/~/extension/~")
|
|
return True
|
|
except Exception:
|
|
return False
|
|
|
|
def build_summary(self, snapshot) -> dict:
|
|
return {
|
|
"channel": "ringcentral",
|
|
"mode": "webhook",
|
|
}
|
|
|
|
def build_account_snapshot(self, account_dict: dict) -> dict:
|
|
return {
|
|
"account_id": account_dict.get("account_id", "default"),
|
|
"name": account_dict.get("name", ""),
|
|
"configured": bool(account_dict.get("client_id") and account_dict.get("jwt_token")),
|
|
"enabled": account_dict.get("enabled", True),
|
|
}
|
|
|
|
def collect_status_issues(self, accounts: list[dict]) -> list[dict]:
|
|
issues = []
|
|
for account in accounts:
|
|
if not account:
|
|
continue
|
|
|
|
if not account.get("client_id"):
|
|
issues.append(
|
|
{
|
|
"channel": "ringcentral",
|
|
"account_id": account.get("account_id", "default"),
|
|
"kind": "client_id_missing",
|
|
"message": "client_id is not configured.",
|
|
"fix": "Set channels.ringcentral.client_id.",
|
|
}
|
|
)
|
|
|
|
if not account.get("jwt_token"):
|
|
issues.append(
|
|
{
|
|
"channel": "ringcentral",
|
|
"account_id": account.get("account_id", "default"),
|
|
"kind": "jwt_token_missing",
|
|
"message": "jwt_token is not configured.",
|
|
"fix": "Set channels.ringcentral.jwt_token.",
|
|
}
|
|
)
|
|
|
|
return issues
|