Frequently Asked Questions
Create a RedwoodJS application, integrate the MessageBird API, set up a database with Prisma to store contacts, build a service to handle sending logic, and create a React frontend to trigger the broadcast. This setup enables efficient, automated SMS campaigns.
RedwoodJS is the core framework for building both the frontend (using React) and backend (GraphQL API) of the bulk SMS application. It also facilitates database interaction through Prisma, providing structure and tooling for a smooth development experience.
MessageBird is a Communication Platform as a Service (CPaaS) that provides reliable APIs for sending SMS messages. Its Node.js SDK simplifies integration with RedwoodJS, allowing you to efficiently send messages to a large audience.
Obtain your live API key from the MessageBird Dashboard under 'Developers -> API access'. Store this key securely in a `.env` file in your project's root directory as `MESSAGEBIRD_ACCESS_KEY=YOUR_ACTUAL_KEY`. Never hardcode API keys directly in your code.
RedwoodJS, via Prisma, supports PostgreSQL, SQLite, and MySQL. The example uses SQLite for development but you can configure any of these based on your needs. Be sure to update the `schema.prisma` and `.env` files accordingly.
Define a 'Contact' model in the `api/db/schema.prisma` file. This model should include fields for 'id', 'name', and 'phoneNumber'. It's essential to mark 'phoneNumber' as unique and store numbers in E.164 format for compatibility.
Use the E.164 format, which includes a plus sign (+) followed by the country code and phone number (e.g., +14155552671). Consistent formatting is crucial for successful message delivery with MessageBird.
The Redwood service fetches contact information from the Prisma database. It then uses the MessageBird Node.js SDK to send SMS messages, managing chunking if the recipient list exceeds MessageBird's API limits.
Chunking divides the recipient list into smaller groups as MessageBird's API has limits per request. This ensures all recipients receive the message even if the contact list is extensive. This guide handles chunking for you automatically.
By default, for easy development, the mutation is open. Critically, for production or any publicly accessible environment, replace `@skipAuth` with `@requireAuth` in `api/src/graphql/messageBroadcaster.sdl.js` after you've implemented Redwood's authentication.
Consider background jobs for very large contact lists or if you need more robust error handling and retry logic. This approach enhances performance and reliability and avoids HTTP timeouts, although implementation is more complex.
Typical errors include incorrect or missing API keys (check your `.env` file), invalid phone number formatting (use E.164), insufficient MessageBird balance, or reaching MessageBird API rate limits. Check your logs and MessageBird's documentation for detailed error codes.
Protect your MessageBird API key using `.env` files and secure environment variables in your deployment environment. Implement robust input validation, enable CSRF protection, and crucially, add authentication by changing `@skipAuth` to `@requireAuth` for the `sendBulkSms` mutation before deploying.
SMS messages exceeding 160 characters (or less with special characters or emojis) are split into multiple segments and billed accordingly. The provided code includes a basic segment calculator but advise users that this is an approximation, and actual costs might vary.
For large contact lists, avoid loading all contacts at once with `findMany()`. Implement batch fetching using Prisma's `skip` and `take` options within a loop in your service to reduce memory usage and improve performance.
Content Loading Error
We encountered an error while processing this content.