Overview#
Outbound campaigns allow you to upload a list of leads and have the system automatically call them sequentially with personalized context.Architecture#
1.
User creates campaign with CSV of leads
2.
User starts campaign (status → scheduled)
3.
Edge Function processes first lead
4.
Call happens via LiveKit droplet
5.
When call ends, database trigger fires
6.
Trigger calls Edge Function to process next lead
7.
Repeat until all leads processed
Next.js UI: Campaign creation, management, monitoring
Supabase Database: Campaigns, leads, triggers
Supabase Edge Function: Campaign processing logic
LiveKit Droplet: Call execution
Setup Instructions#
1. Deploy Edge Function#
In Supabase Dashboard → Settings → Edge Functions:DROPLET_INTERNAL_URL: Your LiveKit droplet URL (e.g., http://142.93.xxx.xxx:8082)
DROPLET_INTERNAL_KEY: Your droplet internal authentication key
Run these SQL commands in Supabase SQL Editor:4. Optional: Cron Backup#
For extra reliability, add a cron job:Dashboard → Integrations → Cron:Name: process-campaigns-backup
URL: https://YOUR_PROJECT_REF.supabase.co/functions/v1/process-campaign
{
"Authorization": "Bearer YOUR_SERVICE_ROLE_KEY",
"Content-Type": "application/json"
}
Body: Check all active campaigns (requires Edge Function modification)
Campaign Lifecycle#
draft → Campaign being created
scheduled → Active, will process leads during time window
paused → Manually paused by user
completed → All leads processed
pending → Waiting to be called
calling → Call in progress
completed → Call finished successfully
failed → Call failed or errored
Monitoring#
Check Campaign Stats:
Query the campaigns table for completed_leads, failed_leads, and total_leads.Debug Stuck Campaigns:
Check last_lead_processed_at - if older than 5 minutes and status is scheduled, campaign may be stuck.Troubleshooting#
Campaigns not processing:1.
Check Edge Function deployment: supabase functions list
2.
Verify database settings: SELECT name, setting FROM pg_settings WHERE name LIKE 'app.%';
3.
Check Edge Function logs for errors
4.
Verify droplet is accessible from Supabase
2.
Verify organization has active phone number and SIP trunk
3.
Verify organization has sufficient balance
4.
Check Edge Function logs for detailed error
1.
Verify campaign timezone is correct
2.
Check schedule_start_time and schedule_end_time format (HH:MM:SS)
3.
Edge Function logs will show "Outside time window" message
Modified at 2026-03-17 10:59:50