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

18 lines
645 B
Python
Raw Normal View History

from yuxi.channels.models import ChannelIdentity, ChannelType
from yuxi.channels.adapters.signal.normalize import normalize_e164
def resolve_thread(identity: ChannelIdentity, agent_id: str = "main") -> str:
chat_id = identity.channel_chat_id
channel_type = identity.channel_type
if channel_type != ChannelType.SIGNAL:
raise ValueError(f"Unexpected channel type: {channel_type}")
if chat_id.startswith("group:"):
group_id = chat_id.removeprefix("group:")
return f"agent:{agent_id}:signal:group:{group_id}"
normalized = normalize_e164(chat_id)
return f"agent:{agent_id}:signal:dm:{normalized}"