Settings Reference¶
All package settings live under the REALTIME_CHAT_MESSAGING key in your
Django settings.py:
REALTIME_CHAT_MESSAGING = {
"MESSAGE_SOFT_DELETE": True,
"INACTIVITY_THRESHOLD": 300,
"SERIALIZERS": {
"MessageSerializer": "myapp.serializers.CustomMessageSerializer",
},
}
You only need to specify the keys you want to override. All other settings fall
back to their defaults. Dictionary settings (SERIALIZERS, MODELS) are
merged with defaults — you only specify the entries you are changing.
Behavioural Settings¶
MESSAGE_SOFT_DELETE¶
Type |
|
Default |
|
Controls how message deletion works.
False— deleted messages are permanently removed from the database.True— deleted messages haveis_deletedset toTrueand remain in the database. Soft-deleted messages are excluded fromroom.messagesqueries. This is useful for audit trails, message recovery, or analytics.
ENABLE_NOTIFICATION¶
Type |
|
Default |
|
Controls the ChatNotification system.
True— notifications are created for every message and dispatched to users on connection viachat.notifications.False— no notifications are created and thechat.notificationsevent is never sent.message.acknowledgedstill updatesdelivered_toon messages.
INACTIVITY_THRESHOLD¶
Type |
|
Default |
|
Unit |
seconds |
Sessions older than this value are considered expired and cleaned up. Clients
should send session.heartbeat events 2–3 times within this window (every
15–30 seconds for the default of 60). Adjust for your application’s expected idle
time:
REALTIME_CHAT_MESSAGING = {
"INACTIVITY_THRESHOLD": 300 # 5 minutes
}
WEBSOCKET_PATH¶
Type |
|
Default |
|
The URL path for WebSocket connections. Clients connect to
ws://<host>/<WEBSOCKET_PATH>. Change this to fit your URL structure:
REALTIME_CHAT_MESSAGING = {
"WEBSOCKET_PATH": "ws/chat/"
}
Pluggable Class Settings¶
All handler and consumer classes can be replaced with custom implementations by providing a dotted import path.
CHAT_CONSUMER_CLASS¶
Type |
|
Default |
|
The WebSocket consumer class. Replace with a subclass of
ChatMessagingConsumer to add custom event handlers or override existing ones.
See Custom Consumer.
EVENT_MAPPER¶
Type |
|
Default |
|
A callable that receives the consumer instance and returns a dict mapping
event type strings to handler methods. Override to add, remove, or remap events.
See Custom Consumer.
EVENT_HANDLER_CLASS¶
Type |
|
Default |
|
The business logic handler. Contains all room, message, session, and notification logic. Override specific methods to change default behaviour. See Custom Handlers.
PERMISSION_HANDLER_CLASS¶
Type |
|
Default |
|
The authorization handler. Implement custom permission rules by subclassing. See Custom Permissions.
EXCEPTION_HANDLER_CLASS¶
Type |
|
Default |
|
The exception handler class. Provides exception_handler_decorator used to
wrap all consumer methods. Override to add custom exception types or change error
formatting. Must expose a classmethod named exception_handler_decorator.
MODELS Dictionary¶
Override individual model classes. Each value is a dotted app_label.ModelName
string. You only need to specify models you are replacing.
REALTIME_CHAT_MESSAGING = {
"MODELS": {
"Message": "myapp.CustomMessage",
"ReadReceipt": "myapp.CustomReadReceipt",
}
}
Available model keys:
Key |
Default |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Note
Room is a polymorphic base model. You cannot swap it in the same way as
other models — all concrete room types inherit from it. See
Custom Models for extending room types.
SERIALIZERS Dictionary¶
Override individual serializer classes. Only specify the serializers you are replacing.
REALTIME_CHAT_MESSAGING = {
"SERIALIZERS": {
"MessageSerializer": "myapp.serializers.CustomMessageSerializer",
"UserSerializer": "myapp.serializers.UserSerializer",
}
}
Available serializer keys:
Key |
Default |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Complete Example¶
REALTIME_CHAT_MESSAGING = {
# Feature flags
"MESSAGE_SOFT_DELETE": True,
"ENABLE_NOTIFICATION": True,
"INACTIVITY_THRESHOLD": 120,
"WEBSOCKET_PATH": "ws/chat/",
# Custom models
"MODELS": {
"Message": "myapp.CustomMessage",
},
# Custom serializers
"SERIALIZERS": {
"MessageSerializer": "myapp.serializers.CustomMessageSerializer",
"UserSerializer": "myapp.serializers.ExtendedUserSerializer",
},
# Custom handlers
"EVENT_HANDLER_CLASS": "myapp.handlers.CustomEventHandler",
"PERMISSION_HANDLER_CLASS": "myapp.permissions.CustomPermissionHandler",
"CHAT_CONSUMER_CLASS": "myapp.consumers.CustomChatConsumer",
"EVENT_MAPPER": "myapp.events.custom_event_mapper",
}