新增 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: 类型定义
63 lines
2.3 KiB
Python
63 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class RingCentralSecurityAdapter:
|
|
def resolve_dm_policy(self) -> dict:
|
|
return {"mode": "pairing", "allow_from": []}
|
|
|
|
def check_allowlist(self, sender_id: str, account) -> bool:
|
|
if not account:
|
|
return True
|
|
allow_from = account.dm_allow_from if hasattr(account, "dm_allow_from") else []
|
|
if not allow_from:
|
|
return True
|
|
return sender_id in allow_from
|
|
|
|
def evaluate(self, chat_type: str, sender_id: str, text: str, account) -> tuple[bool, str]:
|
|
if chat_type == "direct":
|
|
if not account:
|
|
return True, "ok"
|
|
if not getattr(account, "dm_enabled", True):
|
|
return False, "dm_disabled"
|
|
dm_policy = getattr(account, "dm_policy", "pairing")
|
|
if dm_policy == "disabled":
|
|
return False, "dm_disabled"
|
|
if dm_policy == "allowlist" and not self.check_allowlist(sender_id, account):
|
|
return False, "sender_not_in_allowlist"
|
|
if dm_policy == "pairing":
|
|
return True, "pairing_check"
|
|
|
|
elif chat_type in ("group", "team"):
|
|
if not account:
|
|
return True, "ok"
|
|
group_policy = getattr(account, "group_policy", "allowlist")
|
|
if group_policy == "disabled":
|
|
return False, "group_disabled"
|
|
if getattr(account, "require_mention", True) and "@!" not in text:
|
|
return False, "mention_required"
|
|
|
|
return True, "ok"
|
|
|
|
def collect_warnings(self, config: dict, account_id: str | None = None) -> list[str]:
|
|
warnings = []
|
|
rc_config = config.get("channels", {}).get("ringcentral", {})
|
|
|
|
group_policy = rc_config.get("group_policy", "allowlist")
|
|
if group_policy == "open":
|
|
warnings.append(
|
|
"Group policy is 'open' - any RingCentral group can trigger the bot. "
|
|
"Consider using 'allowlist' for production."
|
|
)
|
|
|
|
dm_policy = rc_config.get("dm_policy", "pairing")
|
|
if dm_policy == "open":
|
|
warnings.append(
|
|
"DM policy is 'open' - anyone can DM the bot. Consider using 'pairing' or 'allowlist' for production."
|
|
)
|
|
|
|
return warnings
|