Ahoy! We now recommend you build your SMS appointment reminders with Twilio's built in Message Scheduling functionality. Head on over to the Message Resource documentation to learn more about scheduling SMS messages!
This is a Java 8 web application written using Spark that demonstrates how to send appointment reminders to your customers with Twilio SMS.
Check out this application on GitHub to download the code and read instructions on how to run it yourself. In this tutorial, we'll show you the key bits of code necessary to drive this use case.
Let's get started! Click the button below to move on to the next step of the tutorial.
The Quartz scheduler is instantiated in the main method of our web application, before we set up the routes. We pass a reference to this scheduler to the controller so it can schedule jobs to send out appointment reminders. Note that by default, Quartz temporarily stores jobs in memory, but in production you can configure Quartz to store jobs in a data store of your choice.
Next let's see how we create a new
Once validations pass and the appointment is persisted to the database.
scheduleJob a notification is scheduled based on the time of the appointment.
We will dig further into that function next.
The controller uses the injected scheduler to set up a notification. The
AppointmentScheduler class is used here to actually send out the notification via SMS through a Quartz trigger.
Let's look at how we handle this trigger.
Every time a scheduled job is triggered by Quartz, an instance of the
AppointmentScheduler class is created to handle the job. When the class is loaded, we create a
RestClient to interact with the Twilio API using our account credentials.
Next let's look at how the SMS is sent.
execute method is called on an
AppointmentScheduler instance, we use the Twilio REST API client to actually send a formatted reminder message to our customer via SMS.
That's it! We've successfully set up automated appointment reminders for our customers, which will be delivered via SMS.
Did this help?
Thanks for checking out this tutorial! If you have any feedback to share with us, please reach out on Twitter... we'd love to hear your thoughts, and know what you're building!