Menu

How to build an IVR with Twilio Studio

Twilio Studio is a visual, drag-and-drop editor for creating applications. It works by dragging and dropping Widgets that represent parts of the Twilio API. Stitching these Widgets together creates an application – for example, your very own IVR (Interactive Voice Response) system, with no coding required.

If you've ever said or pressed "1" on your phone to connect to an agent at a call center, you've used an IVR system. An IVR is an interactive phone menu that lets callers navigate by voice or keypress to route calls to a different phone number.

In this tutorial, you'll learn how to create a basic IVR system that gathers key presses from callers and connects their calls to one of two phone numbers (Sales and Support). You will also learn how to accept and route calls based on voice input so that users can use either their voice or keypad.

New to Twilio Studio? We recommend you check out our Getting Started guide for working with Twilio Studio to familiarlize yourself with Studio mechanics before you dig in to this tutorial.

Prerequisites

Before you get started, you'll need:

Create your Flow

You'll start by creating a brand-new Studio Flow for your IVR system. All the logic and routing for your IVR will exist in this Flow.

Create a new Flow from scratch using the Twilio Console. If this is your first time working with Studio, you can see how to create a Flow here. You may wish to name this Flow something like "IVR Tutorial."

Gather user input

The first thing you'll need your Studio-powered application to do is gather information from your callers.

Look in the Widget Library for the Gather Input on Call Widget. Click on this Widget and drag it to your Canvas.

You'll need to connect your Trigger (Start) Widget to this Widget, so click on the red dot underneath Incoming Call and drag it to connect it to your new Widget. This will create a line between the two Widgets and tells your Studio application what to do with incoming calls.

Configure the Gather Input on Call Widget

Click on the Widget you just added to your Canvas. Inside the Gather Input on Call Widget's configuration menu (on the right side of the Canvas), you can rename this Widget to something more meaningful, like greet_caller

Next, you can tell your program what to say to callers. Double-check that the Say or Play a Message field in the Widget configuration is set to "Say a message" – this lets you write whatever message you'd like to have read to your callers. For this tutorial, write something in the text field like "Hello, how can we direct your call? Press 1 for Sales, or say Sales. To reach Support, press 2 or say Support."

The Gather Input on Call Widget expects the user to press keys or say something after they hear this message.

Stop gathering information

You probably don't want to make your IVR program wait after a user has given their keypress response, so scroll down in the Widget settings to the section for Stop gathering on keypress?

Make sure that "YES" is selected, and enter "1" in the field for Stop gathering after __ digits. This will tell your Studio-powered IVR to move on to the next step after our user has entered their response.

Form fields to tell your gather_input widget to stop gathering after 1 keystroke. We see the Config tab selected, "Stop gathering after keypress" followed by a blue, toggle-able box turned to "Yes", and Stop gathering after is set to 1.

Route the call

Now that you have a way to gather your first bit of user data it's time to tell your Studio Flow what to do with that data – route the call to Sales or Support. Start out by creating your workflow for users who press a key to route to the correct department.

Split Based On key press

The Split Based On... Widget tells your Studio Flow how to direct a phone call based on some action your user takes. Find Split Based On... in the Widget Library and drag it on to your Canvas, connecting it to the User Pressed Keys option in your greet_caller Widget. Re-name this Widget to split_key_press.

A Split based on Widget (renamed to split_key_press) is connected to the User Pressed Keys transition from the gather_input widget.

Now you'll need to configure this Widget to tell your Flow how to route the call based on your user's input. In this case, you want to work with keys that the user presses, so under Variable to test in the Widget Configuration, select Digits under greet_caller from the dropdown.

Match variable for split_key_press to widgets.greet_caller.Digits

Next, you'll need to declare the choices you're looking for in those key presses from your users.

Create Transitions for your call

Tap the red New button at the bottom of your split_key_press Widget to reveal the Transition On... dropdown menu. Select Condition Matches to create a new Transition.

If you look to the Widget sidebar on the right of your Canvas, you should see the Transitions tab is now selected for your split_key_press Widget. Scroll down in the Widget until you see If value equal_to... and set the value to "1" in order to connect your callers to Sales and save the Transition.

Next, you'll need a condition for your users who pressed 2 for Support. Just as with the first Transition, tap New, then select Condition Matches..., then set the value equal to 2 in the Transition Configuration and save.

Your Widget should now look like this, with No Matches, 1, and 2 dangling from the bottom:

Split_key_press with transitions in place for None, If Value Equal to 1, and If Value Equal to 2 dangling from the widget.

Now all that's left is to connect these users to the appropriate department!

Connect the Call

In order to connect your users to Sales or Support, use the Connect Call To Widget. You will use one Connect Call To Widget for each phone number you need to connect to this flow, so drag two of these Widgets to your Canvas – one for Sales and one for Support.

Configure your Connect Call To Widgets

For each Connect Call To Widget on your Canvas, you'll need to set up your Sales and Support phone numbers. For the sake of testing, you can use any phone number you have access to. Click on each Widget and rename them: one should be connect_call_to_sales and the other should be connect_call_to_support.

Two widgets and the Widget Configuration panel. We see a widget for connect calls to sales and one to connect calls to support.

For each of these Widgets, connect the call to a single number of your choosing – make sure you're using different numbers for each Widget so you can test out the functionality of your IVR's routing!

Connect the calls

To connect your caller with the appropriate phone number, match the dangling dot from the Split Widget that says 1 to the Connect Call To Widget that you’ve set up for Sales, and the dot for 2 to the Widget for Support. Voila! Key presses are now a functional part of your IVR.

Two connect_call widgets are now attached to transitions for the split_key_press widget

Split Based on Voice

The final step for your IVR is to route users who choose to say "Sales" or "Support" rather than press keys on their phone. You'll use a Split Based On... Widget again, but you'll configure this one to accept a voice response.

Drag another Split Based On... Widget onto the Canvas. Rename this Widget to split_voice_input, and for Variable to test, use the SpeechResult variable from the gather_input Widget. This will ensure that your users' captured speech is able to route the call.

Next, click on the dot below "User Said Something" in your greet_caller Widget and connect it to the split_voice_input Widget you just added.

Split based on... widget added for voice input in our IVR. This widget is attached to the User Said Something transition in the gather_input widget.

Just as before, add conditions to your split_voice_input Widget for Sales or Support. The SpeechResult variable may contain punctuation such as a period at the end of the word. Instead of checking if SpeechResult is Equal To "Sales" or "Support", use the Contains predicate. This will check if the word "Sales" or "Support" is within SpeechResult, which would be evaluated to true even if SpeechResult has a value of "Sales." or "Support.".

Navigate to Transitions within the split_voice_input Widget and select the + button to create a new condition. Create conditions for both Sales and Support. Use the Contains predicate for each condition.

Twilio Studio IVR Tutorial Conditions Speech Result

Finishing your IVR Flow

If you take a look at your Canvas now, you should see a Trigger Widget that takes an incoming call, connects to the Gather Input on Call Widget, then splits to two Split Based On... Widgets (one for key press and one for speech result), each of which has condition matching Transitions to route to a Make Outgoing Call Widget for Sales or Support.

Twilio Studio IVR Tutorial Full Flow Image

After you've saved and published the flow, the last thing to do is hook up your flow to a phone number.

Connect your Twilio Phone Number to your IVR Flow

Once you’re happy with your Flow and you've published all changes, you can connect it to a Twilio Number so people can start interacting with it.

Navigate to the Active Numbers section of the Twilio Console and click on the number you’d like to connect to the Flow. (If you do not have any phone numbers, you can purchase one from the Console.)

After clicking on the number, you will see its configuration menu where you can connect the number to your Studio Flow.

To configure this number to trigger your Studio Flow from an Incoming Call, scroll down to the Voice & Fax section of the configuration menu. Under Configure With, select the dropdown option "Webhook, TwiML Bin, Function, Studio Flow, Proxy Service". Then, under A Call Comes In, select the dropdown option "Studio Flow". You'll see another dropdown menu appear where you can select the Studio Flow you'd like to connect to when a call comes in to this number.

Configure a Studio Flow to connect to a Voice number

Choose the Flow you'd like to connect the number to, and then press Save to save these changes. Your Flow is now connected to your Twilio number!

Test out your brand new IVR by calling the Twilio number that you’ve set for your IVR, and enjoy traversing the automated menu!

What's Next?

Now that you've created your first Studio-powered IVR system, why not dig into more of what you can accomplish with Twilio Studio? Learn how to:

Brent Schooley Kat King Ricky Holtz Shawn Stern Anton Horvath
Rate this page:

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 by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

Thank you for your feedback!

Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

Sending your feedback...
🎉 Thank you for your feedback!
Something went wrong. Please try again.

Thanks for your feedback!

Refer us and get $10 in 3 simple steps!

Step 1

Get link

Get a free personal referral link here

Step 2

Give $10

Your user signs up and upgrade using link

Step 3

Get $10

1,250 free SMSes
OR 1,000 free voice mins
OR 12,000 chats
OR more