ForcePilot/backend/package/yuxi/channel/extensions/imessage/session.py
Kris 4d52f634fe feat(imessage): 新增iMessage渠道插件完整实现
该提交新增了基于BlueBubbles的iMessage渠道插件,支持单聊和群组消息,包含文本、图片、语音、文件和视频消息收发,支持消息编辑、撤回、回复、 reactions和输入状态提示,同时实现了账号配置、安全校验、配对授权、消息格式化与分片等完整功能。
2026-05-21 10:50:15 +08:00

26 lines
1.1 KiB
Python

from __future__ import annotations
from yuxi.channel.extensions.imessage.targets import build_session_key
from yuxi.channel.message.models import PeerKind
from yuxi.channel.protocols import SessionResolution
class IMessageSessionAdapter:
def resolve_session(self, msg: object) -> SessionResolution:
if hasattr(msg, "sender") and hasattr(msg.sender, "kind"):
if msg.sender.kind == PeerKind.DIRECT:
sender_id = msg.sender.id if hasattr(msg.sender, "id") else "unknown"
return SessionResolution(kind="direct", conversation_id=sender_id)
gid = "unknown"
if hasattr(msg, "group") and msg.group:
gid = msg.group.id or "unknown"
return SessionResolution(kind="group", conversation_id=gid)
def build_dm_session_key(self, account_id: str, handle: str) -> str:
return build_session_key("imessage", account_id, "direct", handle)
def build_group_session_key(self, account_id: str, chat_guid: str) -> str:
return build_session_key("imessage", account_id, "group", chat_guid)