ForcePilot/backend/package/yuxi/channel/extensions/tencent_im/security.py
Kris 331daa1216 feat(channel): 添加腾讯 IM 渠道扩展
新增腾讯 IM(Tencent IM)渠道扩展,支持在 Yuxi 平台中集成腾讯即时通讯 IM 渠道。

包含以下功能模块:
- config: 渠道配置管理
- gateway: SSE/WebSocket 网关接入
- webhook: Webhook 事件处理
- outbound: 外发消息管理
- pairing: 用户配对与绑定
- security: 安全校验
- signature: 请求签名验证
- usersig: UserSig 生成
- dedupe: 消息去重
- status: 会话状态管理
- group: 群组管理
- types: 类型定义
2026-05-21 11:49:29 +08:00

33 lines
988 B
Python

import logging
from yuxi.channel.extensions.tencent_im.types import TencentIMAccount
logger = logging.getLogger(__name__)
class TencentIMSecurity:
VALID_POLICIES = {"open", "pairing", "allowlist", "disabled"}
def __init__(self, account: TencentIMAccount | None = None):
if account and account.dm_policy in self.VALID_POLICIES:
self._policy = account.dm_policy
else:
self._policy = "open"
self._allowlist: set[str] = set(account.allow_from) if account else set()
def resolve_dm_policy(self) -> str:
return self._policy
def check_allowlist(self, user_id: str) -> bool:
if self._policy == "open":
return True
if self._policy == "disabled":
return False
return user_id in self._allowlist
def add_to_allowlist(self, user_id: str):
self._allowlist.add(user_id)
def remove_from_allowlist(self, user_id: str):
self._allowlist.discard(user_id)