新增 iMessage 通道适配器完整实现,包含: 1. 核心适配器与工具工厂导出 2. 运行时存储、反射防护、会话路由等基础组件 3. 消息信封、线程管理、回复上下文格式化 4. Tapback 表情反应处理、自定义异常体系 5. 审批按钮、联系人解析、速率限制功能 6. 文本净化、目标解析、缓存管理模块 7. 配置 schema、多账户支持、安装向导等配置模块 8. 审计日志、媒体AI处理等扩展功能
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from __future__ import annotations
|
|
|
|
|
|
def format_reply_context(
|
|
reply_to_message_id: str | None = None,
|
|
reply_to_text: str | None = None,
|
|
reply_to_sender: str | None = None,
|
|
) -> str:
|
|
"""格式化引用回复上下文。
|
|
|
|
生成如 "[Replying to +8613800138000 id:msg_001]" 格式的上下文行,
|
|
附加在出站消息文本前。
|
|
"""
|
|
if not reply_to_message_id and not reply_to_text:
|
|
return ""
|
|
|
|
parts: list[str] = ["[Replying to"]
|
|
|
|
if reply_to_sender:
|
|
parts.append(f" {reply_to_sender}")
|
|
|
|
if reply_to_message_id:
|
|
parts.append(f" id:{reply_to_message_id}")
|
|
|
|
if reply_to_text:
|
|
preview = reply_to_text[:100].replace("\n", " ")
|
|
parts.append(f' "{preview}"')
|
|
|
|
parts.append("]\n")
|
|
return " ".join(parts) if len(parts) > 2 else ""
|
|
|
|
|
|
def describe_reply_context(data: dict) -> str:
|
|
"""从消息数据中提取并格式化回复上下文。"""
|
|
reply_to_guid = data.get("replyToGuid")
|
|
reply_to_text = data.get("threadOriginatorText")
|
|
reply_to_sender = data.get("threadOriginator")
|
|
|
|
return format_reply_context(
|
|
reply_to_message_id=reply_to_guid,
|
|
reply_to_text=reply_to_text,
|
|
reply_to_sender=reply_to_sender,
|
|
)
|