Webhooks & Realtime
SendHub.ai provides real-time data through Supabase Realtime โ subscribe to database changes and react instantly.
Subscribe to Events
// All new messages in a workspace
const channel = sendhub
.channel('my-inbox')
.on('postgres_changes', {
event: 'INSERT',
schema: 'public',
table: 'messages',
filter: `business_id=eq.${workspaceId}`,
}, (payload) => {
const msg = payload.new
console.log(`${msg.direction}: ${msg.content}`)
})
.subscribe()
// Clean up
sendhub.removeChannel(channel)
Available Events
| Table | Event | Use case |
|---|---|---|
messages | INSERT | New message received or sent |
messages | UPDATE | Delivery status changed (sent โ delivered โ read) |
conversations | INSERT | New conversation started |
conversations | UPDATE | Status or assignment changed |
contacts | INSERT | New contact created |
contacts | UPDATE | Contact details or tags changed |
Filtering
Scope subscriptions with the filter parameter:
// Only inbound messages
filter: 'direction=eq.inbound'
// Specific conversation
filter: `conversation_id=eq.${convoId}`
// Specific workspace
filter: `business_id=eq.${workspaceId}`
WhatsApp Status Webhooks
For Business API channels, WhatsApp delivery status updates (sent, delivered, read) are received via webhook and automatically update delivery_status on messages. No configuration needed.