Conversations
A conversation is a thread between a contact and your team on a specific channel. See Database Schema for the full column reference.
List Conversations
const { data } = await sendhub
.from('conversations')
.select(`
id, status, assigned_to, last_message_at,
contacts(id, name, phone, tags, avatar_url),
channels(label, phone_number, channel_type)
`)
.eq('business_id', workspaceId)
.order('last_message_at', { ascending: false })
Filter by Status
// AI-handled only
const { data } = await sendhub
.from('conversations')
.select('*, contacts(name, phone)')
.eq('status', 'ai_handling')
// Assigned to a specific team member
const { data } = await sendhub
.from('conversations')
.select('*, contacts(name)')
.eq('assigned_to', memberId)
// Resolved
const { data } = await sendhub
.from('conversations')
.select('*, contacts(name)')
.eq('status', 'resolved')
Assignment
// Assign to a team member
await sendhub
.from('conversations')
.update({ assigned_to: memberId, status: 'assigned' })
.eq('id', convoId)
// Return to AI
await sendhub
.from('conversations')
.update({ assigned_to: null, status: 'ai_handling' })
.eq('id', convoId)
// Resolve
await sendhub
.from('conversations')
.update({ status: 'resolved' })
.eq('id', convoId)
Real-time Updates
sendhub
.channel('conversations')
.on('postgres_changes', {
event: '*',
schema: 'public',
table: 'conversations',
filter: `business_id=eq.${workspaceId}`,
}, (payload) => {
console.log('Update:', payload.eventType, payload.new)
})
.subscribe()