Developer Guide: Sending Plivo MMS with NestJS - code-examples -

Frequently Asked Questions

Integrate the Plivo Node.js SDK into your NestJS application. Create a Plivo service to handle API interactions, a controller with a POST endpoint, and a DTO for request validation. This allows you to securely send MMS messages using Plivo's robust infrastructure.
The Plivo Node.js SDK simplifies interaction with the Plivo REST API within a NestJS application. It provides convenient methods to send MMS messages, manage phone numbers, and other Plivo functionalities, streamlining the integration process.
NestJS provides a structured, modular architecture with dependency injection and TypeScript support, making it ideal for building robust and maintainable applications that interact with external APIs like Plivo.
Use `media_urls` when your media (images, GIFs) are publicly accessible via URLs. Use `media_ids` if you've pre-uploaded media to Plivo's servers, referencing their unique identifiers. Uploading to Plivo first is useful for private or larger media files.
Plivo generally allows around 2MB per media file and a maximum of 10 attachments per message. Supported types include common image formats like JPEG, PNG, and GIF. Check Plivo's official documentation for the most current limits and supported media types, as these can change.
Create a `.env` file in your project root and store your Plivo Auth ID, Auth Token, and sender number. Import and configure the `@nestjs/config` module in your `app.module.ts` to load these variables securely. Add `.env` to your `.gitignore` file.
Create a Data Transfer Object (DTO) and use `class-validator` decorators (e.g., `@IsPhoneNumber`, `@IsUrl`) to define validation rules. Apply the `ValidationPipe` in your controller or globally to automatically validate incoming requests.
Implement a `try...catch` block around your Plivo API calls in the service. Log the error details and throw a NestJS exception (e.g., `InternalServerErrorException`) to handle errors gracefully without exposing sensitive information to the client.
The 202 Accepted status code signifies that the request to send the MMS has been accepted and is being processed asynchronously. It does not guarantee immediate delivery but confirms that the message is queued for sending.
Yes, using libraries like `async-retry` can help implement retry logic with exponential backoff. This improves the reliability of MMS delivery by handling transient network or API issues.
Plivo primarily offers MMS for US and Canadian numbers. Support for other countries may be limited or result in fallback to SMS. Verify Plivo's documentation for the latest list of supported countries.
Leverage NestJS's asynchronous nature, initialize the Plivo client once, and avoid blocking operations. While caching is less applicable to sending, it could help with related tasks like user profile retrieval if required.
Use environment variables for credentials, input validation with `ValidationPipe`, and implement rate limiting with `@nestjs/throttler`. If your API is public, add authentication/authorization using Guards.
Trial accounts usually restrict MMS sending to verified numbers in your Plivo sandbox. Ensure you have added the recipient numbers to your verified list within the Plivo console.