新增 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: 类型定义
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from yuxi.channel.extensions.ringcentral.sdk import AsyncRingCentralClient
|
|
from yuxi.channel.extensions.ringcentral.types import ResolvedRingCentralAccount
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
DEFAULT_SUBSCRIPTION_EXPIRES = 86400 * 7
|
|
|
|
|
|
async def create_subscription(
|
|
client: AsyncRingCentralClient,
|
|
account: ResolvedRingCentralAccount,
|
|
webhook_url: str,
|
|
expires_in: int = DEFAULT_SUBSCRIPTION_EXPIRES,
|
|
) -> dict:
|
|
payload = {
|
|
"eventFilters": [
|
|
"/restapi/v1.0/glip/posts",
|
|
"/restapi/v1.0/glip/groups",
|
|
],
|
|
"expiresIn": expires_in,
|
|
"deliveryMode": {
|
|
"transportType": "WebHook",
|
|
"address": webhook_url,
|
|
},
|
|
}
|
|
|
|
if not any("adaptive-cards" in f for f in payload["eventFilters"]):
|
|
payload["eventFilters"].append("/team-messaging/v1/adaptive-cards/action")
|
|
|
|
result = await client.post("/restapi/v1.0/subscription", body=payload)
|
|
logger.info("RingCentral subscription created: id=%s", result.get("id"))
|
|
return result
|
|
|
|
|
|
async def renew_subscription(
|
|
client: AsyncRingCentralClient,
|
|
subscription_id: str,
|
|
expires_in: int = DEFAULT_SUBSCRIPTION_EXPIRES,
|
|
) -> dict:
|
|
result = await client.put(
|
|
f"/restapi/v1.0/subscription/{subscription_id}",
|
|
body={"expiresIn": expires_in},
|
|
)
|
|
logger.info("RingCentral subscription renewed: id=%s", subscription_id)
|
|
return result
|
|
|
|
|
|
async def delete_subscription(client: AsyncRingCentralClient, subscription_id: str) -> None:
|
|
await client.delete(f"/restapi/v1.0/subscription/{subscription_id}")
|
|
logger.info("RingCentral subscription deleted: id=%s", subscription_id)
|
|
|
|
|
|
async def get_subscription(client: AsyncRingCentralClient, subscription_id: str) -> dict:
|
|
return await client.get(f"/restapi/v1.0/subscription/{subscription_id}")
|