Frequently Asked Questions
Integrate Sinch's MMS capabilities into your RedwoodJS app by setting up a project, configuring Sinch credentials, creating backend services and GraphQL mutations, and developing a frontend to handle user input and media URLs. This allows sending rich media content alongside text messages using Sinch's infrastructure. Refer to the step-by-step guide for detailed instructions and code examples.
The Sinch Conversation API is a unified interface for sending various types of messages, including MMS, across different channels. This guide uses it to send multimedia messages (text and images) from a RedwoodJS web application, leveraging Sinch's communication platform. It simplifies the process of integrating messaging features into your applications.
Node-fetch version 2 offers better compatibility with RedwoodJS's common CommonJS setup, making integration simpler. While RedwoodJS can support the ESM modules used by node-fetch v3+, version 2 provides a robust solution without the added complexity of ESM configurations.
Securely store your Sinch credentials (Project ID, App ID, Access Key, Access Secret, MMS Number, and Region URL) as environment variables in a .env file in your RedwoodJS project root. Ensure you never commit this file to version control. Restart your RedwoodJS dev server for changes to take effect.
The user interacts with the RedwoodJS frontend, triggering a GraphQL mutation. This mutation is received by the RedwoodJS API side, which calls a library function to interact with the Sinch Conversation API. Optionally, the API logs transaction details via Prisma. Sinch processes the request and delivers the MMS.
The @requireAuth directive is recommended within your SDL for security. It ensures only authenticated users can trigger your sendMms mutation. Modify or remove this directive only if you use custom authentication not managed by standard Redwood Auth.
The API side receives GraphQL mutations, calls the Sinch library function to send messages, and optionally logs messages to the database via Prisma. It manages the interaction between the frontend and the Sinch API, handling authentication, data processing, and logging.
Yes, the guide demonstrates optional logging to a database using Prisma. A MessageLog model is created to store details like recipient, sender, message content, Sinch message ID, and status. This logging capability aids in tracking message delivery and troubleshooting.
The provided lib/sinch.ts function parses error messages from the Sinch API and logs them. These errors are propagated up to the service and then to the frontend as part of the mutation response, facilitating error handling and display to the user. Consider adding retry mechanisms for specific errors.
Common errors include invalid credentials (401 Unauthorized), malformed requests (400 Bad Request), and number provisioning issues. Issues with the media URL, such as inaccessibility or incorrect format, can also cause errors. Always refer to the Sinch documentation for comprehensive error codes and solutions.
The guide provides basic E.164 format validation, but for production, consider using dedicated libraries like Zod or Yup within your service. Enforce strict validation on both frontend and backend to prevent unexpected behavior and security risks. Ensure the number starts with a '+'.
Sinch's servers need to directly access the image URL to include it in the MMS message. Private or internal network URLs are inaccessible to Sinch and will result in delivery failures. Always use a publicly accessible image URL.
Crucially, never commit your .env file to version control. Use your hosting provider's environment variable management in production. Implement robust input validation, use the @requireAuth directive or equivalent authorization, and consider rate limiting on the API endpoint to prevent abuse.
MMS delivery can sometimes experience delays. Consult Sinch's logs and dashboard for message submission status and details. If delays persist, contact Sinch support for assistance. Consider adding retry mechanisms within your application for improved reliability.
Send MMS with Sinch, RedwoodJS, and Node.js
Learn how to send MMS (Multimedia Messaging Service) using the Sinch Conversation API in your RedwoodJS application. This complete Node.js tutorial shows you how to integrate multimedia messaging with text and images through GraphQL mutations and Prisma database logging. Follow this step-by-step guide to implement MMS functionality from project setup through testing, including secure API configuration, reusable service functions, and comprehensive error handling.
This MMS integration enables real-world use cases like appointment confirmations with QR codes, e-commerce order updates with product images, visual receipts with branded logos, marketing campaigns with promotional content, and service notifications with instructional diagrams.
What You'll Build: RedwoodJS MMS Application
Build a complete MMS messaging application using RedwoodJS, Node.js, and the Sinch Conversation API:
Why Send MMS Messages:
MMS (Multimedia Messaging Service) lets you send rich media content—images, videos, and text—directly to mobile phones. Common applications include:
For SMS-only messaging without multimedia, see our Node.js SMS guide or learn about E.164 phone number formatting for international messaging.
Understanding the RedwoodJS MMS Integration
What You're Building:
Add functionality to a RedwoodJS application enabling it to send MMS messages through the Sinch Conversation API. This involves:
Problem Solved:
Programmatically send rich media content (images) alongside text messages to users directly from a web application, leveraging Sinch's communication infrastructure.
Technologies Used:
System Architecture:
lib/sinch.ts).Prerequisites:
npm install -g @redwoodjs/cli. Latest RedwoodJS version: 8.8.1 (as of January 2025).Expected Outcome:
Build a functional RedwoodJS application that sends MMS messages (text + image from URL) to specified phone numbers using the Sinch Conversation API, with basic logging.
1. Set Up Your RedwoodJS Project for MMS
Create a new RedwoodJS project with TypeScript and install the dependencies needed to send MMS messages via the Sinch Conversation API.
Create RedwoodJS App: Open your terminal and run the following command. This guide uses TypeScript.
Install Dependencies: Install
node-fetchto make requests from your API service to the Sinch API. Navigate to theapiworkspace and installnode-fetchversion 2.Why
node-fetch@2? Version 3+ uses ESM modules by default, which can sometimes require extra configuration in primarily CommonJS environments like the default RedwoodJS API side. Version 2 provides robustfetchfunctionality with simpler integration for this guide.Database Setup (Optional Logging): Create a simple Prisma model to log outgoing MMS messages. Open
api/db/schema.prisma:UserExamplemodel.MessageLogmodel:Apply Database Migration: Create and apply the migration to your database (creates a SQLite file by default).
This command generates SQL migration files and applies them, creating the
MessageLogtable.Generate SDL and Service for Logging (Optional): If you want GraphQL access to the logs (not strictly required for sending), scaffold it:
2. Configure Sinch API Credentials for MMS
Set up your Sinch account, create a Conversation API app, and obtain the API credentials and MMS-enabled phone number required to send multimedia messages.
Log in to Sinch Dashboard: Access your Sinch Customer Dashboard.
Navigate to Conversation API: In the left-hand menu, find "Products" → "Conversation API".
Create a Conversation API App:
Obtain Credentials: Once the app is created, you'll land on its configuration page. Find the following:
Configure MMS Channel:
SERVICE_PLAN_ID.SERVICE_PLAN_IDin the MMS channel configuration within the Conversation API App.Note: Sinch Dashboard UI may change over time. Refer to the official Sinch Conversation API documentation if the paths described here differ.
3. Build the Sinch MMS Service Library
Create a reusable Node.js library function to send MMS via the Sinch Conversation API, then build a RedwoodJS service and GraphQL schema to expose this functionality to your frontend.
Create the Sinch Library Function: Create a new file
api/src/lib/sinch.ts. This function encapsulates the logic for sending the MMS message via the Conversation API.Key Points:
media_message,contact_id,channel_properties.MMS.sender_number).message_id).Generate MMS Service and SDL: Use the Redwood CLI to generate the boilerplate for the service and GraphQL schema definition.
Note: Add
--no-crudand--no-testsas you're defining a custom mutation, not standard CRUD operations. Skip automated tests for brevity in this guide (though highly recommended for production).Define the GraphQL Mutation (SDL): Open
api/src/graphql/mms.sdl.tsand define thesendMmsmutation.Explanation:
MmsSendResponseto standardize the mutation's return value.sendMmsmutation takesrecipient, optionaltext, and requiredmediaUrlas arguments.@requireAuthdirective ensures only authenticated users (if using Redwood Auth) can trigger this mutation. Adjust if your auth setup differs.Implement the MMS Service: Open
api/src/services/mms/mms.tsand implement thesendMmsfunction. This function calls the library function and handles logging to the database.Explanation:
db), logger, and thesendSinchMmsfunction.sendernumber from environment variables.sendSinchMmsin atry...catchblock.sinchMessageIdto theMessageLogtable.MmsSendResponseobject.4. Create the GraphQL MMS API
Verify your GraphQL schema and service are configured correctly, then test the MMS mutation using the RedwoodJS GraphQL Playground.
Check the Service: Open
api/src/services/mms/mms.tsand verify thesendMmsfunction is correctly implemented.Check the SDL: Open
api/src/graphql/mms.sdl.tsand verify thesendMmsmutation is defined.Test the Mutation: Use the RedwoodJS GraphQL Playground (available at
http://localhost:8910/graphqlwhen the dev server is running) to test thesendMmsmutation. Example query:5. Build the MMS Frontend Interface
Create a React page component with a form that lets users send MMS messages by triggering the GraphQL mutation.
Generate a Page:
Implement the Page Component: Open
web/src/pages/SendMmsPage/SendMmsPage.tsxand add a form to collect the MMS details.Explanation:
MetaTags,useMutation,toast,Form, form fields).SEND_MMS_MUTATIONmatching the SDL.useMutationhook to get thesendMmsfunction and loading/error states.onCompletedhandles successful or failed responses from the backend mutation, displaying toasts.onErrorhandles network-level or unexpected GraphQL errors.onSubmithandler performs basic client-side checks and calls thesendMmsfunction with form data.TextField,TextAreaField,Submit,Label,FieldError,FormError) are used for the UI and basic validation.loading).6. Test Sending MMS Messages
Test your complete MMS integration by sending a multimedia message with text and an image to a real phone number.
Start the Dev Server: If it's not already running:
Navigate to the Page: Open your browser and go to
http://localhost:8910/send-mms.Fill the Form:
+15559876543)..jpg,.png, or.gifimage. A simple test URL:https://www.gravatar.com/avatar/?d=mp(yields a generic person icon). Ensure the URL works directly in your browser.Submit the Form: Click "Send MMS".
Check for Results:
yarn rw devis running. You should see logs fromapi/src/lib/sinch.tsandapi/src/services/mms/mms.tsindicating the attempt and success/failure.MessageLogtable (you can useyarn rw prisma studioto open a GUI). You should see a record for the attempt.7. Implement Error Handling and Logging
Understand the error handling patterns and logging strategies for production MMS applications.
lib/sinch.tsfunction attempts to parse error messages from Sinch's API response. These are logged and propagated to the service, then to the frontend via the mutation response. Common errors include invalid credentials (401), malformed requests (400), or number provisioning issues.node-fetchmight throw errors for network issues (e.g., DNS resolution failure, timeouts). These are caught inlib/sinch.tsand the service.loggeris used on the API side. For production, configure more robust logging (e.g., sending logs to a dedicated service, adjusting log levels). Check the RedwoodJS Logging documentation.8. Secure Your MMS Application
Implement security best practices to protect API credentials, validate user input, and prevent abuse.
.envfile containing secrets to version control. Use environment variable management provided by your hosting platform for production.mediaUrlto prevent Server-Side Request Forgery (SSRF) if the URL is user-provided and processed further on the backend (less critical here as Sinch fetches it, but good practice).@requireAuthdirective is used. Ensure your RedwoodJS authentication is properly configured to protect the mutation endpoint.express-rate-limitadapted for Redwood services) to prevent abuse. Check Sinch API rate limits.9. Troubleshoot Common MMS Issues
Resolve common problems with Sinch API authentication, phone number formatting, and media URL accessibility.
SINCH_ACCESS_KEYandSINCH_ACCESS_SECRETin your.envfile. Ensure they are correctly copied and the.envfile is loaded (restart dev server). Verify you are using the correct key pair for the specifiedSINCH_PROJECT_IDandSINCH_APP_ID.recipientorsenderformat (must be E.164).mediaUrl. The URL must be publicly reachable by Sinch's servers. Private network URLs won't work.lib/sinch.ts).app_id,recipients,media_message.url).SINCH_REGION_URLmatches the region where your Conversation API App was created (usoreu). Using the wrong region URL will result in errors (likely 404 Not Found or authentication failures).SINCH_MMS_NUMBERmust be correctly assigned to the Service Plan linked in the Conversation API App's MMS channel settings, and it must be enabled for MMS traffic by Sinch (this is usually the case for US/Canada numbers suitable for A2P MMS). Contact Sinch support if you suspect provisioning issues.Content-Typeheader (e.g.,image/jpeg,image/png).node-fetchv3+ Issues: If you accidentally installednode-fetchv3 or later and encounterrequire is not definederrors in the API, either switch back to v2 (yarn workspace api remove node-fetch && yarn workspace api add node-fetch@2) or configure your environment for ESM compatibility if preferred.10. Deploy Your MMS Application
Prepare your RedwoodJS MMS application for production deployment with proper environment configuration and monitoring.
For production deployment, you'll need to:
For detailed RedwoodJS deployment instructions, see the RedwoodJS deployment documentation. For SMS alternatives or comparison, explore our Twilio Node.js guides or learn about 10DLC registration for US commercial messaging.