Frequently Asked Questions
You can send SMS messages within a RedwoodJS application by integrating the Sinch SMS API and using their Node.js SDK. This involves creating a RedwoodJS backend service and a GraphQL mutation to trigger the message sending process via Sinch.
The Sinch SMS API allows your RedwoodJS application to send and receive SMS messages globally. It's integrated using the Sinch Node.js SDK (@sinch/sdk-core) for simplified interaction.
Storing sensitive credentials like Sinch API keys in environment variables ensures they are not hardcoded into your application, enhancing security. RedwoodJS uses .env files to manage these variables.
Creating a single Sinch client instance is a performance best practice. Do this during initialization to avoid re-initializing the client with every request, especially under heavy load.
RedwoodJS services encapsulate backend logic. In this case, an SMS service handles the interaction with the Sinch SDK, including sending messages and managing responses.
Install the Sinch Node.js SDK (`@sinch/sdk-core`) in your RedwoodJS API side using `yarn workspace api add @sinch/sdk-core`. Then, configure your environment variables with your Sinch credentials.
Implement a try...catch block around the Sinch SDK's send method and use RedwoodJS's logger to record successes and failures. The example code returns structured error objects, letting GraphQL handle responses consistently. Consider retry mechanisms for transient issues using libraries like `async-retry`.
Use RedwoodJS's logger within a try...catch block around the Sinch API call. Log failures with `logger.error` and provide helpful error messages in the returned object or by throwing errors, depending on your GraphQL error handling strategy.
While not strictly required, you can create an SmsLog model in your Prisma schema and update your service to create a log entry for each sent message, including status and other relevant details.
Yes, by configuring Sinch Delivery Reports (webhooks) in your Sinch API settings and creating a corresponding RedwoodJS function to receive and process the delivery status updates. This allows you to update your database with the final delivery status (e.g., DELIVERED, FAILED).
Use environment variables for API keys, implement authentication/authorization with the `@requireAuth` directive, validate input data thoroughly, and consider rate limiting to protect your endpoint from abuse.
Always use the E.164 format for phone numbers (e.g., +14155552671). Validate input using a library like `libphonenumber-js` for accuracy and security.
Network or temporary Sinch API issues can cause SMS sending to fail. Retries improve reliability. Use the `async-retry` library to implement retries in your Redwood service. Ensure to handle different error scenarios appropriately within the retry logic and avoid retrying on non-recoverable errors such as invalid credentials.
Initialize the SinchClient once and reuse the instance. Also, use asynchronous operations, keep the SMS body concise, and leverage the Sinch API's batch sending feature for multiple recipients. If logging to a database, optimize database queries and indexing.
Use RedwoodJS's logging, integrate error tracking services like Sentry, monitor the Sinch Dashboard for SMS logs and usage reports, and set up health checks for your RedwoodJS API. Implementing Sinch Delivery Reports (webhooks) allows detailed tracking of delivery statuses.
Content Loading Error
We encountered an error while processing this content.