Messages
Receive messages
How incoming WhatsApp messages are processed in wakit.
Incoming messages from WhatsApp are automatically processed and stored in the messages table. You don't need to do anything to receive them — the webhook handles everything.
Flow
- A user sends a WhatsApp message to your number
- Meta sends a webhook event to the
whatsapp-webhookEdge Function - The function parses the message and inserts it into the
messagestable - A conversation is created or updated automatically
- If an AI agent is active, it processes the message and responds
Query incoming messages
const { data } = await supabase
.from('messages')
.select('*')
.eq('organization_id', orgId)
.eq('direction', 'incoming')
.order('created_at', { ascending: false })
.limit(20);Query by conversation
const { data } = await supabase
.from('messages')
.select('*')
.eq('conversation_id', conversationId)
.order('created_at', { ascending: true });Real-time updates
Subscribe to new messages via Supabase Realtime:
const channel = supabase
.channel('messages')
.on(
'postgres_changes',
{
event: 'INSERT',
schema: 'public',
table: 'messages',
filter: `organization_id=eq.${orgId}`,
},
(payload) => {
console.log('New message:', payload.new);
}
)
.subscribe();Message content types
Incoming messages can be any WhatsApp type:
| Type | Description |
|---|---|
text | Plain text message |
image | Photo with optional caption |
video | Video with optional caption |
audio | Voice note or audio file |
document | PDF, DOC, etc. |
sticker | Static or animated sticker |
location | GPS coordinates |
contacts | Shared contact cards |
reaction | Emoji reaction to a message |
interactive | Button or list reply |
Media preprocessing
If media preprocessing is enabled (via the Integrations section), wakit automatically extracts information from media files using AI:
- Audio → transcription
- Images → description
- Video → description
- PDF/documents → text extraction
This is handled by the media-preprocessor Edge Function and uses the Google Gemini API.