Scheduling Messages for Appointment Reminders with Twilio

January 10, 2022
Written by
Reviewed by
Dave Esber
Twilion
Chris Mateo
Contributor
Opinions expressed by Twilio contributors are their own

Scheduling Messages for Appointment Reminders with Twilio

Sending appointment reminders via text or other channels is a great way for care providers to stay in touch with patients, reduce no-shows, and ensure they get the care they need. However, how can you set them to automatically be sent at the appropriate time from your electronic health records system, or EHR, without having to manage yet another complex system? It can be difficult to have your systems talk to each other, much less send out reminders to patients. However, appointment reminders are so valuable that it's worth finding a way to make them work.

With Twilio’s new message scheduling capability, you can have messages from your EHR automatically go to your patients at predetermined times. This allows you the flexibility to automatically create appointment reminders days (or even hours) before an appointment, as well as schedule follow up reminders post-appointment. Today, I’ll show you how to create scheduled messages using Twilio’s new message scheduling capabilities.

Prerequisites

Before you can get started with Twilio’s messaging scheduling capabilities, you’ll need to make sure you have a few things ready.

  • If you haven’t yet, sign up for a free Twilio account here
  • Review the docs for message scheduling
  • In our example, we use Airtable
    • If you’re planning to use your EHR, make sure it is capable of calling APIs when appointments are created (note: you may need middleware to do so)

Demo: A message scheduler with Twilio

In this section, I’ll show you an example of what you can build, using Airtable as an example backend. You could apply the same principles to using a full-fledged EHR as a scheduling backend, as well!

Consider our scheduling interface – here I’m using an Appointment Scheduling web form to allow people to schedule appointments. I’ve also integrated this with Twilio, so when I submit an appointment, it will also schedule an SMS to go out as an appointment reminder.

Let's say, for example, I put in my information and get an appointment.

 

Screenshot of appointment submission

When I submit it, it goes into my system of record. You can see, this has come into my Appointments view in Airtable and I've got a status field saying that reminders have been scheduled to go out to the phone number.

Screenshot of system of record populating with scheduled messages

In the Appointments view in Airtable, I can see the appointment date and time, when the message is scheduled to be delivered, as well as the message itself.

Screenshot of system of record showing appointment ID, appointment date/time, scheduled message delivery date/time, status, and message

In this example, I created an appointment reminder set to go out 24 hours before my appointment. I also created an appointment reminder set up for an hour before the appointment itself. I also created a "missed appointment" reminder, which we'll discuss in a moment.

Once these messages are scheduled, they automatically go out at the specified time. The TO, FROM, and BODY fields are stored in Twilio when the API is called, and used when the scheduled message is delivered. Since you can make the body of the message include any text you want, you even have the ability to personalize the message! In the example below, I've personalized the message with the patient's name, but you could add any information that's relevant.

Sample Scheduled Message


Finally, I have an SMS that goes out an hour after the appointment in case the patient does not show up. This message can be canceled when appropriate using the Twilio API capabilities.

The idea here is when someone checks in for an appointment, I would call the API to cancel that particular message going out.

Screenshot of check in on right and scheduled message being canceled on left

This is just one example of how you can use the Message Scheduling API for appointment reminders.

Our sample appointment scheduling system

The setup for this sample appointment scheduling system is relatively straightforward. You can also review this blog post to learn more about our Quick Deploy app that allows you to integrate with your existing EHR.

In our example, when an appointment is created in the Appointment Scheduler web form, it calls the Twilio Messaging API and provides the following information:

  • To
  • MessagingServiceSid
  • Body
  • Status: Scheduled
  • Delivery Date/Time (ISO 8601 format)
axios.post('https://api.twilio.com/2010-04-01/Accounts/YOUR_TWILIO_ACCOUNT_SID/Messages.json', new URLSearchParams({
   MessagingServiceSid: 'YOUR_TWILIO_MESSAGING_SERVICE',
   To: phone,
   Body: `Hi ${name}, your appointment is tomorrow! Appt ID is `+apptId,
   ScheduleType: 'fixed',
   SendAt: reminder1.toISOString()
 }), {
   auth: {
     username: accountSid,
     password: authToken
   }
 })

Then, once the message is scheduled and we get a response back from Twilio, we can populate our Airtable with the relevant information from the message. Continuing from our last code sample:


.then((result) => {
  return table.create({
       "Appointment ID": apptId,
       "Message SID": result.data.sid,
       "Patient Phone #": phone,
       "Appointment Date/Time": date,
       "Msg Delivery Date/Time": reminder1.toISOString(),
       "Status": result.data.status,
       "Message": `Hi ${name}, your appointment is tomorrow! Appt ID is `+apptId
   });
 })

In our example earlier, I repeated this "create and store" process three total times to schedule one text 24 hours prior to an appointment, one an hour before an appointment, and one an hour after an appointment. You can create any number of scheduled messages based on your use case.

I’ve also set up a flow for appointment check-in as well as for canceling upon receiving a “missed appointment” text. In the Appointment Check-in web form, when a patient checks in, it looks up the appointment reminders associated with the appointment ID and retrieves the unique identifier (“message SID”) associated with any reminders still to go out – in this case, the “missed appointment” reminder. It then calls the Twilio Messaging API and provides the following information:

  • Message SID
  • Status: Canceled

let cancelResult = await axios.post(`https://api.twilio.com/2010-04-01/Accounts/${YOUR_TWILIO_ACCOUNT_SID}/Messages/${messageSid}`, new URLSearchParams({
       Status: 'canceled'
     }), {
       auth: {
         username: accountSid,
         password: authToken
       }
     }).catch((err) => console.log(err));

This then sets the state of the outgoing message to `canceled`, ensuring that the patient does not receive a “missed appointment” SMS for an appointment they attended.

Conclusion: scheduling appointment reminders with Twilio

As you’ve seen, with a few steps to call the Twilio Messaging API, you can ensure that patients get the outreach they need with little to no manual intervention on a clinician’s end. This “set-it-and-forget-it” approach to appointment reminders can drive great outcomes, as seen at Twilio clients like NYU Langone and many others. To access scheduling functionality in its public beta today, please review these docs and enjoy building!

 

Ankit Gupta is a Principal Solutions Engineer at Twilio, focused on the Healthcare and Life Sciences vertical. He works with providers, payers, device manufacturers, and others in the space to ensure higher patient engagement and better outcomes overall. He lives in Durham, NC and, when not in front of his computer, loves gadgets, building out a smart home, taking care of his new baby, and chasing after his dog Zara.

Ankur Kumar is a Principal Solutions Engineer at Twilio. He loves to create anything for the Internet. He's focused lately on all things messaging. Email Ankur at ankumar [at] twilio.com if you need any help.