Chat API
The LuxMart Chat API provides real-time communication between stores and admin support via WebSocket connections and REST endpoints.
Overview
The chat system allows stores to initiate support sessions with admins, send and receive messages in real-time, and manage chat sessions.
Features
- Real-time Communication: WebSocket-based bidirectional messaging
- Session Management: Create and manage chat sessions
- Admin Assignment: Admins can claim and manage multiple store conversations
- Typing Indicators: See when the other party is typing
- Message Read Receipts: Track message read status
- Notifications: Admins receive notifications for new messages
Chat Components
WebSocket Connections
- Store WebSocket: Real-time messaging for stores
- Admin WebSocket: Real-time messaging for admins
REST Endpoints
Store Endpoints
- Get Session: Get or create a chat session
- Send Message: Send a message (also available via WebSocket)
Admin Endpoints
- Get Open Sessions: List all unclaimed sessions
- Get My Sessions: List sessions claimed by the admin
- Get Session: Get detailed session info with messages
- Claim Session: Claim an open session
- Close Session: Close a claimed session
- Send Message: Send a message (also available via WebSocket)
- Get Notifications: Get all notifications
- Get Notification Count: Get unread notification count
- Mark Notification Read: Mark a notification as read
- Mark All Notifications Read: Mark all notifications as read
Shared Endpoints
- Upload Attachment: Upload file attachments for chat
- Mark Messages as Read: Mark all messages in a session as read
Chat Models
ChatSession
{
"id": 1,
"store_id": 5,
"admin_id": 2,
"status": "active",
"created_at": "2025-12-16T10:00:00Z",
"updated_at": "2025-12-16T10:30:00Z",
"store": {
"id": 5,
"name": "Tech Store",
"logo_url": "https://example.com/logo.jpg",
"email": "store@example.com"
}
}
Status Values:
- open: Session created but not yet claimed by an admin
- active: Session is actively being handled by an admin
- closed: Session has been closed
ChatMessage
{
"id": 123,
"session_id": 1,
"sender_type": "store",
"content": "Hello, I need help with my account",
"is_read": false,
"created_at": "2025-12-16T10:15:00Z"
}
Sender Types:
- store: Message sent by the store
- admin: Message sent by an admin
ChatNotification
{
"id": 45,
"admin_id": 2,
"message_id": 123,
"session_id": 1,
"store_id": 5,
"store_name": "Tech Store",
"store_logo": "https://example.com/logo.jpg",
"content": "Hello, I need help...",
"is_read": false,
"created_at": "2025-12-16T10:15:00Z"
}
Typical Chat Flow
Store Initiating Chat
- Store calls GET /v1/chat/store/session/ to get or create a session
- Store connects to WebSocket:
ws://api.luxmart.site/v1/chat/ws/store/?token=<auth_token> - Store sends messages via WebSocket
- Store receives admin messages in real-time
Admin Handling Chat
- Admin connects to WebSocket:
ws://api.luxmart.site/v1/chat/ws/admin/?token=<auth_token> - Admin calls GET /v1/chat/admin/sessions/open/ to see available sessions
- Admin calls POST /v1/chat/admin/session/claim/ to claim a session
- Admin calls GET /v1/chat/admin/session/?session_id=
to load message history - Admin sends/receives messages via WebSocket
- Admin receives notifications for messages from stores when on other pages
Authentication
All chat endpoints and WebSocket connections require authentication:
REST Endpoints:
WebSocket Connections:
ws://api.luxmart.site/v1/chat/ws/store/?token=<auth_token>
ws://api.luxmart.site/v1/chat/ws/admin/?token=<auth_token>
Base URL
Production: https://api.luxmart.site/v1/chat/
Staging: https://api-staging.luxmart.site/v1/chat/
WebSocket: wss://api.luxmart.site/v1/chat/ws/
For development: