Build Production-Ready SMS/MMS Marketing Campaigns with Next.js, Node.js, and Plivo - code-examples -

Frequently Asked Questions

Build a Next.js application with API routes to handle campaign creation and a Node.js worker process using BullMQ to manage the message queue. This worker interacts with the Plivo API to send messages based on jobs added to the queue, ensuring reliable delivery even with large recipient lists. The provided guide details project setup, implementation, and deployment steps.
BullMQ is used as a robust message queue system built upon Redis. It handles the potentially time-consuming task of sending numerous SMS/MMS messages reliably and without blocking the main application thread. This ensures scalability and prevents message loss due to server issues or API limitations.
Prisma, a next-generation ORM (Object-Relational Mapper), simplifies database management within the Node.js/TypeScript backend. It provides type-safe database queries, schema migrations, and efficient database operations, facilitating easier interaction with the PostgreSQL database used in this project.
The application's API endpoint accepts a `scheduledAt` parameter during campaign creation. This parameter expects an ISO 8601 formatted date-time string. If provided, the campaign's messages will be queued in BullMQ with a delay, processed by the worker at the specified future time.
Redis functions as the in-memory data store backing the BullMQ message queue. It ensures efficient and reliable storage of queued message jobs until they are processed and sent by the worker. Its speed and persistence make it ideal for handling asynchronous tasks like sending messages.
The system includes an `OptOut` model in the database to record opted-out phone numbers. Before sending any message, the application checks the recipient number against this list to ensure compliance and prevent unwanted messages. The implementation details are provided in the article's API endpoint section.
Install the `plivo-node` SDK and initialize the Plivo client in a helper function. In the BullMQ job worker, use the Plivo client to create and send SMS/MMS messages based on the queued job data which includes recipient numbers and message content. The guide provides setup and implementation code snippets.
Install Node.js and NPM, create a Next.js project, install dependencies like 'plivo-node', 'prisma', 'bullmq', configure environment variables with Plivo and database credentials, and set up local database instances using Docker. The provided article outlines each step in detail.
Basic message statuses (e.g., SENT, FAILED) are tracked for each recipient in the database. The guide also includes a section on implementing webhooks to receive more detailed statuses like DELIVERED/UNDELIVERED from Plivo if you want real-time updates directly from Plivo.
Whenever your SMS sending volume is large enough that sending each message individually within the request cycle could lead to timeouts or performance issues, a message queue like BullMQ is highly recommended. It allows the system to process the requests asynchronously, improving performance and reliability.
Yes, this system supports sending MMS (multimedia) messages. You can add an array of media URLs to the request data and the Plivo client will send them as an MMS message. The `mediaUrls` field in the `Campaign` and `SmsJobData` structures enables MMS handling.
The article provides a database schema that includes an `OptOut` table. The implementation of adding numbers to this table is not explicitly covered in the article, but typically would involve creating an API endpoint or interface to record opt-out requests from users (e.g., SMS reply with 'STOP', web form).
This project leverages Next.js for the frontend and API routes, Node.js for the runtime, Plivo for sending SMS/MMS, Prisma for database interaction with PostgreSQL, Redis with BullMQ for message queuing, and optional tools like Tailwind CSS for styling and Docker for local development.