<Response> <GetDigits action="https://example.com/ivr/" numDigits="1" timeout="10" retries="2"> <Speak> Welcome to Acme Corp. Press 1 for sales. Press 2 for support. Press 3 for billing. Press 0 to speak with an operator. </Speak> </GetDigits> <Speak>Sorry, we didn't receive valid input. Goodbye.</Speak></Response>
Handle the input on your server:
# Flask example@app.route('/ivr/', methods=['POST'])def handle_ivr(): digits = request.form.get('Digits') response = plivoxml.ResponseElement() if digits == '1': response.add(plivoxml.SpeakElement('Connecting you to sales.')) dial = plivoxml.DialElement() dial.add(plivoxml.NumberElement('+14155551111')) response.add(dial) elif digits == '2': response.add(plivoxml.SpeakElement('Connecting you to support.')) dial = plivoxml.DialElement() dial.add(plivoxml.NumberElement('+14155552222')) response.add(dial) elif digits == '3': response.add(plivoxml.RedirectElement('https://example.com/billing-menu/')) elif digits == '0': response.add(plivoxml.SpeakElement('Please hold for an operator.')) dial = plivoxml.DialElement() dial.add(plivoxml.NumberElement('+14155550000')) response.add(dial) else: response.add(plivoxml.SpeakElement('Invalid option.')) response.add(plivoxml.RedirectElement('https://example.com/ivr-start/')) return Response(response.to_string(), mimetype='application/xml')
<Response> <GetDigits action="https://example.com/handle-input/" finishOnKey="#" timeout="15"> <Speak> Enter your account number followed by the pound key. </Speak> </GetDigits></Response>
Collect digits without redirecting (fire and forget):
<Response> <GetDigits action="https://example.com/log-input/" redirect="false" numDigits="1"> <Speak>Press any key to confirm you're listening.</Speak> </GetDigits> <Speak>Thank you. Continuing with your call.</Speak></Response>
The <GetInput> element collects user input through automatic speech recognition (ASR) or DTMF digit presses. It’s the recommended replacement for <GetDigits>, supporting both speech and digit input.
<Response> <GetInput action="https://example.com/handle-input/" inputType="dtmf speech"> <Speak>How can I help you today? You can say your request or press 1 for sales, 2 for support.</Speak> </GetInput> <Speak>We didn't receive any input. Please try again.</Speak></Response>
from plivo import plivoxmlresponse = plivoxml.ResponseElement()getinput = plivoxml.GetInputElement( action='https://example.com/handle-input/', input_type='dtmf speech')getinput.add_speak('How can I help you today?')response.add(getinput)response.add(plivoxml.SpeakElement("We didn't receive any input."))print(response.to_string())
Seconds to wait for the caller to begin providing input. Distinct from executionTimeout (total time), digitEndTimeout (between digits), and speechEndTimeout (end of speech)
retries
integer
1
Number of times to retry input collection if no valid input is received
<GetInput action="/handle-input/" inputType="speech" speechModel="command_and_search" language="en-US"> <Speak>What would you like to do?</Speak></GetInput>
<GetInput action="/handle-input/" inputType="speech" hints="account balance, transfer money, pay bill, customer service"> <Speak>How can I help you with your account today?</Speak></GetInput>