Send Appointment Reminders with Twilio Studio

Appointment reminders are a breeze with Twilio Studio! Let’s look at how to build a simple flow that hooks into your application via REST API and sends a reminder SMS with a confirmation message.

 

Create Your Flow

We’ll start with a fresh Twilio Studio flow; log into your Twilio account and navigate to the Studio Dashboard, then tap the + icon to create a new flow. You can name your flow anything you like; we’re calling ours Appointment Reminder.

Appointment Reminder Flow

You’ll notice that the canvas comes with a widget already in place -- that’s the Trigger widget, which kicks off our flow when the trigger we specify is fired. In this case, our trigger is going to be a REST API call. See the REST API section of the Studio User Guide to learn how to make these calls.

REST API Trigger

 

Send & Wait For Reply

We’ll start by dragging a Send & Wait For Reply widget onto the canvas, and connecting it to the REST API trigger by dragging the red dot to the grey dot in the corner of the new widget. We can use this widget to send an SMS to the user with a prompt to reply to. In this case, we’re going to use a value (time) from our API call, so the message body is going to be “Your appointment is coming up on {{flow.data.appointment_time}}. Please reply 1 to confirm and 2 to cancel.” Studio supports the Liquid template language, which is a fancy way of saying “a way to help you load dynamic content throughout your flow.” We’re telling Studio that we’d like it to dynamically interpret the text between the two curly braces based on something -- in this case, the appointment_time value from our request.

Confirm appointment time

 

Split Based on Reply

We’re expecting the user to reply to this text message to confirm or cancel their appointment. We’ll need some logic that will help us know which choice the user would like to make. We’ll use the Split Based On… widget to help handle that. Drag it onto the canvas and connect it to the dangling Reply dot from our Send & Wait For Reply widget.

Split based on Reply

First, we’ll need to configure the variable we’re testing. In this case, we’re concerned with the user’s reply, so we’ll select confirm_appt and then inbound.Body from the dropdown on the right-side panel (yours may have a different name if your Send & Wait For Reply widget is not called confirm_appt).

Split variable to test

 

Set Transition Conditions

Next, we’ll need to declare the choices we’re looking for in those text replies -- the digits 1 and 2. Tap the red New at the bottom of the Split widget to reveal the Transition On… dropdown menu. Select Condition Matches to create a new Transition.

Split confirmation condition

In the right sidebar, find the new Transition that you just created, and select Equal To from the dropdown. We’re going to set this value to 1, to confirm the appointment. Save the new transition and it will appear on the widget.

Condition equal to 1

Next, we’ll need a condition for if the user has pressed 2 to cancel the appointment. Just as with the first Transition, we’re going to tap New, then select Condition Matches…., then set the value equal to 2 in the sidebar and save. Our widget should look like this, with No Matches, 1, and 2 dangling from the bottom:

Confirmation split widget

 

Make an HTTP Request

Next, we’re going to want to handle the appointment confirmation by making a request back to our servers. We can do this by dragging an HTTP Request widget onto the canvas and filling in the required fields (Request Method and Request URL) in the right sidebar. In this sample, we’re using http://example.com, but you’ll want to set the Request URL to the appropriate endpoint for your application. If you’d like to send a request body or parameters, you may set those in the right sidebar as well.

Make HTTP request

When the request successfully completes, we want to text our user with a thank you. We can do this by dragging a Send Message widget onto the canvas, and populating the Message Body with our note for the user.

Thank You message


Cancellation Path

Now it’s time to do the same steps over again, this time for the cancellation. We’ll drag an HTTP Request widget onto the canvas and hook it to the dangling 2 from our Split widget, make a request to our cancellation endpoint, and send an acknowledgment message to the user.

Cancellation path

 

No Match Condition

But what if the user enters text besides 1 or 2 (our confirmation and cancellation conditions)? We can take advantage of the built-in No Matches condition, and prompt the user with the reminder again. Drag a Send Message widget onto the canvas and connect it to the No Matches dot, then enter the error message of your choosing. We can then re-prompt the user with the original appointment reminder by dragging the Sent dot on the Send Message widget to our original Send & Wait For Reply widget.

No matches condition


The Finished Product

The final state of the canvas is that we have our Trigger widget take a REST API request, prompt the user to confirm or cancel with a Send & Wait For Reply widget, routed responses through a Split Based On… widget, used HTTP Request widgets to POST cancellations and confirmations back to our own endpoint, and used Send Message widgets to acknowledge the user’s response.

Appointment Reminder Final Canvas

 

Time to test it out! You can make a request from your API to Studio and kick off this appointment reminder flow, then text back to confirm or cancel. For endpoint details, parameters, and a sample curl request, see the REST API section of the Studio User Guide. Get ready to have your calendar perfectly synced with your clients!




Jennifer Aprahamian
Brent Schooley

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.