wakit
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

  1. A user sends a WhatsApp message to your number
  2. Meta sends a webhook event to the whatsapp-webhook Edge Function
  3. The function parses the message and inserts it into the messages table
  4. A conversation is created or updated automatically
  5. 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:

TypeDescription
textPlain text message
imagePhoto with optional caption
videoVideo with optional caption
audioVoice note or audio file
documentPDF, DOC, etc.
stickerStatic or animated sticker
locationGPS coordinates
contactsShared contact cards
reactionEmoji reaction to a message
interactiveButton 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.

On this page