新增 iMessage 通道适配器完整实现,包含: 1. 核心适配器与工具工厂导出 2. 运行时存储、反射防护、会话路由等基础组件 3. 消息信封、线程管理、回复上下文格式化 4. Tapback 表情反应处理、自定义异常体系 5. 审批按钮、联系人解析、速率限制功能 6. 文本净化、目标解析、缓存管理模块 7. 配置 schema、多账户支持、安装向导等配置模块 8. 审计日志、媒体AI处理等扩展功能
30 lines
967 B
Python
30 lines
967 B
Python
from __future__ import annotations
|
|
|
|
from yuxi.channels.models import ChannelIdentity, ChatType
|
|
|
|
|
|
def resolve_thread_key(
|
|
identity: ChannelIdentity,
|
|
account_id: str = "default",
|
|
pinned_dm_owner: str | None = None,
|
|
) -> str:
|
|
channel_user_id = identity.channel_user_id
|
|
chat_guid = identity.channel_chat_id
|
|
chat_type = resolve_chat_type(chat_guid)
|
|
|
|
if chat_type == ChatType.GROUP:
|
|
return f"agent:main:imessage:group:{chat_guid}:{account_id}"
|
|
|
|
if pinned_dm_owner:
|
|
clean_owner = pinned_dm_owner.replace("+", "").replace("-", "").replace(" ", "")
|
|
return f"agent:main:imessage:dm:{clean_owner}:{account_id}"
|
|
|
|
clean_phone = channel_user_id.replace("+", "").replace("-", "").replace(" ", "")
|
|
return f"agent:main:imessage:dm:{clean_phone}:{account_id}"
|
|
|
|
|
|
def resolve_chat_type(chat_guid: str) -> ChatType:
|
|
if ";-;" in chat_guid or "@chat" in chat_guid:
|
|
return ChatType.GROUP
|
|
return ChatType.DIRECT
|