How to Gather User Input (IVR)
In this guide we will show you how to collect digits inputted by a user on their phone’s keypad for a period of time. Please ensure you have followed our earlier guide on how to make an outbound call with Bandwidth.
You can gather a user’s input to create an interactive voice response (IVR) system.
#
Gathering User InputThe <Gather>
verb is used to collect digits inputted by the user.
The gather is terminated when one of these conditions is met:
- The user presses any one of the
terminatingDigits
(if specified) - The user has pressed at least one key and more than
interDigitTimeout
seconds have elapsed - Any nested audio has ended and
firstDigitTimeout
seconds have elapsed without the user pressing any digits - The user presses
maxDigits
digits - If the
gatherUrl
attribute is specified, the Gather event is sent to thegatherUrl
upon completion of the gather. BXML returned by that callback are then executed. IfgatherUrl
is specified, verbs following the<Gather>
will be ignored.
If no gatherUrl
attribute is specified, the gathered digits are discarded and execution of verbs following the <Gather>
continues.
- XML
- Java
- C#
- Ruby
- NodeJS
- Python
- PHP
And endpoint /digitsCallback
should return:
The above number prompts the caller to input a number, after which the gather ends and a <SpeakSentence>
says the pressed number back to the caller.
#
Advanced IVR SystemTo further enhance your IVR system, additional verbs can be nested inside of a <Gather>
tag. These include playing media and text to speech. In this new example, the sentence "Please press a digit" will be said at the start of the call and after each press, instead of only at the beginning of the call.
- XML
- Java
- C#
- Ruby
- NodeJS
- Python
- PHP
In this example, there is one <SpeakSentence>
and two <PlayAudio>
nested within the gather. If, after playing, the caller doesn't press a button, the audio will replay two more times.
#
Where to next?Now that you have learnt how to build an IVR tree, check out some of the available actions in the following guides: