新增 Webex、微信 iLink、微信小程序三个渠道扩展。 Webex 渠道扩展功能模块: - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - streaming: 流式消息处理 - pairing: 用户配对与绑定 - security: 安全校验 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - media: 媒体资源处理 微信 iLink 渠道扩展功能模块: - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - outbound: 外发消息管理 - streaming: 流式消息处理 - pairing: 用户配对与绑定 - security: 安全校验 - dedupe: 消息去重 - monitor: 渠道状态监控 - status: 会话状态管理 - context_store: 上下文存储 - aes_ecb: AES-ECB 加解密 - media: 媒体资源处理 - typing: 输入状态 微信小程序渠道扩展功能模块: - config: 渠道配置管理 - gateway: SSE/WebSocket 网关接入 - webhook: Webhook 事件处理 - outbound: 外发消息管理 - streaming: 流式消息处理 - pairing: 用户配对与绑定 - security: 安全校验 - crypto: 加解密处理 - dedupe: 消息去重 - message: 消息处理 - passive_reply: 被动回复 - media: 媒体资源处理 - status: 会话状态管理
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from yuxi.channel.extensions.wechat_ilink.types import ILinkAccount, ILinkDMStrategy, ILinkGroupStrategy
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ILinkSecurity:
|
|
def __init__(self, account: ILinkAccount, pairing=None):
|
|
self._account = account
|
|
self._pairing = pairing
|
|
|
|
def check_dm_access(self, sender_id: str) -> bool:
|
|
policy = self._account.dm_policy
|
|
|
|
if policy == ILinkDMStrategy.DISABLED:
|
|
return False
|
|
|
|
if policy == ILinkDMStrategy.OPEN:
|
|
if not self._account.allow_from or "*" in self._account.allow_from:
|
|
return True
|
|
return sender_id in self._account.allow_from
|
|
|
|
if policy == ILinkDMStrategy.ALLOWLIST:
|
|
return sender_id in self._account.allow_from
|
|
|
|
if policy == ILinkDMStrategy.PAIRING:
|
|
return self._check_pairing(sender_id)
|
|
|
|
return True
|
|
|
|
def check_group_access(self, group_id: str, sender_id: str) -> bool:
|
|
policy = self._account.group_policy
|
|
|
|
if policy == ILinkGroupStrategy.DISABLED:
|
|
return False
|
|
|
|
if policy == ILinkGroupStrategy.OPEN:
|
|
return True
|
|
|
|
if policy == ILinkGroupStrategy.ALLOWLIST:
|
|
return group_id in self._account.allow_from
|
|
|
|
return True
|
|
|
|
def _check_pairing(self, sender_id: str) -> bool:
|
|
if self._pairing is None:
|
|
return False
|
|
return self._pairing.is_paired(sender_id)
|