Messages Module
The messages module provides the foundation for Chanx's structured message system, including base message
types, channel events, and standard message implementations.
Base Messages
- class chanx.messages.base.BaseMessage(*, action: Any, payload: Any)
Base message for all Chanx communications.
Use cases: - Incoming messages: Client to server WebSocket communication - Outgoing messages: Server to client responses and notifications - Channel events: Server to server communication via channel layer
All message types must define a unique 'action' field using a Literal type. Action values must be unique within each consumer for proper routing.
- action
Discriminator field identifying message type
- Type:
Any
- payload
Message data
- Type:
Any
Incoming Messages
- class chanx.messages.incoming.PingMessage(*, action: Literal['ping'] = 'ping', payload: None = None)
Simple ping message to check WebSocket connection status.
Outgoing Messages
- class chanx.messages.outgoing.PongMessage(*, action: Literal['pong'] = 'pong', payload: None = None)
Simple pong message response to ping requests.
- class chanx.messages.outgoing.ErrorMessage(*, action: Literal['error'] = 'error', payload: Any = None)
Error message for communicating issues to the client.
- payload
Error information dictionary with 'detail' field and optional error codes
- Type:
Any
- class chanx.messages.outgoing.AuthenticationPayload(*, status_code: int, status_text: str, data: Any = None)
Payload for authentication messages.
Contains status information about the authentication process.
- status_code
HTTP-like status code (e.g., 200 for success)
- Type:
int
- status_text
Human-readable status description
- Type:
str
- data
Additional authentication data
- Type:
Any
- class chanx.messages.outgoing.AuthenticationMessage(*, action: Literal['authentication'] = 'authentication', payload: AuthenticationPayload)
Authentication result message sent to the client.
Sent after connection authentication to inform client of the result.
- payload
AuthenticationPayload containing status details
- class chanx.messages.outgoing.CompleteMessage(*, action: Literal['complete'] = 'complete', payload: None = None)
Confirmation message indicating processing is complete.
Sent after a request has been fully processed to signal completion.
- class chanx.messages.outgoing.GroupCompleteMessage(*, action: Literal['group_complete'] = 'group_complete', payload: None = None)
Confirmation message indicating group message processing is complete.
Sent after a group message has been fully processed and distributed to all consumers in the group to signal completion of the group broadcast operation. This allows clients to know when all intended recipients have received the message.
- action
Literal string 'group_complete' as the discriminator value
- Type:
Literal['group_complete']
- class chanx.messages.outgoing.EventCompleteMessage(*, action: Literal['event_complete'] = 'event_complete', payload: None = None)
Confirmation message indicating event processing is complete.
Sent after a channel event has been fully processed to signal completion of the event handling operation. This allows clients to know when event processing has finished.
- action
Literal string 'event_complete' as the discriminator value
- Type:
Literal['event_complete']