Complete Twilio WhatsApp Setup Guide

BIBLE-Compliant Messaging for FleetOS

This guide gets real WhatsApp messages flowing through Twilio, integrated with company-owned architecture.


🎯 What You're Building

Fleet creates request β†’ Supplier company gets WhatsApp notification
                    ↓
           Supplier replies "ACK" β†’ Status updates to acknowledged
                    ↓
           Fleet company gets notification β†’ "Supplier acknowledged"

Key Features:

  • βœ… Company-owned notifications (org-first routing)

  • βœ… WhatsApp replies update database (2-way messaging)

  • βœ… Magic links in messages (1-click access)

  • βœ… No individual user dependency (BIBLE-compliant)


πŸ“‹ Prerequisites

  1. Twilio Account (Free trial: https://www.twilio.com/try-twilio)

  2. Supabase Project (Already set up)

  3. WhatsApp-enabled phone (For testing)


Part 1: Twilio Setup (15 minutes)

Step 1.1: Create Twilio Account

  1. Go to: https://www.twilio.com/try-twilio

  2. Sign up with email

  3. Verify your phone number

  4. Note your trial credit ($15.00 free)

Step 1.2: Enable WhatsApp Sandbox

Twilio Console β†’ Messaging β†’ Try it out β†’ Try WhatsApp

  1. You'll see a WhatsApp sandbox number: +1 415 523 8886

  2. Copy the sandbox code (e.g., join yellow-tiger)

  3. On your phone:

    • Open WhatsApp

    • Send message to: +1 415 523 8886

    • Message: join yellow-tiger (use YOUR code)

  4. You should get confirmation: "Sandbox: βœ… You are all set!"

Step 1.3: Get Credentials

Twilio Console β†’ Account Info

Copy these! You'll need them in the next section.


Part 2: Supabase Configuration (10 minutes)

Step 2.1: Install Supabase CLI

Step 2.3: Set Twilio Secrets

Verify secrets:

Should show:

  • TWILIO_ACCOUNT_SID

  • TWILIO_AUTH_TOKEN

  • TWILIO_WHATSAPP_FROM


Part 3: Deploy Edge Functions (5 minutes)

Step 3.1: Deploy Send Function

Expected output:

Step 3.2: Deploy Webhook Function

Expected output:

Step 3.3: Test Send Function

Check your phone! You should get a WhatsApp message.


Part 4: Configure Twilio Webhook (5 minutes)

Step 4.1: Set Incoming Message Webhook

Twilio Console β†’ Messaging β†’ Settings β†’ WhatsApp Sandbox Settings

  1. "When a message comes in" field:

  2. Method: POST

  3. Content Type: application/x-www-form-urlencoded

  4. Click Save

Step 4.2: Test Incoming Webhook

From your phone (WhatsApp):

Send to +1 415 523 8886:

You should get back:

βœ… Webhook is working!


Part 5: Hook Up to Service Requests (10 minutes)

Step 5.1: Add Notification to Request Creation

File: services/shared/QueryService.ts

Find createServiceRequest() method and add after insert:

Step 5.2: Test End-to-End Flow

  1. Create test supplier with phone number:

  2. Create test request via dashboard or API

  3. Check your phone! You should get WhatsApp notification

  4. Reply "ACK" β†’ Check database, status should update to 'acknowledged'


Part 6: Production Setup (Future)

Get Real WhatsApp Business Number

Twilio Console β†’ Messaging β†’ Senders β†’ WhatsApp senders β†’ Request to enable my Twilio numbers for WhatsApp

  1. Fill business info form

  2. Submit for approval (1-3 days)

  3. Get dedicated WhatsApp number (e.g., +1 555 123 4567)

  4. Update secret:

Cost: ~$1/month + $0.005 per message


πŸ§ͺ Testing Checklist

βœ… Outgoing Messages

βœ… Incoming Messages

βœ… End-to-End Flow


πŸ› Troubleshooting

"Twilio not configured on server"

Solution:

"No routing target available"

Solution:

  • Company needs at least one contact with phone or email

  • Check contacts table has record for company

  • Check contact_value matches phone number exactly

"Unknown phone number" from webhook

Solution:

Webhook not receiving messages

Solution:

  1. Check Twilio webhook URL is correct

  2. Test webhook directly:

  3. Check Supabase function logs:

    • Go to Supabase Dashboard β†’ Edge Functions β†’ whatsapp-webhook β†’ Logs


πŸ“Š Architecture Overview


πŸŽ“ Key Concepts

Company-Owned Work (BIBLE Architecture)

  • Work belongs to COMPANIES, not individual users

  • Notifications route to ORG first (last-active fallback)

  • Any org member can act on any work

  • Emergency access always works

  • Org-scoped (not user-scoped)

  • Include companyId and rfqId in token

  • Valid for 7 days (org links) or 1 hour (RFQ links)

  • No login required

Two-Way Messaging

  • Outgoing: Python/Node β†’ Supabase β†’ Twilio β†’ WhatsApp

  • Incoming: WhatsApp β†’ Twilio β†’ Supabase β†’ Database

  • Commands parsed: ACK, ACCEPT, DECLINE, HELP


Services:

  • services/WhatsAppService.ts - Frontend WhatsApp wrapper

  • services/NotificationService.ts - Org-level routing logic

  • services/RFQNotificationService.ts - RFQ-specific notifications

  • services/shared/QueryService.ts - Database operations

Edge Functions:

  • supabase/functions/send-whatsapp/index.ts - Outgoing messages

  • supabase/functions/whatsapp-webhook/index.ts - Incoming webhook

Documentation:

  • docs/FLEETOS_ROUTING_ACCESS_BIBLE.md - Routing principles

  • docs/FLEETOS_FUNDAMENTAL_DECISION.md - Company-owned architecture

  • docs/setup/WHATSAPP_BACKEND_QUICKSTART.md - Original quick start


βœ… Success Criteria

You've successfully set up WhatsApp when:

  1. βœ… Twilio credentials configured in Supabase

  2. βœ… Edge functions deployed and working

  3. βœ… Can send test WhatsApp message

  4. βœ… Webhook receives and processes replies

  5. βœ… Service request creation triggers notification

  6. βœ… Reply "ACK" updates database status

  7. βœ… Everything is BIBLE-compliant (org-first routing)


Questions? Check:

  • Twilio logs: https://console.twilio.com/us1/monitor/logs/whatsapp

  • Supabase logs: https://supabase.com/dashboard/project/bsbjwjpgiangjqqqxota/functions

  • Edge function logs: Supabase Dashboard β†’ Edge Functions β†’ Logs


Created: 2026-01-09 Status: Ready to implement Architecture: BIBLE-compliant (company-owned + org-first routing)

Last updated

Was this helpful?