新增小红书、XMPP、元宝、Zalo 四个渠道扩展。 小红书渠道扩展主要模块:config, gateway, webhook, outbound, streaming, pairing, security, dedupe, media, status, window XMPP 渠道扩展主要模块:plugin, config, gateway, outbound, streaming, pairing, security, dedupe, accounts, commands, muc, rate_limiter, stanza_utils, status, monitor 元宝渠道扩展主要模块:plugin, client, config_schema, gateway, outbound(chunk/queue/transport), inbound(dispatcher), streaming, pairing, security, accounts, actions, commands, codec(biz/conn), session, shared, utils Zalo 渠道扩展主要模块:api, config, gateway, webhook, outbound, pairing, security, session, polling, monitor, status
71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
import logging
|
|
|
|
from yuxi.channel.extensions.zalo.config import ZaloConfigAdapter
|
|
from yuxi.channel.extensions.zalo.pairing import ZaloPairing
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ZaloSecurity:
|
|
def __init__(self, config_adapter: ZaloConfigAdapter | None = None):
|
|
self._config_adapter = config_adapter or ZaloConfigAdapter()
|
|
|
|
def resolve_dm_policy(self) -> dict:
|
|
return {"mode": "pairing", "allow_from": []}
|
|
|
|
def resolve_dm_policy_for_account(self, account: dict) -> dict:
|
|
mode = account.get("dm_policy", "pairing")
|
|
return {"mode": mode, "allow_from": account.get("allow_from", [])}
|
|
|
|
async def check_allowlist(self, peer_id: str, channel_type: str, account_id: str = "default") -> bool:
|
|
account = await self._config_adapter.resolve_account(account_id)
|
|
|
|
if channel_type == "group":
|
|
allowed = account.get("group_allow_from", [])
|
|
else:
|
|
allowed = account.get("allow_from", [])
|
|
|
|
if not allowed:
|
|
return False
|
|
|
|
normalized_peer = ZaloPairing.normalize_allow_entry(peer_id)
|
|
for entry in allowed:
|
|
if ZaloPairing.normalize_allow_entry(entry) == normalized_peer:
|
|
return True
|
|
return False
|
|
|
|
def resolve_require_mention(self, ctx) -> bool | None:
|
|
config = getattr(ctx, "config", {}) if ctx else {}
|
|
group_id = getattr(ctx, "group_id", None) if ctx else None
|
|
|
|
if group_id:
|
|
groups = config.get("groups", {})
|
|
group_cfg = groups.get(group_id, {})
|
|
if "require_mention" in group_cfg:
|
|
return group_cfg["require_mention"]
|
|
|
|
return True
|
|
|
|
def resolve_group_intro_hint(self, ctx) -> str | None:
|
|
return None
|
|
|
|
def resolve_tool_policy(self, ctx) -> dict | None:
|
|
return None
|
|
|
|
def apply_config_fixes(self, config: dict) -> dict:
|
|
return config
|
|
|
|
def collect_warnings(self, config: dict, account_id: str | None = None, account: dict | None = None) -> list[str]:
|
|
warnings = []
|
|
|
|
if account:
|
|
dm_policy = account.get("dm_policy", "")
|
|
if dm_policy == "open":
|
|
warnings.append("Zalo dmPolicy is 'open' — consider 'pairing' or 'allowlist' for production use")
|
|
|
|
group_policy = account.get("group_policy", "")
|
|
if group_policy == "open" and not account.get("group_allow_from"):
|
|
warnings.append("Zalo groupPolicy is 'open' without group allowlist")
|
|
|
|
return warnings
|