Sending MMS with NestJS and AWS Pinpoint - code-examples -

Frequently Asked Questions

Use NestJS with the AWS Pinpoint SMS and Voice API v2 and Amazon S3. Create a NestJS API endpoint to handle requests, upload media to S3, and send MMS via Pinpoint. This setup enables your application to send rich media content to users.
AWS Pinpoint SMS and Voice API v2 is the service used to send SMS and MMS messages. The v2 version specifically provides the `SendMediaMessage` capability, which allows you to send multimedia content.
NestJS provides a structured and efficient way to build server-side applications. Its modular architecture, dependency injection, and TypeScript support make it a robust choice for integrating with AWS services.
Use a bucket policy when you need to grant read access to your S3 bucket for AWS Pinpoint without making objects public. This is a more secure way to manage access control than relying on ACLs for every single object.
Yes, the provided DTO uses international format validation (E.164) for phone numbers. Ensure your AWS Pinpoint Origination Identity is configured for international messaging if needed.
Store your AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION) securely in a `.env` file. Then, use NestJS's `ConfigModule` to load these variables into your application, avoiding hardcoding and improving testability.
Amazon S3 stores the media files (images, videos) that are attached to your MMS messages. The NestJS application uploads the media to S3 and then provides the S3 URI to Pinpoint for sending.
AWS Pinpoint needs access to the media files stored in S3 to include them in the MMS messages. This is managed via a bucket policy, which is a secure way to control access without making your files public.
Use the `FileInterceptor` from `@nestjs/platform-express` to intercept and process the incoming media file. Combine this with `ParseFilePipe` and validators like `FileTypeValidator` and `MaxFileSizeValidator` to ensure only valid files are accepted.
You'll need `sms-voice:SendMediaMessage` to send MMS via Pinpoint, `s3:PutObject` to upload media to S3, and potentially `s3:PutObjectAcl` depending on how you manage S3 access control.
Implement error handling for both S3 upload and Pinpoint sending operations. Catch AWS SDK errors, log them with stack traces, and throw appropriate HTTP exceptions. Consider using a custom exception filter to standardize error responses.
Create separate modules for AWS interactions (AwsModule) and MMS logic (MmsModule). Use services to encapsulate logic and controllers to expose API endpoints. This provides a clean and maintainable structure.
You'll need Node.js, an AWS account with proper IAM permissions, AWS CLI (optional), NestJS CLI, an MMS-capable phone number or short code registered with AWS Pinpoint, and a basic understanding of TypeScript, NestJS, and REST APIs.
Although not covered in the initial setup, consider implementing a database schema (e.g., using TypeORM or Prisma) to log MMS send attempts, status, and responses. This enables better tracking, analysis, and auditing.