新增 iMessage 通道适配器完整实现,包含: 1. 核心适配器与工具工厂导出 2. 运行时存储、反射防护、会话路由等基础组件 3. 消息信封、线程管理、回复上下文格式化 4. Tapback 表情反应处理、自定义异常体系 5. 审批按钮、联系人解析、速率限制功能 6. 文本净化、目标解析、缓存管理模块 7. 配置 schema、多账户支持、安装向导等配置模块 8. 审计日志、媒体AI处理等扩展功能
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
from yuxi.channels.models import ChannelIdentity
|
|
|
|
|
|
def format_inbound_envelope(
|
|
identity: ChannelIdentity,
|
|
sender_name: str = "",
|
|
chat_name: str = "",
|
|
reply_context: dict | None = None,
|
|
) -> str:
|
|
"""生成标准入站信封格式。
|
|
|
|
格式示例:
|
|
[From: Alice (alice@icloud.com)] @Family Chat
|
|
"""
|
|
parts: list[str] = []
|
|
|
|
sender_display = sender_name or identity.channel_user_id
|
|
parts.append(f"[From: {sender_display}")
|
|
|
|
if identity.channel_user_id != sender_display:
|
|
parts.append(f" ({identity.channel_user_id})")
|
|
|
|
parts.append("]")
|
|
|
|
if chat_name:
|
|
parts.append(f" @{chat_name}")
|
|
|
|
if reply_context:
|
|
reply_to_id = reply_context.get("reply_to_message_id")
|
|
reply_to_text = reply_context.get("reply_to_text")
|
|
if reply_to_text:
|
|
preview = reply_to_text[:80].replace("\n", " ")
|
|
parts.append(f"\n > Replying to: {preview}")
|
|
elif reply_to_id:
|
|
parts.append(f"\n > Replying to message id:{reply_to_id}")
|
|
|
|
return "".join(parts)
|