Campaigns Setup
Technical setup guide for deploying the outbound campaigns infrastructure with Edge Functions and database triggers.
Overview
Outbound campaigns allow you to upload a list of leads and have the system automatically call them sequentially with personalized context.
Architecture
Flow:
- User creates campaign with CSV of leads
- User starts campaign (status →
scheduled) - Edge Function processes first lead
- Call happens via LiveKit droplet
- When call ends, database trigger fires
- Trigger calls Edge Function to process next lead
- Repeat until all leads processed
Components:
- 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
cd supabase
supabase functions deploy process-campaign2. Configure Environment Variables
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
3. Configure Database
Run these SQL commands in Supabase SQL Editor:
-- Set Edge Function URL (replace YOUR_PROJECT_REF)
ALTER DATABASE postgres SET app.supabase_functions_url = 'https://YOUR_PROJECT_REF.supabase.co/functions/v1';
-- Set service role key (from Dashboard → Settings → API)
ALTER DATABASE postgres SET app.supabase_service_role_key = 'eyJh...';
-- Verify
SELECT name, setting FROM pg_settings WHERE name LIKE 'app.%';4. Optional: Cron Backup
For extra reliability, add a cron job:
Dashboard → Integrations → Cron:
- Name:
process-campaigns-backup - Schedule:
*/2 * * * * - Type: HTTP Request
- Method: POST
- URL:
https://YOUR_PROJECT_REF.supabase.co/functions/v1/process-campaign - Headers:
{ "Authorization": "Bearer YOUR_SERVICE_ROLE_KEY", "Content-Type": "application/json" } - Body: Check all active campaigns (requires Edge Function modification)
Campaign Lifecycle
Status Flow:
draft→ Campaign being createdscheduled→ Active, will process leads during time windowpaused→ Manually paused by usercompleted→ All leads processed
Lead Status Flow:
pending→ Waiting to be calledcalling→ Call in progresscompleted→ Call finished successfullyfailed→ Call failed or errored
Monitoring
View Edge Function Logs:
supabase functions logs process-campaign --tailCheck 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:
- Check Edge Function deployment:
supabase functions list - Verify database settings:
SELECT name, setting FROM pg_settings WHERE name LIKE 'app.%'; - Check Edge Function logs for errors
- Verify droplet is accessible from Supabase
Calls not initiating:
- Check droplet logs
- Verify organization has active phone number and SIP trunk
- Verify organization has sufficient balance
- Check Edge Function logs for detailed error
Time window not working:
- Verify campaign timezone is correct
- Check
schedule_start_timeandschedule_end_timeformat (HH:MM:SS) - Edge Function logs will show "Outside time window" message