Frequently Asked Questions
You can send bulk SMS messages with RedwoodJS by integrating Twilio's Messaging Service. Build a RedwoodJS service function to handle the logic, expose it via a GraphQL API endpoint, and create a frontend form to trigger the broadcast. Use a Messaging Service SID for sending, not a regular Twilio number, to leverage number pooling and carrier compliance.
A Twilio Messaging Service is a feature that simplifies sending bulk SMS. It provides features like number pooling, opt-out management, and sticky sender, enhancing deliverability and scalability. It's essential for sending large volumes of SMS messages and managing compliance requirements like A2P 10DLC.
Using a Twilio Messaging Service is crucial for bulk SMS sending as it offers advantages like number pooling, managing opt-outs, and simplified compliance. These features help ensure reliable delivery and avoid carrier filtering.
For high-volume or mission-critical bulk SMS sending, use a background job queue. This separates the sending process from the user request, improving API responsiveness and providing robust retry mechanisms. Queues handle temporary failures like carrier issues, improving overall reliability.
To set up your Twilio Messaging Service SID, create a Messaging Service in the Twilio Console, add your purchased Twilio phone number to its sender pool, and then locate and copy the Service SID. Paste this SID into your RedwoodJS project's `.env` file as `TWILIO_MESSAGING_SERVICE_SID`.
You need a database model to store subscriber phone numbers. The model should at least have a `phoneNumber` field (ideally unique and stored in E.164 format), and optionally a `name` field. The example uses Prisma in the `schema.prisma` file.
E.164 is an international standard for phone number formatting. It ensures numbers are stored correctly for global compatibility with Twilio. An E.164 number includes a plus sign (+) followed by the country code and national subscriber number (e.g., +15551234567).
Use `Promise.allSettled` to handle failures gracefully. This sends messages concurrently and waits for all promises to settle (succeed or fail). Log errors with context (like the phone number) and return a summary of success/failure counts with detailed error information.
RedwoodJS services contain the core backend logic of your application. They keep your business logic separate from other layers like the API, making your code cleaner, more testable, and easier to maintain. The `sendBulkSms` function is a good example.
Define a mutation (e.g., `broadcastSms`) in your GraphQL schema (`.sdl.js`) that takes the message body as input. Redwood automatically maps this to your service function based on naming conventions.
Use `yarn rw setup auth dbAuth` to set up authentication in your RedwoodJS application. This generates necessary authentication logic. Remember to also create the frontend login/signup pages and use `@requireAuth` on your GraphQL mutation to enforce authentication.
Use Redwood's built-in logger (`logger.error`, `logger.warn`, etc.) for structured logging. For production, customize `api/src/lib/logger.js` to output JSON and integrate with a logging service. Include context like the phone number when logging SMS failures.
Yes, using a background job queue like BullMQ with Redis or a cloud-based queue is the recommended way to handle SMS retries. It decouples the retry logic from the user request, providing more robust error handling and improved reliability.
Use environment variables for Twilio credentials (never hardcode them), secure your `.env` file, use secrets management in production, implement input validation/sanitization, and enforce rate limiting on your API endpoints to prevent abuse.
Content Loading Error
We encountered an error while processing this content.