新增群晖Chat渠道适配器的全套实现,包括: 1. 基础适配器与导出接口定义 2. DSM API认证、探测与会话管理 3. 轮询与Webhook两种消息接收方式 4. 消息去重、格式化与规范化处理 5. 多账号支持与权限安全策略 6. 目录用户/群组发现功能 7. 审批配对与流量控制机制 8. 安全审计与配置检查功能
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
"""Target management for Synology Chat channel.
|
||
|
||
ID normalization, validation, and format hints for user/group targeting.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
|
||
_CHANNEL_PREFIX = "synologychat:"
|
||
|
||
|
||
def normalize_target(target: str) -> str:
|
||
"""Strip channel prefix from a target identifier if present.
|
||
|
||
Handles both 'synologychat:' and 'synology-chat:' prefixes.
|
||
"""
|
||
if target.startswith("synologychat:"):
|
||
return target[len("synologychat:") :]
|
||
if target.startswith("synology-chat:"):
|
||
return target[len("synology-chat:") :]
|
||
return target
|
||
|
||
|
||
def looks_like_id(value: str) -> bool:
|
||
"""Check if a value looks like a Synology Chat user/channel ID.
|
||
|
||
Synology Chat IDs are generally pure numeric strings.
|
||
"""
|
||
return bool(value and value.isdigit())
|
||
|
||
|
||
def target_format_hint() -> str:
|
||
"""Return the expected format for target identifiers."""
|
||
return (
|
||
"Synology Chat 目标格式:\n"
|
||
"- 用户 ID:纯数字字符串,例如 '12345'\n"
|
||
"- 频道 ID:纯数字字符串,例如 '67890'\n"
|
||
"- 可通过 user_list / channel_list API 获取可用 ID\n"
|
||
"- 支持前缀格式 'synologychat:<id>'(自动剥离)\n"
|
||
)
|
||
|
||
|
||
def build_target_label(user_id: str, channel_id: str | None = None) -> str:
|
||
"""Build a human-readable label for a target."""
|
||
if channel_id:
|
||
return f"synologychat:{channel_id}:{user_id}"
|
||
return f"synologychat:{user_id}"
|