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.Optional order ID if conversation is about a specific order
Optional store ID for direct store messaging
The system automatically determines conversation type based on:
- If
storeIdandorderIdare 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.Conversation ID to send message to
Message content
Type of message being sent
Image attachment details (required for image messages)
Mark Messages as Read
Mark messages as read in a conversation.Conversation ID
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.Conversation ID to archive
Delete Message
Delete a message (soft delete - marks as deleted but preserves for audit).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.Conversation ID
Whether user is currently typing
Get Conversations
Retrieve user’s conversations with pagination.Filter by conversation status (default: active conversations)
Maximum number of conversations to return (default: 50)
Get Conversation Details
Get detailed information about a specific conversation.Conversation ID to get details for
Get Messages
Retrieve messages from a conversation with pagination.Conversation ID to get messages from
Maximum number of messages to return (default: 50)
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.Conversation ID to get typing indicators for
Can Chat with Store
Check if a customer can start a direct conversation with a store.Store ID to check chat eligibility for
Customers can only chat with stores if:
- Direct messaging is enabled globally
- Store has direct messaging enabled
- 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
Conversation not found
Conversation not found
Status Code:
404Conversation blocked
Conversation blocked
Status Code:
403Image validation failed
Image validation failed
Status Code:
400The chat system includes automatic notifications for new messages and supports both customer-to-store and customer-to-admin conversations with seamless transfer capabilities.
