SMS & WhatsApp Queue Processor: Automated Message Delivery via Twilio
Automate reliable SMS and WhatsApp message delivery with queue-based processing, intelligent channel routing, and comprehensive compliance logging via Twilio.
🎯 What This Workflow Does:
This robust n8n workflow processes queued messages every hour, automatically sending up to 50 SMS or WhatsApp messages per batch via Twilio's APIs. Messages are intelligently routed to the appropriate channel, logged for compliance, and rate-limited to prevent spam filters—providing a reliable, scalable messaging infrastructure for businesses of any size.
✨ Key Features:
Hourly Processing: Runs 24 times daily, delivering 1,200+ messages per day
Dual-Channel Support: SMS and WhatsApp routing in one workflow
Queue-Based Architecture: Reliable FIFO (First In, First Out) processing
Batch Processing: Handles up to 50 messages per execution
Intelligent Routing: Automatic SMS vs WhatsApp channel selection
Full Compliance Logging: Every message tracked in Supabase
Rate Limit Protection: 2-second delays prevent carrier spam filters
Twilio Integration: Industry-leading SMS and WhatsApp Business API
Error Handling: Failed messages remain in queue for retry
Cost Tracking: Log includes per-message cost data
Beginner-Friendly: 12+ detailed sticky notes explaining every component
📱 Channel Specifications:
SMS Features:
Traditional text messaging to any mobile number
160 characters per segment
98%+ deliverability rate
Global reach (190+ countries)
Works on all phones
Cost: ~$0.0075 per message (US)
WhatsApp Features:
Rich media support (images, documents, buttons)
Template-based notifications
Lower cost (~$0.005 per message)
Higher engagement rates
WhatsApp Business API required
Two-way conversations in 24-hour window
🔧 Technical Stack:
Trigger: Schedule (every hour, 24x daily)
Queue Management: Supabase Edge Functions
Database: Supabase (sms_queue, sms_log tables)
SMS Provider: Twilio SMS API
WhatsApp Provider: Twilio WhatsApp Business API
Authentication: HTTP Basic Auth (Twilio) + Header Auth (Supabase)
Rate Limiting: Wait node (2-second delays)
Logging: Supabase REST API
💡 Perfect For:
E-commerce: Order confirmations, shipping updates, delivery notifications
Healthcare: Appointment reminders, prescription notifications, test results
Financial Services: Transaction alerts, security codes, balance notifications
SaaS Companies: User onboarding, feature announcements, system alerts
Service Businesses: Booking confirmations, staff notifications, customer updates
Education: Class reminders, grade notifications, parent communications
Marketing: Promotional campaigns, flash sales, event invitations
🚀 What You Will Need:
Required Services:
Twilio account with verified phone number
Twilio WhatsApp Business API access (for WhatsApp)
Supabase account (free tier available)
Database tables: sms_queue, sms_log
Credentials:
Twilio Account SID
Twilio Auth Token
Twilio Phone Number (SMS)
Twilio WhatsApp Number (WhatsApp)
Supabase API Key
📈 Use Cases:
Transactional Notifications:
Order confirmations with order number and details
Shipping updates with tracking links
Payment receipts and invoices
Account security alerts (2FA codes)
Appointment Management:
Booking confirmations
24-hour reminders
Cancellation notifications
Reschedule options via WhatsApp buttons
Customer Communication:
Support ticket updates
Service request status
Feedback requests
Customer satisfaction surveys
Marketing Campaigns:
Flash sale announcements
New product launches
Exclusive offers to VIP customers
Event invitations with RSVP
Internal Operations:
Staff shift reminders
Emergency notifications
System alerts to admins
Delivery driver coordination
🎓 Beginner-Friendly Features:
Every node includes comprehensive sticky notes with:
Plain English explanations of queue processing
Channel comparison (SMS vs WhatsApp pros/cons)
Cost breakdowns per message type
Rate limiting logic explained clearly
Compliance requirements (TCPA, GDPR)
Database schema with example data
Twilio setup guide step-by-step
Troubleshooting tips for common issues
No prior messaging API experience required!
🔄 Workflow Process:
Schedule triggers every hour (top of the hour)
Fetches message queue from Supabase (up to 50 pending messages)
Splits messages into individual items for processing
Routes by channel using switch node:
SMS messages → Twilio SMS API
WhatsApp messages → Twilio WhatsApp API
Sends message via appropriate Twilio endpoint
Logs delivery with full metadata to sms_log table
Rate limits with 2-second delay before next message
Repeats for all messages in batch
Total batch time: ~1.7 minutes for 50 messages (well within hourly window)
📊 Expected Results:
Delivery Capacity:
50 messages per batch
24 batches per day
1,200 messages daily capacity
36,000 messages monthly capacity
Reliability:
Queue-based = no lost messages
Failed messages remain in queue
Automatic retry on next run
Full delivery tracking
Cost Efficiency:
SMS: $0.0075 × 1,000 = $7.50/month
WhatsApp: $0.005 × 1,000 = $5.00/month
Mixed: Average $6-7/month per 1,000 messages
No monthly fees, pay-as-you-go
Performance:
98%+ delivery rate (SMS)
95%+ open rate (WhatsApp)
<5 second delivery time
Real-time logging
🌟 Advanced Features:
Queue Management:
FIFO processing ensures order
Priority field for urgent messages
Scheduled_for field for future sends
Retry_count for failure tracking
Status tracking (pending/sent/failed)
Channel Intelligence:
Automatic routing based on channel field
Fallback from WhatsApp to SMS (optional enhancement)
Cost optimization (prefer WhatsApp when available)
Channel availability checking
Compliance & Logging:
Every message logged with timestamp
Phone number tracking
Delivery status recording
Cost per message tracked
Provider attribution
90-day retention for compliance
Rate Limiting Strategy:
2-second delays between messages
Prevents carrier spam filters
Respects Twilio rate limits
Customizable per use case
Batch size adjustable (50 default)
💰 Cost Analysis:
Twilio Pricing (US):
SMS: $0.0075 per outbound message
WhatsApp: $0.005 per business-initiated message
No monthly fees
Volume discounts available
Example Monthly Costs:
1,000 messages: $5-7.50
5,000 messages: $25-37.50
10,000 messages: $50-75
50,000 messages: $250-375
Compared to Alternatives:
Email: $0.001 per email (but lower engagement)
Push notifications: $0.0001 per push (limited to app users)
SMS/WhatsApp: Higher cost but 98% open rate vs 20% email
ROI Calculation:
SMS open rate: 98%
Email open rate: 20%
SMS is 5x more effective
Worth the 7.5x cost premium for critical messages
🔒 Compliance & Security:
Legal Requirements:
TCPA Compliance (US): Obtain prior express consent
GDPR (EU): Right to access, delete, and opt-out
CASL (Canada): Written or electronic consent required
Quiet Hours: Respect 9 AM - 9 PM local time
Best Practices:
Maintain opt-in records
Provide clear unsubscribe instructions
Honor opt-outs immediately
Keep message logs for 90+ days
Include business identification
Avoid deceptive content
Security Measures:
Twilio credentials in environment variables
Supabase API key secured
HTTPS for all API communications
Phone number encryption in database
Access logging for audit trails
Data Privacy:
Minimal PII storage
Secure credential management
Encrypted data transmission
Regular log cleanup
User consent tracking
📱 Message Queue Schema:
sms_queue table:
CREATE TABLE sms_queue (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
phone TEXT NOT NULL,
message TEXT NOT NULL,
channel TEXT CHECK (channel IN ('sms', 'whatsapp')),
status TEXT DEFAULT 'pending',
priority INTEGER DEFAULT 5,
scheduled_for TIMESTAMP DEFAULT NOW(),
retry_count INTEGER DEFAULT 0,
created_at TIMESTAMP DEFAULT NOW(),
updated_at TIMESTAMP DEFAULT NOW()
);
sms_log table:
sqlCREATE TABLE sms_log (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
message_id UUID REFERENCES sms_queue(id),
phone TEXT NOT NULL,
channel TEXT NOT NULL,
status TEXT NOT NULL,
provider TEXT NOT NULL,
cost NUMERIC(10,4),
sent_at TIMESTAMP DEFAULT NOW(),
delivered_at TIMESTAMP,
error_message TEXT
);
🎯 Integration Opportunities:
CRM Systems:
Salesforce: Trigger messages on deal stages
HubSpot: Send follow-ups after form submissions
Pipedrive: Notify on pipeline changes
E-commerce Platforms:
Shopify: Order and shipping notifications
WooCommerce: Abandoned cart reminders
Magento: Customer communication automation
Booking Systems:
Calendly: Appointment confirmations
Acuity: Reminder notifications
Square: Payment receipts
Support Tools:
Zendesk: Ticket status updates
Freshdesk: Support notifications
Intercom: Customer messages
🔧 Customization Options:
Adjust Frequency:
Every 30 minutes for faster delivery
Every 2-3 hours for lower volume
Custom schedule based on business hours
Batch Size:
Increase to 100 messages for high volume
Decrease to 25 for tighter rate limiting
Dynamic sizing based on queue length
Channel Selection:
Auto-fallback from WhatsApp to SMS
Cost optimization (prefer cheaper channel)
User preference detection
Geographic availability checking
Error Handling:
Automatic retry with exponential backoff
Max retry limit (e.g., 3 attempts)
Failed message notifications
Dead letter queue for permanent failures
📊 Monitoring & Analytics:
Key Metrics to Track:
Messages sent per hour/day/month
Delivery success rate
Channel distribution (SMS vs WhatsApp)
Average cost per message
Failed message rate
Queue processing time
Peak usage hours
Dashboard Queries:
sql-- Daily message volume
SELECT DATE(sent_at), channel, COUNT(*), SUM(cost)
FROM sms_log
WHERE sent_at > NOW() - INTERVAL '30 days'
GROUP BY DATE(sent_at), channel;
-- Delivery success rate
SELECT
channel,
COUNT(*) as total,
SUM(CASE WHEN status = 'sent' THEN 1 ELSE 0 END) as delivered,
ROUND(100.0 SUM(CASE WHEN status = 'sent' THEN 1 ELSE 0 END) / COUNT(), 2) as success_rate
FROM sms_log
GROUP BY channel;
🚀 Scaling Considerations:
High Volume (10K+ messages/day):
Reduce trigger interval to 15-30 minutes
Increase batch size to 100-200 messages
Request higher Twilio rate limits
Consider dedicated short code (SMS)
Implement message prioritization
Global Reach:
Multiple Twilio phone numbers per region
Currency and cost tracking per country
Timezone-aware scheduling
Language-specific templates
Reliability Improvements:
Implement webhook for delivery receipts
Automatic retry logic with backoff
Monitoring and alerting
Fallback SMS provider