Developer Guide: Sending Plivo MMS with Fastify and Node.js - code-examples -

Frequently Asked Questions

Your Plivo Auth ID and Auth Token are found on your Plivo console dashboard after you log in. These credentials are essential for authenticating with the Plivo API.
Use the Plivo Node.js SDK with a web framework like Fastify. This allows you to create a server-side application that can handle MMS sending requests via the Plivo API. Make sure to set up your Plivo account and configure the necessary credentials in your project.
Fastify is a high-performance Node.js web framework known for its speed and plugin ecosystem. The tutorial uses it for its efficiency and features like built-in request validation and easy route handling.
Dotenv helps manage environment variables, allowing you to store sensitive information like API keys outside your codebase. This improves security and makes it easier to manage different environments (development, production).
Use npm or yarn. Install `fastify`, `plivo`, and `dotenv` as core dependencies. For development, `pino-pretty` is recommended for enhanced logging. Run `npm install fastify plivo dotenv` or `yarn add fastify plivo dotenv`, and similarly for dev dependencies.
The `.env` file securely stores your Plivo Auth ID, Auth Token, sender number, host, and port. This keeps sensitive credentials out of your codebase, enhancing security.
Create directories for source code (`src`), routes (`src/routes`), and place your main application file (`app.js`) in `src`. Routes are defined in files within `src/routes`. Also, include `.env`, `.env.example`, and `.gitignore` files in the root.
You need a Plivo phone number with MMS capabilities enabled, typically available for the US and Canada. Purchase one from the Plivo console and confirm MMS is enabled.
The provided code example uses `try...catch` blocks and checks for `PlivoResponseError` to handle errors. You can provide specific responses depending on the error code returned by the Plivo API.
The tutorial uses `@fastify/rate-limit` to implement rate limiting. The default example configuration limits to 100 requests per minute per IP, which is customizable.
Rate limiting helps prevent abuse and protects your Plivo account balance by controlling the number of MMS messages sent within a specific time window.
Use `curl` to send test requests to your local Fastify server. Provide valid JSON data with recipient number, media URLs, and message text in the request body.
A successful response will return a 200 OK status code with a JSON body including the message, messageUuid (an array of UUIDs), and apiId.
It means Plivo has accepted your request and queued the message for sending. It doesn't guarantee delivery; for that, implement status callbacks.
The tutorial provides troubleshooting for authentication errors, invalid numbers, media URL issues, rate limiting, and other potential Plivo API errors. Refer to the article for more details.