Building a Production-Ready Bulk SMS Service with Node.js, Express, and Plivo - code-examples -

Frequently Asked Questions

Use the provided Node.js/Express application and the Plivo Node.js SDK. The application interacts with the Plivo API to send messages efficiently to large recipient lists via an API endpoint. Make sure to configure your Plivo credentials, sender ID, and API key in the .env file and install the necessary npm dependencies.
Plivo's documented limit for destination numbers per API call is 1000. The provided Node.js code handles lists larger than this limit by implementing intelligent batching within the sendBulkSms function.
Promise.allSettled is used to handle concurrent batch sending. It ensures that the application waits for all batch sending promises to resolve or reject, providing a robust way to track the success or failure of each batch regardless of individual outcomes.
For very large recipient lists (e.g., 10,000+), processing sendBulkSms directly in the API request handler can lead to timeouts. A background job queue like BullMQ or RabbitMQ is recommended to handle these large lists asynchronously and prevent blocking the main thread.
Yes, using Plivo's delivery report webhooks. The Node.js application includes a webhook endpoint (/api/webhooks/plivo/delivery-report) to receive and process these updates. You'll need to implement database integration to persist and track the status updates effectively.
Create a .env file in the project root and add your PLIVO_AUTH_ID, PLIVO_AUTH_TOKEN, and PLIVO_SENDER_ID. Obtain these from your Plivo account dashboard. Never commit this file to version control.
The API_KEY is crucial for securing the /api/bulk-sms endpoint. The provided auth.js middleware ensures that only requests with the correct API key can access this endpoint, preventing unauthorized use.
Use the validateWebhookSignature function in plivoService.js. This function handles the signature verification process, ensuring that incoming webhooks are indeed from Plivo and haven't been tampered with.
Only set PLIVO_WEBHOOK_SECRET if you've configured a separate webhook secret in your Plivo application settings. If you're using the default (your Plivo Auth Token), you don't need to set this variable, and the code will default to using PLIVO_AUTH_TOKEN.
The 'url' parameter specifies the webhook URL where Plivo will send delivery report updates. Ensure this URL is publicly accessible (e.g., using ngrok for local development). The provided code dynamically constructs the URL using API_BASE_URL.
The sendBulkSms function automatically splits the recipient list into batches of 1000 (Plivo's limit) and sends each batch concurrently using sendBulkSmsBatch.
A 207 Multi-Status response from the /api/bulk-sms endpoint indicates that the request was processed, but some batches failed during submission to Plivo. Check the server logs for details on the failed batches.
Robust validation of recipient phone numbers (using E.164 format checking) is essential to prevent sending messages to incorrect numbers, improve deliverability, and avoid wasting resources on invalid numbers.