curl -X POST https://api.magpipe.ai/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"
}'
const response = await fetch(
'https://api.magpipe.ai/functions/v1/webhook-chat-message',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
widget_key: 'wgt_a1b2c3d4e5f6789012345678',
message: 'Hi, I have a question about your services',
visitor_id: 'v_abc123def456',
page_url: window.location.href
}),
}
);
const { session_id, aiResponse } = await response.json();
console.log('AI:', aiResponse);
// Use session_id for subsequent messages
import requests
response = requests.post(
'https://api.magpipe.ai/functions/v1/webhook-chat-message',
headers={
'Content-Type': 'application/json',
},
json={
'widget_key': 'wgt_a1b2c3d4e5f6789012345678',
'message': 'Hi, I have a question about your services',
'visitor_id': 'v_abc123def456',
'page_url': 'https://example.com/pricing'
}
)
data = response.json()
print(f"AI: {data['aiResponse']}")
{
"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"
}
{
"error": {
"code": "widget_not_found",
"message": "Widget not found or inactive"
}
}
Chat Widget
Send Chat Message
Send a message to a chat widget session
POST
/
webhook-chat-message
curl -X POST https://api.magpipe.ai/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"
}'
const response = await fetch(
'https://api.magpipe.ai/functions/v1/webhook-chat-message',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
widget_key: 'wgt_a1b2c3d4e5f6789012345678',
message: 'Hi, I have a question about your services',
visitor_id: 'v_abc123def456',
page_url: window.location.href
}),
}
);
const { session_id, aiResponse } = await response.json();
console.log('AI:', aiResponse);
// Use session_id for subsequent messages
import requests
response = requests.post(
'https://api.magpipe.ai/functions/v1/webhook-chat-message',
headers={
'Content-Type': 'application/json',
},
json={
'widget_key': 'wgt_a1b2c3d4e5f6789012345678',
'message': 'Hi, I have a question about your services',
'visitor_id': 'v_abc123def456',
'page_url': 'https://example.com/pricing'
}
)
data = response.json()
print(f"AI: {data['aiResponse']}")
{
"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"
}
{
"error": {
"code": "widget_not_found",
"message": "Widget not found or inactive"
}
}
Send a visitor message to a chat session and receive an AI response. This endpoint is used by the embeddable chat widget.
Request Body
Response
curl -X POST https://api.magpipe.ai/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"
}'
const response = await fetch(
'https://api.magpipe.ai/functions/v1/webhook-chat-message',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
widget_key: 'wgt_a1b2c3d4e5f6789012345678',
message: 'Hi, I have a question about your services',
visitor_id: 'v_abc123def456',
page_url: window.location.href
}),
}
);
const { session_id, aiResponse } = await response.json();
console.log('AI:', aiResponse);
// Use session_id for subsequent messages
import requests
response = requests.post(
'https://api.magpipe.ai/functions/v1/webhook-chat-message',
headers={
'Content-Type': 'application/json',
},
json={
'widget_key': 'wgt_a1b2c3d4e5f6789012345678',
'message': 'Hi, I have a question about your services',
'visitor_id': 'v_abc123def456',
'page_url': 'https://example.com/pricing'
}
)
data = response.json()
print(f"AI: {data['aiResponse']}")
{
"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"
}
{
"error": {
"code": "widget_not_found",
"message": "Widget not found or inactive"
}
}
Real-time Updates
Chat messages are delivered in real-time via Supabase Realtime. Subscribe to thechat_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();