Skip to main content
POST
https://mtxbiyilvgwhbdptysex.supabase.co/functions/v1
/
webhook-chat-message
curl -X POST https://mtxbiyilvgwhbdptysex.supabase.co/functions/v1/webhook-chat-message \
  -H "Content-Type: application/json" \
  -d '{
    "widget_key": "wgt_a1b2c3d4e5f6789012345678",
    "message": "Hi, I have a question about your services",
    "visitor_id": "v_abc123def456",
    "page_url": "https://example.com/pricing"
  }'
{
  "session_id": "e5f6a7b8-c9d0-1e2f-3a4b-567890cdef12",
  "aiResponse": "Hello! I'd be happy to help you learn about our services. What specific questions do you have?",
  "aiMessageId": "f6a7b8c9-d0e1-2f3a-4b5c-678901def234"
}
Send a visitor message to a chat session and receive an AI response. This endpoint is used by the embeddable chat widget.

Request Body

widget_key
string
required
The public widget key from your dashboard.
message
string
required
The visitor’s message content.
session_id
string
Existing chat session ID. Omit to create a new session.
visitor_id
string
Unique visitor identifier (e.g., from localStorage UUID).
visitor_name
string
Visitor’s name (if collected).
visitor_email
string
Visitor’s email (if collected).
page_url
string
The URL of the page where the chat was initiated.

Response

session_id
string
The chat session ID (use for subsequent messages).
aiResponse
string
The AI agent’s response message.
aiMessageId
string
Unique identifier for the AI response message.
curl -X POST https://mtxbiyilvgwhbdptysex.supabase.co/functions/v1/webhook-chat-message \
  -H "Content-Type: application/json" \
  -d '{
    "widget_key": "wgt_a1b2c3d4e5f6789012345678",
    "message": "Hi, I have a question about your services",
    "visitor_id": "v_abc123def456",
    "page_url": "https://example.com/pricing"
  }'
{
  "session_id": "e5f6a7b8-c9d0-1e2f-3a4b-567890cdef12",
  "aiResponse": "Hello! I'd be happy to help you learn about our services. What specific questions do you have?",
  "aiMessageId": "f6a7b8c9-d0e1-2f3a-4b5c-678901def234"
}

Real-time Updates

Chat messages are delivered in real-time via Supabase Realtime. Subscribe to the chat_messages table for instant updates:
const channel = supabase
  .channel('chat_messages')
  .on(
    'postgres_changes',
    { event: 'INSERT', schema: 'public', table: 'chat_messages' },
    (payload) => {
      console.log('New message:', payload.new);
    }
  )
  .subscribe();