ForcePilot/backend/package/yuxi/channel/extensions/tlon/session.py

25 lines
965 B
Python
Raw Normal View History

from yuxi.channel.extensions.tlon.types import TlonTarget, TlonTargetKind
def resolve_tlon_outbound_session_route(target: TlonTarget, account_ship: str,
account_id: str) -> dict:
if target.kind == TlonTargetKind.DM:
return {
"peer": {"kind": "direct", "id": target.ship},
"chat_type": "direct",
"from": f"tlon:dm:{target.ship}",
"to": f"tlon:dm:{target.ship}",
"session_key": f"tlon:dm:{account_id}:{target.ship}",
}
else:
return {
"peer": {"kind": "group", "id": target.nest},
"chat_type": "group",
"from": f"tlon:group:{target.nest}",
"to": f"tlon:group:{target.nest}",
"session_key": f"tlon:group:{account_id}:{target.nest}",
}
def build_session_key(account_id: str, chat_type: str, peer_id: str) -> str:
return f"tlon:{chat_type}:{account_id}:{peer_id}"