ForcePilot/backend/package/yuxi/channels/adapters/imessage/session.py

30 lines
967 B
Python
Raw Normal View History

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