新增 iMessage 通道适配器完整实现,包含: 1. 核心适配器与工具工厂导出 2. 运行时存储、反射防护、会话路由等基础组件 3. 消息信封、线程管理、回复上下文格式化 4. Tapback 表情反应处理、自定义异常体系 5. 审批按钮、联系人解析、速率限制功能 6. 文本净化、目标解析、缓存管理模块 7. 配置 schema、多账户支持、安装向导等配置模块 8. 审计日志、媒体AI处理等扩展功能
57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
def format_approval_message(request_id: str, action: str, payload: dict[str, Any] | None = None) -> str:
|
|
"""生成审批请求消息文本。
|
|
|
|
iMessage 不支持内联按钮,使用文本命令模拟审批。
|
|
"""
|
|
lines = [
|
|
"Pending Approval Required",
|
|
f"Action: {action}",
|
|
f"Request ID: {request_id}",
|
|
"",
|
|
]
|
|
|
|
if payload:
|
|
for key, val in payload.items():
|
|
val_str = str(val)[:100]
|
|
lines.append(f" {key}: {val_str}")
|
|
|
|
lines.extend(
|
|
[
|
|
"",
|
|
"Reply with:",
|
|
f" approve {request_id} — to approve",
|
|
f" reject {request_id} — to reject",
|
|
]
|
|
)
|
|
|
|
return "\n".join(lines)
|
|
|
|
|
|
def format_approval_result(request_id: str, approved: bool, message: str = "") -> str:
|
|
status = "APPROVED" if approved else "REJECTED"
|
|
lines = [f"Approval {status}: {request_id}"]
|
|
if message:
|
|
lines.append(f" {message}")
|
|
return "\n".join(lines)
|
|
|
|
|
|
def parse_approval_command(text: str) -> tuple[str | None, str | None]:
|
|
"""解析审批文本命令。
|
|
|
|
返回 (action, request_id),其中 action 为 "approve" 或 "reject"。
|
|
"""
|
|
text_lower = text.strip().lower()
|
|
parts = text_lower.split(maxsplit=1)
|
|
if len(parts) < 2:
|
|
return None, None
|
|
action = parts[0]
|
|
request_id = parts[1].strip()
|
|
if action in ("approve", "reject"):
|
|
return action, request_id
|
|
return None, None
|