Build a Scheduled SMS Reminder App with RedwoodJS and Sinch - code-examples -

Frequently Asked Questions

Use RedwoodJS's GraphQL API, integrated with the Sinch SMS API, to schedule and send SMS reminders. Create a Redwood service that interacts with both the Sinch API and your database to manage reminder scheduling and data storage. Build a frontend form in RedwoodJS to collect user input and trigger the reminder scheduling process via the GraphQL API.
The Sinch SMS API enables your RedwoodJS application to send SMS messages. It handles the complexities of SMS delivery, allowing you to focus on application logic. Specifically, the 'send_at' feature allows scheduling SMS messages for future delivery without managing background jobs within RedwoodJS itself.
RedwoodJS offers a full-stack, serverless-friendly framework that simplifies development by providing integrated frontend (React), backend (GraphQL API, Prisma), and database access. This structure makes it easier to handle user interactions, data management, and external API integrations like Sinch.
Luxon is highly beneficial when working with dates and times, especially when dealing with different time zones. It's used to parse, manipulate, and format dates/times accurately in your RedwoodJS application, avoiding common time zone issues. In this SMS reminder app, Luxon ensures accurate calculation of the reminder time based on the user's specified time zone and converts it to UTC for consistent storage and Sinch API interaction.
Yes, you can use SQLite for local development and simpler projects. RedwoodJS defaults to SQLite and handles the basic setup automatically if you use provider = "sqlite" in your schema.prisma file. For production environments, PostgreSQL is generally recommended for its scalability and robustness, requiring you to configure the DATABASE_URL environment variable appropriately.
RedwoodJS uses .env files for environment variables. Create a .env file in your project's root directory and add your sensitive information, such as API keys and database URLs. Ensure .env is added to .gitignore to prevent committing secrets to version control.
Prisma acts as an Object-Relational Mapper (ORM) for your database. It simplifies database interactions by allowing you to work with data using JavaScript objects and methods. In this application, Prisma facilitates storing and retrieving reminder details like patient name, appointment time, and phone number.
The user interacts with a React frontend, which communicates with a GraphQL API. The API interacts with a Redwood service that handles logic, using Prisma to manage data in a database (PostgreSQL/SQLite) and the Sinch API to schedule SMS messages. Sinch sends the SMS at the designated time.
You need Node.js (v20 or higher recommended), Yarn v1, a Sinch account (with API credentials and a provisioned number), access to a terminal, and basic understanding of JavaScript, React, GraphQL, and databases.
The Sinch SMS API expects times in UTC for the send_at parameter. Use a library like Luxon to convert user-provided times (along with their time zone) into UTC before passing to the Sinch API. Ensure your database also stores all DateTime fields in UTC for consistency.
Define a 'Reminder' model in your api/db/schema.prisma file specifying fields like patientName, phoneNumber, appointmentTime, reminderTime, and status. Use appropriate data types and consider an index on status and reminderTime for efficient querying.
The 'PENDING' status indicates that an SMS reminder has been scheduled but has not yet been sent by Sinch. Other status options could be SENT or FAILED for enhanced tracking and reporting.
E.164 is an international standard format for phone numbers (e.g., +15551234567) that ensures consistency and compatibility with global communication systems. Using E.164 simplifies validation and reduces ambiguity when sending SMS messages internationally.
Implement try...catch blocks around API calls and database operations to handle potential errors gracefully. Log errors using Redwood's logger and provide user feedback through toasts or other notification mechanisms. Consider retry mechanisms for API calls and compensation logic for database errors to enhance robustness.