Build Appointment Reminders with RedwoodJS and Twilio SMS - code-examples -

Frequently Asked Questions

Start by creating a new RedwoodJS application using the command `yarn create redwood-app ./your-project-name`. Then navigate to the project directory. Install the necessary Twilio helper library in the API workspace with `yarn workspace api add twilio`.
Twilio's Programmable Messaging API is used to send SMS reminders. Its Message Scheduling feature enables reliable delivery without building a custom scheduling system. This simplifies development and ensures robust functionality.
Scheduling is handled by the Twilio Node.js helper library and RedwoodJS services. The `scheduleReminder` function calculates the appropriate `sendAt` time, considering the appointment time and a predefined offset. It uses the user's time zone for display but schedules based on UTC for consistency.
Store appointment times in UTC in your database. The user's time zone is stored separately and is used only for displaying the appointment time in the user's local time and formatting the reminder message. Twilio scheduling always uses UTC.
You need Node.js v18 or later, Yarn, a Twilio account, a Twilio phone number with SMS capability, and a configured Twilio Messaging Service. Familiarity with JavaScript, Node.js, React, GraphQL, and database concepts is helpful.
Twilio's Message Scheduling requires a Messaging Service. It offers benefits like sender ID pools, scalability, and advanced opt-out handling, making it more suitable than sending messages from a single number directly.
While RedwoodJS defaults to SQLite for simplicity, PostgreSQL is recommended for production environments due to its robustness and scalability. You can configure the database connection string in the `.env` file.
Your Twilio Account SID, Auth Token, and Messaging Service SID should be stored as environment variables in a `.env` file in your project's root directory. RedwoodJS automatically loads these variables, making them available to your services.
The `scheduledMessageSid` field in the database stores the unique identifier of the scheduled message returned by Twilio. This allows you to cancel or modify the scheduled reminder later if needed.
The provided code includes functionality to cancel existing reminders using the stored `scheduledMessageSid`. This cancellation logic is implemented within the `updateAppointment` and `deleteAppointment` mutations.
Use the E.164 format (e.g., +15551234567) for phone numbers. This ensures international compatibility. The provided code includes validation to enforce this format.
RedwoodJS uses GraphQL for its API. The `appointments.sdl.ts` file defines the schema for appointment data, and `appointments.ts` contains resolver functions for interacting with the database and Twilio.
RedwoodJS uses Prisma as its database toolkit. You define the data model in the `schema.prisma` file and manage migrations using the Redwood CLI.
You can find your Account SID and Auth Token on the main dashboard ("Account Info") of the Twilio Console after logging in.
The example code schedules the reminder 60 minutes before the appointment. The `scheduleReminder` function handles scheduling logic, ensuring the reminder is scheduled within Twilio's constraints (15 minutes to 7 days in the future).
Yes, the SMS reminder content can be customized. The `scheduleReminder` function demonstrates formatting the message body and incorporating details like the recipient's name and the appointment time and timezone.