Skip to main content

Prerequisites

  • Node.js 16+ installed
  • Supabase account (create one here)
  • WhatsApp Business API credentials
  • Basic knowledge of TypeScript/JavaScript

Step 1: Create Supabase Database

1.1 Create Project

  1. Go to Supabase Dashboard
  2. Click “New Project”
  3. Enter project name and database password
  4. Choose a region close to your users
  5. Click “Create new project”

1.2 Run SQL Schema

  1. Go to SQL Editor in your Supabase dashboard
  2. Click “New Query”
  3. Copy the entire content from /sql/supabase-schema.sql (located in the SDK repository)
  4. Paste and click “Run”
You should see:

1.3 Verify Tables Created

Run this query to verify:
Expected output:
  • whatsapp_messages
  • whatsapp_conversations

1.4 Get API Credentials

  1. Go to Settings → API
  2. Copy these values:
    • Project URL: https://xxxxx.supabase.co
    • Service Role Key (⚠️ NOT the anon/public key)
IMPORTANT: Use the Service Role Key, not the anon/public key. The service role key bypasses Row Level Security (RLS) and is only safe for backend/API routes.

Step 2: Install Dependencies

Or with yarn:

Step 3: Configure Environment Variables

Create a .env.local file (or .env for non-Next.js projects):

Step 4: Initialize SDK with Storage

Basic Setup

Verify Storage is Enabled


Step 5: Setup Webhooks with Storage

Next.js App Router Example

Create app/api/webhook/route.ts:

Express.js Example


Querying Stored Messages

See the Querying Data guide for detailed examples of:
  • Getting conversation history
  • Searching messages
  • Tracking message threads
  • Analyzing conversations
  • Exporting data
Quick example:

Troubleshooting

Storage Not Enabling

Problem: isStorageEnabled() returns false Solutions:
  1. Verify you’re using Service Role Key, not Anon Key
  2. Check tables exist
  3. Check initialization logs

Permission Errors

Problem: insert or update violates foreign key constraint Solution: Make sure autoConversations: true is enabled. This automatically creates conversations before saving messages.

Connection Errors

Problem: Failed to connect to Supabase Solutions:
  1. Verify URL is correct (should start with https://)
  2. Check API key is valid
  3. Test connection manually:

RLS (Row Level Security) Issues

If you get permission denied errors with Service Role Key:
For production, keep RLS enabled and use Service Role Key only in backend.

Best Practices

1. Security

  • ✅ Use Service Role Key only in backend/API routes
  • ✅ Never expose Service Role Key in frontend code
  • ✅ Use environment variables for all credentials
  • ✅ Add .env to .gitignore

2. Performance

  • ✅ Enable enableBuffer: true in webhook processor
  • ✅ Set appropriate bufferTimeMs (default: 5000ms)
  • ✅ Use retentionDays to auto-cleanup old data
  • ✅ Create indexes on frequently queried fields

3. Error Handling

4. Cleanup Resources


Schema Overview

whatsapp_messages Table

whatsapp_conversations Table


Next Steps

Query Messages

Learn how to query and search stored messages

Best Practices

Security, performance, and production tips

Custom Adapters

Build custom storage adapters for other databases

Webhook System

Learn more about webhook processing