Inbox & Channels Module Specification
1. Purpose & Overview
The and modules deliver realtime multi-agent chat inbox functionality over WebSockets powered by Django Channels and Redis Channel Layer.
inboxchannels2. Responsibilities
- Manage WebSocket connection lifecycle (,
connect,disconnect) viareceive.InboxConsumer - Route messages across agent connections in group .
inbox_<tenant_id> - Provide live unread count updates and agent typing indicators.
3. Directory Structure
text
services/api/inbox/
├── consumers.py
├── routing.py
├── views.py
└── tests/
4. Models & Database Schemas
- Uses and
messaging.Conversationmodels for data persistence.messaging.Message
5. Services & Business Logic
- : Authenticates user, extracts
InboxConsumer.connect(), and subscribes socket to Redis grouptenant_id.inbox_<tenant_id> - : Unsubscribes socket from Redis group.
InboxConsumer.disconnect() - : Utility service for sending events to all tenant agents.
broadcast_event(tenant_id, event_type, payload)
6. Serializers & Data Transfer Objects
- Realtime WebSocket JSON Frames: ,
new_message,message_status_update.unread_count_update
7. Views & API Endpoints
- WebSocket Endpoint:
/ws/inbox/<tenant_id>/ - : Retrieve active agent counts and chat queue length.
GET /api/inbox/stats/
8. Permissions & Role Rules
- Operators must be authenticated and belong to the specified in the URL path.
tenant_id
9. Signals & Event Listeners
- Receives events from and
messagingmodules for instant broadcasting.webhooks
10. Background Tasks & Celery Jobs
- None (WebSocket consumer operations run asynchronously on Daphne event loop).
11. Data Flow & External Dependencies
- Relies on for Redis Pub/Sub backend.
channels_redis.core.RedisChannelLayer
12. Business Rules & Validations
- WebSockets disconnect automatically if Redis connection times out or authentication fails.
13. Sequence Diagram (Mermaid)
Rendering diagram...
14. Known Limitations & Technical Debt
- Requires active Redis instance ().
CHANNEL_REDIS_URL
15. Future Improvements
- Add agent collision detection (visual indicator showing when another agent is viewing or typing a reply to the same customer).