Build RedwoodJS Marketing Campaigns with MessageBird - code-examples -

Frequently Asked Questions

Create a RedwoodJS service to handle the messaging logic, integrate the MessageBird Node.js SDK, and expose the service through a GraphQL mutation. This allows your application to send SMS messages programmatically via the MessageBird API.
MessageBird acts as the third-party SMS gateway provider. The RedwoodJS application integrates with MessageBird's API using their Node.js SDK, allowing you to send SMS messages directly from your RedwoodJS application.
RedwoodJS offers a full-stack, serverless-friendly framework with built-in GraphQL and Prisma, simplifying development and deployment. Its structured approach promotes code organization and maintainability for campaign management.
Set a `MESSAGEBIRD_DEFAULT_ORIGINATOR` environment variable if you want a consistent sender ID for most campaigns. This simplifies the API call but can be overridden per campaign if needed. If not set, a generic default might be used, potentially affecting deliverability.
The basic implementation provides submission status. For detailed delivery reports (e.g., delivered, failed), configure MessageBird webhooks to receive real-time updates and store them in a database.
Install the MessageBird Node.js SDK, obtain your Live API Key from the MessageBird dashboard, and store it securely in a `.env` file in your project root. Never commit API keys directly into your code.
The core technologies include RedwoodJS, Node.js, MessageBird, Prisma (ORM), GraphQL, and Jest (testing). This combination provides a robust and efficient platform for building and managing SMS campaigns.
Error handling ensures your application gracefully manages issues like invalid recipient numbers, network problems, or MessageBird API errors. Implement try-catch blocks, logging, and retry mechanisms in your RedwoodJS service.
Retry logic is useful for handling transient errors, such as temporary network issues or brief MessageBird service disruptions. Use a library like `async-retry` to manage retries with exponential backoff.
Be aware of the 160-character limit for standard SMS. Longer messages are split (concatenated), impacting cost. Inform users of potential extra charges. Unicode (emoji) messages have a 70-character limit.
Use the E.164 format (+[country code][number]) for maximum compatibility, especially with international numbers. Consider using a library like `libphonenumber-js` for validation and normalization.
Storing campaign information in a database using Prisma allows you to track campaign history, monitor status (submitted, failed, etc.), and analyze campaign performance over time.
Use Redwood's authentication (e.g., `requireAuth`, `@requireAuth`), validate and sanitize user inputs, protect your MessageBird API key, and implement rate limiting to prevent abuse.
Alphanumeric sender IDs are supported in many countries but not all. Check MessageBird's documentation for country-specific regulations. In some regions (e.g., US/Canada), pre-registered numbers are required.
Adhere to MessageBird's best practices, including using registered sender IDs, handling opt-outs correctly, ensuring valid recipient numbers, and monitoring delivery reports via webhooks.