Skip to content

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

REST Endpoints

Store Endpoints

Admin Endpoints

Shared Endpoints

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

  1. Store calls GET /v1/chat/store/session/ to get or create a session
  2. Store connects to WebSocket: ws://api.luxmart.site/v1/chat/ws/store/?token=<auth_token>
  3. Store sends messages via WebSocket
  4. Store receives admin messages in real-time

Admin Handling Chat

  1. Admin connects to WebSocket: ws://api.luxmart.site/v1/chat/ws/admin/?token=<auth_token>
  2. Admin calls GET /v1/chat/admin/sessions/open/ to see available sessions
  3. Admin calls POST /v1/chat/admin/session/claim/ to claim a session
  4. Admin calls GET /v1/chat/admin/session/?session_id= to load message history
  5. Admin sends/receives messages via WebSocket
  6. Admin receives notifications for messages from stores when on other pages

Authentication

All chat endpoints and WebSocket connections require authentication:

REST Endpoints:

Authorization: Token <your_token>

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:

API: http://localhost:8000/v1/chat/
WebSocket: ws://localhost:8000/v1/chat/ws/