Skip to main content

Overview

The Chat System API provides comprehensive messaging functionality for customer support, including direct messaging between customers and stores, admin support, typing indicators, and message management. Location: convex/shared/chat.ts

Real-time Messaging

Instant messaging with typing indicators and read receipts

Image Support

Send images with automatic validation and compression

Conversation Management

Create, archive, and manage conversations between users

Admin Support

Built-in admin support system with conversation transfer

Create or Get Conversation

Create a new conversation or get existing one for customer support.
orderId
Id<'orders'>
Optional order ID if conversation is about a specific order
storeId
Id<'stores'>
Optional store ID for direct store messaging
The system automatically determines conversation type based on:
  • If storeId and orderId are provided and customer has orders with store → customer_to_store
  • Otherwise → customer_to_admin

Send Message

Send a text or image message in a conversation.
conversationId
Id<'conversations'>
required
Conversation ID to send message to
content
string
required
Message content
messageType
'text' | 'image'
required
Type of message being sent
imageAttachment
object
Image attachment details (required for image messages)

Mark Messages as Read

Mark messages as read in a conversation.
conversationId
Id<'conversations'>
required
Conversation ID
messageIds
Array<Id<'messages'>>
Specific message IDs to mark as read (optional - marks all unread if not provided)

Archive Conversation

Archive a conversation to remove it from active conversations.
conversationId
Id<'conversations'>
required
Conversation ID to archive

Delete Message

Delete a message (soft delete - marks as deleted but preserves for audit).
messageId
Id<'messages'>
required
Message ID to delete
Only the message sender can delete their own messages. Admins can delete any message.

Update Typing Status

Update user’s typing status in a conversation for real-time indicators.
conversationId
Id<'conversations'>
required
Conversation ID
isTyping
boolean
required
Whether user is currently typing

Get Conversations

Retrieve user’s conversations with pagination.
status
'active' | 'archived' | 'closed'
Filter by conversation status (default: active conversations)
limit
number
Maximum number of conversations to return (default: 50)

Get Conversation Details

Get detailed information about a specific conversation.
conversationId
Id<'conversations'>
required
Conversation ID to get details for

Get Messages

Retrieve messages from a conversation with pagination.
conversationId
Id<'conversations'>
required
Conversation ID to get messages from
limit
number
Maximum number of messages to return (default: 50)
cursor
string
Pagination cursor for loading more messages

Get Unread Count

Get total unread message count for the authenticated user.

Get Typing Indicators

Get current typing indicators for a conversation.
conversationId
Id<'conversations'>
required
Conversation ID to get typing indicators for

Can Chat with Store

Check if a customer can start a direct conversation with a store.
storeId
Id<'stores'>
required
Store ID to check chat eligibility for
Customers can only chat with stores if:
  1. Direct messaging is enabled globally
  2. Store has direct messaging enabled
  3. Customer has at least one non-cancelled order with the store

Get Chat Settings

Get current chat system settings.

Real-time Integration

The chat system supports real-time updates through Convex subscriptions:

Message Types

The system supports various message types:

Text Messages

Standard text messages with full UTF-8 support

Image Messages

Images with automatic validation and compression

System Messages

Automated system notifications and updates

Transfer Notices

Messages indicating conversation transfers

Error Handling

Status Code: 404
Status Code: 403
Status Code: 403
Status Code: 400
The chat system includes automatic notifications for new messages and supports both customer-to-store and customer-to-admin conversations with seamless transfer capabilities.
Use typing indicators sparingly to avoid overwhelming the system. Consider debouncing typing status updates.