Developer Guide: Building SMS Marketing Campaigns with Fastify and Plivo - code-examples -

Frequently Asked Questions

Use the `/send` endpoint of the Fastify API, specifying the campaign ID. The API integrates with Plivo's SMS platform to dispatch messages to opted-in subscribers. This setup handles subscriber management, consent, and reliable message delivery using Fastify's efficient framework and Plivo's communication platform.
Fastify is a high-performance Node.js web framework used to build the backend API service for the SMS marketing application. It was chosen for its speed, extensibility, and developer-friendly features such as built-in validation and logging, which enhance the performance and maintainability of the application.
Plivo is a cloud communications platform that offers robust SMS API capabilities. It's integrated into the project for its reliable message delivery, easy-to-use developer tools, and scalability to handle potentially large volumes of messages.
Pino-pretty is best used during development. It formats logs for improved readability in the console. For production environments, standard JSON logging is preferred for structured logging, which is easier to parse by monitoring systems.
While the tutorial uses PostgreSQL, you could potentially adapt the project to use a different database. You'd need to adjust the Prisma schema and connection string in the `.env` file and might need to modify database interactions in the service layer if there are specific syntax differences.
First, create a Plivo account and obtain your Auth ID, Auth Token, and a Plivo phone number. Then, configure these credentials in the project's `.env` file. The Plivo SDK is used to send SMS messages via their API.
Prisma acts as an Object-Relational Mapper (ORM), simplifying interactions with the PostgreSQL database. It allows developers to work with database records as JavaScript objects, abstracting away complex SQL queries, improving code readability, and type safety.
Docker is used for containerizing the Fastify application, ensuring consistent deployment across different environments. This containerization approach makes the deployment process more predictable and manageable, whether deploying to a local server, a cloud platform, or other containerized environments.
The tutorial recommends using the latest Long-Term Support (LTS) version of Node.js. LTS versions offer stability, security, and ongoing support, which are essential for production applications. Use `node -v` to check your Node.js version.
The Fastify API exposes endpoints for subscriber management. `POST /api/v1/subscribers` creates a new subscriber, `GET /api/v1/subscribers` retrieves all subscribers, `GET /api/v1/subscribers/:id` retrieves a specific subscriber by ID, `PUT /api/v1/subscribers/:id/optin` updates the opt-in status, and `DELETE /api/v1/subscribers/:id` deletes a subscriber.
The application follows a client-server architecture where a client (e.g., a web interface) interacts with the Fastify API, which in turn communicates with the Plivo API for sending SMS messages. A PostgreSQL database stores subscriber and campaign data, providing persistence for the application.
The project uses the `libphonenumber-js` library for phone number validation and formatting. It ensures phone numbers are in the correct format (preferably E.164) and helps prevent issues with SMS delivery due to incorrect formatting.
Tracking consent is a legal requirement for SMS marketing in many jurisdictions (e.g., TCPA, GDPR). It allows you to send messages only to users who have explicitly agreed to receive them, promoting ethical and legal compliance.
Fly.io is suggested as a platform for deploying the full-stack application and database. While deployment details are not included in the provided article section, it is mentioned as a deployment option. It simplifies the deployment process.