新增 Intercom 渠道扩展,支持在 Yuxi 平台中集成 Intercom 客服渠道。 包含以下功能模块: - client: Intercom API 客户端封装 - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - streaming: 流式消息处理 - format: 消息格式转换 - outbound: 外发消息管理 - handoff: 转人工会话切换 - pairing: 用户配对与绑定 - security: 安全签名校验 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - session_guard: 会话防护 - types: 类型定义
67 lines
2.3 KiB
Python
67 lines
2.3 KiB
Python
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class IntercomSecurity:
|
|
def resolve_dm_policy(self) -> dict:
|
|
return {"mode": "open", "allow_from": []}
|
|
|
|
async def check_allowlist(self, peer_id: str, channel_type: str) -> bool:
|
|
return True
|
|
|
|
def resolve_dm_policy_for_account(self, account: dict) -> dict:
|
|
mode = account.get("dm_policy", "open")
|
|
return {"mode": mode, "allow_from": account.get("allow_from", [])}
|
|
|
|
def authorize_dm(self, account: dict, contact_id: str) -> tuple[bool, str]:
|
|
policy = account.get("dm_policy", "open")
|
|
allow_from = account.get("allow_from", [])
|
|
|
|
if policy == "disabled":
|
|
return False, "DM is disabled"
|
|
|
|
if policy == "open":
|
|
if "*" in allow_from or not allow_from:
|
|
return True, ""
|
|
return contact_id in allow_from, "not-allowlisted"
|
|
|
|
if policy == "allowlist":
|
|
if not allow_from:
|
|
return False, "allowlist-empty"
|
|
return contact_id in allow_from, "not-allowlisted"
|
|
|
|
if policy == "pairing":
|
|
return True, "pairing-required"
|
|
|
|
return False, "unknown-policy"
|
|
|
|
def apply_config_fixes(self, config: dict) -> dict:
|
|
config.setdefault("channels", {})
|
|
config["channels"].setdefault("intercom", {})
|
|
return config
|
|
|
|
def collect_warnings(self, config: dict, account_id: str | None = None, account: dict | None = None) -> list[str]:
|
|
warnings: list[str] = []
|
|
|
|
if account:
|
|
if not account.get("webhook_secret"):
|
|
warnings.append("webhookSecret is not configured. Webhook signature verification will be skipped.")
|
|
if account.get("dm_policy") == "open" and not account.get("allow_from"):
|
|
warnings.append('dmPolicy is "open" without allowFrom. Consider adding allowFrom=["*"] explicitly.')
|
|
if account.get("dm_policy") == "allowlist" and not account.get("allow_from"):
|
|
warnings.append('dmPolicy is "allowlist" but allowFrom is empty. No contacts will be allowed.')
|
|
|
|
return warnings
|
|
|
|
def collect_audit_findings(
|
|
self,
|
|
config,
|
|
account_id=None,
|
|
account=None,
|
|
source_config=None,
|
|
ordered_account_ids=None,
|
|
has_explicit_account_path=False,
|
|
) -> list[dict]:
|
|
return []
|