In this example, after a caller enters digits on the keypad, Plivo sends them as a request to the action URL. We also include a nested Speak element, so input can be gathered at any time during the Speak element.

If the caller enters a digit during the speaking of the text, the Speak element will stop speaking and wait for digits, the finishOnKey, or a timeout.

If the GetDigits element times out without input, the Speak element will complete and the GetDigits element will exit without submitting. Plivo will then process the next element in the document, which in this case is a Speak element that informs the caller that no input was received.

For a nested phone tree, you should return a GetDigits element from the action URL. In the top example, if the caller enters a four-digit PIN, Plivo will POST the Digits to the action URL, and your application can return the second XML example to play another message and accept input.

from plivo import plivoxml

response = plivoxml.ResponseElement()
response.add(
    plivoxml.GetDigitsElement(
        action='https://<yourdomain>.com/gather_pin/', method='POST').add(
            plivoxml.SpeakElement(
                'Enter PIN.')))
response.add(plivoxml.SpeakElement('Input not received.'))
print(response.to_string())
Response
<Response>
    <GetDigits action="https://<yourdomain>.com/gather_pin/" method="POST">
        <Speak>Enter your 4-digit pin number, followed by the hash key</Speak>
    </GetDigits>
    <Speak>Input not received</Speak>
</Response>
Return this XML to gather department:
<Response>
    <GetDigits action="https://<yourdomain>.com/gather_department/" method="POST">
        <Speak>Enter 1 for support and 2 for sales</Speak>
    </GetDigits>
</Response>