This guide covers both Sandbox (Testing) and Production (Live) setups for Twilio WhatsApp integration in your Hawkins fraud detection system.
Best for: Testing the approval flow without Twilio setup
- In Supabase Dashboard → Project Settings → Edge Functions → Secrets
- Add secret:
Key: ENABLE_WHATSAPP_DEV_MODE Value: true - Redeploy the
send-whatsapp-approvaledge function - ✅ WhatsApp approvals will be simulated (no real messages sent)
Best for: Testing real WhatsApp messages before production
- Create Twilio Account at console.twilio.com
- Copy your credentials from the Console homepage:
- Account SID:
AC...(starts with AC) - Auth Token: Click "Show" to reveal
- Account SID:
- Navigate to WhatsApp Sandbox:
- Go to Messaging → Try it out → Send a WhatsApp message
- Or direct link: WhatsApp Sandbox
- Send WhatsApp message from your phone to: +1 415 523 8886
- Message content:
join [your-sandbox-code]- Your sandbox code is shown in Twilio Console
- Example:
join capital-evening
- Wait for confirmation: You'll receive a message saying you've joined
- ✅ Now WhatsApp messages can be sent to your number
-
Go to Supabase Dashboard → Your Project → Project Settings → Edge Functions → Secrets
-
Add these three secrets:
Key: TWILIO_ACCOUNT_SID Value: YOUR_TWILIO_ACCOUNT_SID_HERE Key: TWILIO_AUTH_TOKEN Value: YOUR_TWILIO_AUTH_TOKEN_HERE Key: TWILIO_WHATSAPP_NUMBER Value: +14155238886⚠️ CRITICAL FORMAT RULES:- ✅ Correct:
+14155238886(with + prefix, NO "whatsapp:" prefix) - ❌ Wrong:
whatsapp:+14155238886(this will cause errors) - ❌ Wrong:
14155238886(missing + prefix)
- ✅ Correct:
-
Redeploy the
send-whatsapp-approvaledge function:supabase functions deploy send-whatsapp-approval
- In your Hawkins app → Customer Dashboard
- Click "Quick Transaction" and submit a test transaction
- You should receive a WhatsApp message on the phone that joined the sandbox
- Reply:
YES ITSMEto approve orNOto decline - ✅ The transaction should update based on your response
Best for: Production deployments with your own WhatsApp Business number
- Verified business (Facebook Business Manager)
- Business documents ready
- WhatsApp Business API approval (1-3 business days)
- In Twilio Console: Messaging → Senders → WhatsApp senders
- Click: "Request Access" for WhatsApp Business API
- Provide business information:
- Business name and website
- Business category
- Business address
- Upload business documents:
- Business registration documents
- Tax ID or business license
- Submit for review (typically 1-3 business days)
- After approval, you'll receive a WhatsApp Business number (e.g.,
+1234567890) - This number must be:
- Not currently used with WhatsApp
- Owned by your business
- Able to receive SMS verification codes
-
Go to Supabase Dashboard → Project Settings → Edge Functions → Secrets
-
Update these secrets:
Key: TWILIO_ACCOUNT_SID Value: YOUR_TWILIO_ACCOUNT_SID_HERE Key: TWILIO_AUTH_TOKEN Value: YOUR_TWILIO_AUTH_TOKEN_HERE Key: TWILIO_WHATSAPP_NUMBER Value: +1234567890 (your approved WhatsApp Business number)⚠️ FORMAT RULES:- ✅ Use your approved business number with + prefix
- ✅ Do NOT include "whatsapp:" prefix
- ✅ Example:
+12025551234
-
Remove dev mode (if previously set):
- Delete
ENABLE_WHATSAPP_DEV_MODEsecret
- Delete
-
Redeploy the edge function:
supabase functions deploy send-whatsapp-approval
Cause: Incorrect TWILIO_WHATSAPP_NUMBER format
Fix:
- Check Supabase Edge Function secrets
- Ensure format is:
+14155238886(NO "whatsapp:" prefix) - Must include
+at the start - Redeploy edge function after fixing
Cause: Invalid Twilio credentials
Fix:
- Verify Account SID starts with
AC - Re-copy Auth Token from Twilio Console (click "Show")
- Check for typos or extra spaces
- Update in Supabase secrets and redeploy
Cause: Haven't joined Twilio sandbox OR sandbox expired
Fix for Sandbox:
- Send WhatsApp message:
join [code]to +1 415 523 8886 - Wait for confirmation message
- Sandbox expires after 72 hours of inactivity - rejoin if needed
Fix for Production:
- Complete WhatsApp Business API approval in Twilio Console
- Use your approved WhatsApp Business number
- Update TWILIO_WHATSAPP_NUMBER with approved number
Check:
- ✅ Joined Twilio sandbox (for testing)
- ✅ Phone number format correct:
+[country_code][number] - ✅ Edge function secrets correctly configured
- ✅ Edge function redeployed after secret changes
- ✅ Check Supabase Edge Function logs for errors
- Twilio account created
- Joined WhatsApp sandbox by messaging +1 415 523 8886
- TWILIO_ACCOUNT_SID configured in Supabase
- TWILIO_AUTH_TOKEN configured in Supabase
- TWILIO_WHATSAPP_NUMBER set to
+14155238886 - Edge function redeployed
- Test transaction sent and WhatsApp message received
- WhatsApp Business API approved by Twilio
- WhatsApp Business number assigned
- TWILIO_ACCOUNT_SID configured in Supabase
- TWILIO_AUTH_TOKEN configured in Supabase
- TWILIO_WHATSAPP_NUMBER set to approved business number
- ENABLE_WHATSAPP_DEV_MODE deleted (if previously set)
- Edge function redeployed
- Test transaction sent to production number
- ✅ Messages only work with numbers that joined sandbox
- ✅ Message shows "sent from unverified business"
- ✅ Sandbox expires after 72 hours of inactivity
- ✅ Limited to 1 message per 24 hours per number
- ✅ Send to any WhatsApp number worldwide
- ✅ Verified business badge displayed
- ✅ No message limits
- ✅ Custom business name shown as sender
- Twilio Documentation: WhatsApp API Docs
- Supabase Docs: Edge Functions
- Check Supabase Logs: Project → Edge Functions → Logs
- Twilio Console: Check SMS logs for delivery status
- Never commit Twilio credentials to git
- Use Supabase secrets for credential storage
- Rotate Auth Token regularly (every 90 days)
- Enable Two-Factor Authentication on Twilio account
- Monitor usage in Twilio Console to detect unauthorized access
- No charge for sandbox testing
- Limited functionality
- Only pre-approved numbers
- WhatsApp Business API: $0.005 - $0.02 per message (varies by country)
- Conversation-based pricing (24-hour windows)
- Free tier: First 1,000 conversations per month
Check current pricing: Twilio WhatsApp Pricing
Your setup is working correctly when:
- ✅ Customer receives WhatsApp message within 5 seconds of transaction
- ✅ Reply "YES ITSME" updates transaction status to approved
- ✅ Reply "NO" updates transaction status to declined
- ✅ 60-second timer stops when reply received
- ✅ No errors in Supabase Edge Function logs
- Complete WhatsApp Business API approval
- Get your production WhatsApp Business number
- Update
TWILIO_WHATSAPP_NUMBERin Supabase secrets - Remove
ENABLE_WHATSAPP_DEV_MODE(if set) - Redeploy edge function
- Test with production number
- ✅ Your users no longer need to "join" anything!