Skip to content

Routing

InboundRoomRouter

Bases: ABC

Route an inbound message to a room (or None for auto-create).

route abstractmethod async

route(channel_id, channel_type, participant_id=None, channel_data=None, *, organization_id=None, identity=None)

Return room_id for the message, or None to create a new room.

participant_id is the address naming the message's conversation (Channel.conversation_address): the sender's, or on a chat channel the chat it was posted in; None for a message with no address, its sender empty or blank and no chat. channel_data is the message's metadata.

organization_id is the organization the caller acts for (RFC §17.2), None when the call names none. identity is the one the store resolves participant_id to within that organization (resolve_identity), read by the framework once per message before the first route, or None: the router and the check made when the sender is recorded name the sender alike (RFC §10.4).

The answer is held to RFC §10.1 step 2's rules whoever gave it: a room of another organization than organization_id fails the message (RoomNotFoundError), and a room id the store lacks is created under that id. An override must accept both keywords; the framework passes them on every call.

DefaultInboundRoomRouter

DefaultInboundRoomRouter(store, *, channel_of=None)

Bases: InboundRoomRouter

Default router (RFC §10.4): the sender's own room, then a channel bound to a single conversation that is open to the sender, else None.

Returns None rather than choosing when the message could belong to more than one room. A new room is recoverable; a message delivered into someone else's conversation is not — it is stored there, broadcast to that room's channels, and read back as context by that room's agent.

RoomFilter

Bases: BaseModel

Which rooms a routing lookup reads (RFC §14.1): the statuses and the organization.

Used with :meth:ConversationStore.find_room_id_by_binding, :meth:ConversationStore.find_room_id_by_participant and :meth:ConversationStore.find_room_ids_by_channel. An empty filter reads every room.

statuses class-attribute instance-attribute

statuses = None

Only the rooms in one of these statuses. None reads every status; the default router's step 1 reads ACTIVE and PAUSED rooms (RFC §10.4).

organization_id class-attribute instance-attribute

organization_id = None

Only the rooms of this organization (RFC §17.2). None reads every room, as a call that names no organization does.

admits

admits(room)

Whether room is one the filter reads.