Frequently Asked Questions
Use the Vonage SMS API with the Node.js SDK and Express. Create a POST endpoint that accepts the recipient's number and message, then use the SDK to send the SMS via Vonage's servers. The provided tutorial includes a step-by-step guide and code examples to get you started quickly.
The Vonage SMS API enables sending text messages programmatically from your applications. This guide specifically shows how to use the API with API Key and Secret authentication for sending outbound SMS messages from a Node.js backend.
Dotenv helps manage sensitive credentials like API keys and secrets by storing them in a '.env' file. This prevents accidentally committing these credentials to version control, enhancing security.
Use vonage.sms.send()
when sending SMS messages with API Key and Secret authentication in the Vonage Node.js SDK. This method is suitable for straightforward SMS sending scenarios, as described in this guide.
The example provided in the tutorial sends to one recipient at a time. For sending to multiple recipients, you would need to loop through an array of numbers or adapt the API call within the SDK if it provides batch sending functionalities.
First, create a project directory and initialize a Node.js project with npm. Install express
, @vonage/server-sdk
, and dotenv
. Create index.js
, .env
, and .gitignore
files. Then, configure Vonage credentials and virtual number in the .env
file.
Express.js provides the web server framework for creating the API endpoint that receives requests to send SMS messages. It handles routing the /send-sms
request to the logic that interacts with the Vonage SMS API.
The provided code example demonstrates error handling by checking the 'status' field in the Vonage API response. A status of '0' signifies success, while other codes indicate errors, which are then handled appropriately.
During the trial period of a Vonage account, you must whitelist the recipient phone numbers for testing. Add the recipient's number to your approved test numbers in the Vonage dashboard to prevent the 'Non-Whitelisted Destination' error.
Log in to your Vonage API Dashboard, where the API Key and Secret are usually displayed on the main page or under 'API settings'. Copy these values for use in your application.
A Vonage virtual number serves as the sender ID for your SMS messages. You need a Vonage number to send SMS from, which you can obtain from the Vonage dashboard. Make sure it's in the correct format, such as +14155552671.
After starting your Node.js server, test the /send-sms
endpoint with tools like curl
or Postman. Send a POST request with the recipient's number and message in JSON format. Verify the response and check if the recipient received the SMS.
This error occurs when you're using a trial Vonage account and the recipient number isn't whitelisted. Ensure the recipient's number is added to your approved test numbers in the Vonage dashboard.
Double-check your Vonage API key and secret in your .env
file for typos, making sure they match what's in your Vonage Dashboard. Ensure the .env
file is loaded correctly using require('dotenv').config()
early in your Node.js code.
Building Production-Ready SMS Marketing Campaigns with Plivo, Node.js, and Vite (React/Vue)
This comprehensive guide walks you through building a complete SMS marketing campaign system using the Plivo SMS API, Node.js for the backend, and Vite with React or Vue for the frontend dashboard. You'll learn how to manage contacts, create campaigns, schedule bulk sends, track analytics, handle opt-outs, and maintain compliance with TCPA regulations.
Project Overview and Goals
Goal: Create a full-stack SMS marketing platform that enables businesses to manage campaigns, segment audiences, schedule bulk messages, track engagement metrics, and maintain regulatory compliance.
Problem Solved: Addresses the challenges of managing large subscriber lists, coordinating campaign schedules, tracking delivery and engagement, preventing spam complaints, ensuring TCPA/GDPR compliance, and providing a user-friendly interface for campaign management.
Technologies Used:
Backend:
plivo
): Official SDK for interacting with Plivo's SMS APIFrontend:
System Architecture:
Expected Outcome: A complete SMS marketing platform featuring:
Prerequisites:
+14155550100
)1. Setting Up the Project
Backend Setup
Create Project Structure:
Install Backend Dependencies:
Key dependencies explained:
plivo
: Official Plivo Node.js SDK (documentation)typeorm
+pg
: ORM and PostgreSQL driver for database operationsbullmq
+ioredis
: Queue system for reliable bulk message processingcsv-parser
+multer
: CSV contact import functionalitydate-fns
: Date manipulation for campaign schedulingInitialize TypeScript:
Configure
tsconfig.json
:Create Backend Folder Structure:
Project structure:
Configure Environment Variables (.env):
IMPORTANT: According to TCPA regulations, messages must not be sent before 8 AM or after 9 PM in the recipient's local time zone to avoid violations (penalties up to $1,500 per message).
Update package.json Scripts:
Frontend Setup
Create Vite Project with React or Vue:
For React:
For Vue:
Install Frontend Dependencies:
Configure Tailwind CSS:
Update
tailwind.config.js
:Add to
src/index.css
:Frontend Folder Structure:
2. Configuring Database and Plivo
Database Setup
Create Database Entities:
src/entities/Contact.ts
:src/entities/Campaign.ts
:src/entities/Message.ts
:src/entities/OptOut.ts
:Initialize Database Connection:
src/config/database.ts
:Plivo Service Implementation
src/services/PlivoService.ts
:3. Implementing Campaign Management Backend
Campaign Service with Queue Integration
src/services/CampaignService.ts
:BullMQ Queue Worker
src/queues/SmsQueue.ts
:Campaign Controller
src/controllers/CampaignController.ts
:4. TCPA Compliance and Opt-Out Management
According to TCPA regulations enforced by the FCC, businesses must:
Penalties for violations range from $500 to $1,500 per message (source).
Opt-Out Handler
src/services/OptOutService.ts
:Webhook Handler for Inbound Messages
src/controllers/WebhookController.ts
:5. Frontend Implementation (React with Vite)
API Client Setup
frontend/src/services/api.ts
:Campaign Dashboard Component
frontend/src/components/CampaignDashboard.tsx
:Campaign Creation Form
frontend/src/components/CampaignForm.tsx
:Contact Import Component
frontend/src/components/ContactImport.tsx
:6. Security Considerations
Rate Limiting
Implement rate limiting to prevent API abuse:
Data Encryption
.env
files to version controlInput Validation
TCPA Compliance Measures
7. Testing the Application
Backend Testing
Test endpoints with curl:
Frontend Testing
Access the application at
http://localhost:5173
Integration Testing
8. Deployment
Environment Configuration
Production .env:
Backend Deployment (Docker)
Dockerfile
:Frontend Deployment (Vercel/Netlify)
Build command:
Configure environment variable:
Database Migrations
Monitoring and Logging
9. Troubleshooting
Common Issues
Message Delivery Failures:
^\+[1-9]\d{1,14}$
TCPA Violations:
CampaignController
to require "STOP" keywordQueue Processing Delays:
MAX_MESSAGES_PER_SECOND
in.env
redis-cli ping
Plivo Authentication Errors:
curl -u AUTH_ID:AUTH_TOKEN https://api.plivo.com/v1/Account/AUTH_ID/
Database Connection Failures:
psql -h localhost -U postgres -d sms_campaigns
Conclusion
You have successfully built a production-ready SMS marketing campaign platform using Plivo, Node.js, and Vite with React/Vue. This system includes:
✅ Full-stack architecture with Express backend and modern frontend ✅ Campaign management with scheduling and segmentation ✅ Contact management with CSV import and tagging ✅ Reliable bulk messaging using BullMQ queue system ✅ TCPA compliance with opt-out management and quiet hours ✅ Real-time analytics and delivery tracking ✅ Scalable infrastructure ready for production deployment
Key Compliance Reminders:
Next Steps:
Resources:
This foundation provides everything needed to build a compliant, scalable SMS marketing platform that respects user privacy while delivering effective campaigns.