Phone Tree

    After the caller enters digits on the keypad, Plivo sends them as a request to the action URL. We also add a nested Speak> element. This means that input can be gathered at any time during <Speak>.

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

    If <GetDigits> tag 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 which informs the caller that no input was received.

    For a nested phone tree, you should return a GetDigits XML from the action URL. In the above case, when the caller enters the 4 digit pin number, Plivo will POST the Digits to the action URL, your application should return the second XML to play another message and accept inputs.

    Response

    <Response>
        <GetDigits action="http://www.foo.com/gather_pin/" method="POST">
            <Speak>Enter your 4-digit pin number, followed by the hash key</Speak>
        </GetDigits>
        <Speak>Input not received. Thank you</Speak>
    </Response>
    

    Return the following XML to gather department:

    <Response>
        <GetDigits action="http://www.foo.com/gather_department/" method="POST">
            <Speak>Enter 1 for support and 2 for sales</Speak>
        </GetDigits>
    </Response>
    

    Example Request

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    
    from plivo import plivoxml
    
    response = plivoxml.ResponseElement()
    response.add(
        plivoxml.GetDigitsElement(
            action='http://www.foo.com/gather_pin/', method='POST').add(
                plivoxml.SpeakElement(
                    'Enter your 4-digit pin number, followed by the hash key')))
    response.add(plivoxml.SpeakElement('Input not received. Thank you'))
    print(response.to_string())
    
    # XML to gather department
    get_dept_digits_response = plivoxml.ResponseElement()
    get_dept_digits_response.add(
        plivoxml.GetDigitsElement(
            action='http://www.foo.com/gather_department/', method='POST').add(
                plivoxml.SpeakElement('Enter 1 for support and 2 for sales')))
    print(get_dept_digits_response.to_string())
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    
    require 'rubygems'
    require 'plivo'
    
    include Plivo::XML
    include Plivo::Exceptions
    
    begin
      response = Response.new
    
      params = {
          action: 'https://www.foo.com/gather_pin/',
          method: 'POST'
      }
    
      get_digits = response.addGetDigits(params)
      input_received_speak = 'Enter the 4-digit pin number, followed by the hash key'
      get_digits.addSpeak(input_received_speak)
    
      input_not_received_speak = 'Input not received. Thank you'
      response.addSpeak(input_not_received_speak)
    
      xml = PlivoXML.new(response)
      puts xml.to_xml
    rescue PlivoXMLError => e
      puts 'Exception: ' + e.message
    end
    
    begin
      response = Response.new
    
      params = {
          action: 'https://www.foo.com/gather_department/',
          method: 'POST'
      }
    
      get_digits = response.addGetDigits(params)
      speak_body = 'Enter 1 for support and 2 for sales'
      get_digits.addSpeak(speak_body)
      
      xml = PlivoXML.new(response)
      puts xml.to_xml
    rescue PlivoXMLError => e
      puts 'Exception: ' + e.message
    end
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    
    var plivo = require('plivo');
    
    var response = plivo.Response();
    
    var params = {
        'action': "https://www.foo.com/gather_pin/",
        'method': "POST"
    };
    var get_digits = response.addGetDigits(params);
    
    var input_received_speak = "Enter your 4-digit pin number, followed by the hash key";
    get_digits.addSpeak(input_received_speak);
    
    var input_not_received_speak = "Input not received. Thank you";
    response.addSpeak(input_not_received_speak);
    
    console.log(response.toXML());
    
    /*
    Sample Output
    <Response>
        <GetDigits action="https://www.foo.com/gather_pin/" method="POST">
            <Speak>Enter your 4-digit pin number, followed by the hash key</Speak>
        </GetDigits>
        <Speak>Input not received. Thank you</Speak>
    </Response>
    */
    
    
    /* Code to generate XML to be returned from url at action */
    
    var plivo = require('plivo');
    
    var response = plivo.Response();
    
    var params = {
            'action': "https://www.foo.com/gather_department/",
            'method': "POST"
    };
    var get_digits = response.addGetDigits(params);
    
    var speak_body = "Enter 1 for support and 2 for sales";
    get_digits.addSpeak(speak_body);
    
    console.log(response.toXML());
    
    /*
    Sample Output
    <Response>
        <GetDigits action="https://www.foo.com/gather_department/" method="POST">
            <Speak>Enter 1 for support and 2 for sales</Speak>
        </GetDigits>
    </Response>
    */
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    
    <?php
        require '../vendor/autoload.php';
        use Plivo\XML\Response;
    
        $response = new Response();
    
        $params = array(
            'action' => "https://www.foo.com/gather_pin/",
            'method' => "POST"
        );
    
        $get_digits = $response->addGetDigits($params);
        $input_received_speak = "Enter your 4-digit pin number, followed by the hash key";
        $get_digits->addSpeak($input_received_speak);
    
        $input_not_received_speak = "Input not received. Thank you";
        $response->addSpeak($input_not_received_speak);
    
        Header('Content-type: text/xml');
        echo($response->toXML());
    
        /*
        Sample Output
    
        <Response>
            <GetDigits action="https://www.foo.com/gather_pin/" method="POST">
                <Speak>Enter your 4-digit pin number, followed by the hash key</Speak>
            </GetDigits>
            <Speak>Input not received. Thank you</Speak>
        </Response>
        */
    ?>
    
    <?php
        /* XML to be returned by the redirect URL */
    
        require '../vendor/autoload.php';
        use Plivo\XML\Response;
    
        $response = new Response();
    
        $params = array(
            'action' => "https://www.foo.com/gather_department/",
            'method' => "POST"
        );
    
        $get_digits = $response->addGetDigits($params);
        $speak_body = "Enter 1 for support and 2 for sales";
        $get_digits->addSpeak($speak_body);
    
        Header('Content-type: text/xml');
        echo($response->toXML());
    
        /*
        Sample Output
    
        <Response>
            <GetDigits action="https://www.foo.com/gather_department/" method="POST">
                <Speak>Enter 1 for support and 2 for sales</Speak>
            </GetDigits>
        </Response>
        */
    ?>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    
    // Example for getdigits - phone tree
    package com.plivo.api.xml.samples.getdigits;
    
    import com.plivo.api.exceptions.PlivoXmlException;
    import com.plivo.api.xml.GetDigits;
    import com.plivo.api.xml.Response;
    import com.plivo.api.xml.Speak;
    
    
    class PhoneTree {
        public static void main(String[] args) throws PlivoXmlException {
            Response response = new Response()
                    .children(
    
    
                            new GetDigits()
                                    .action("http://www.foo.com/gather_pin/")
                                    .method("POST")
                                    .children(
                                            new Speak("Enter pin number followed by hash key")
                                    ),
    
    
                            new Speak("Input not received. Thank you.")
                    );
            System.out.println(response.toXmlString());
        }
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    
    using System;
    using System.Collections.Generic;
    using Plivo.XML;
    
    namespace Plivo
    {
    	class MainClass
    	{
    		public static void Main(string[] args)
    		{
    			Plivo.XML.Response resp = new Plivo.XML.Response();
    			Plivo.XML.GetDigits get_digits = new
    				Plivo.XML.GetDigits("",
    				   new Dictionary<string, string>()
    			{
    				{"action", "http://www.foo.com/gather_pin/"},
    				{ "method", "POST" }
    			});
    			resp.Add(get_digits);
    
    			get_digits.AddSpeak("Enter PIN number.",
    				new Dictionary<string, string>() { });
    			resp.AddSpeak("Input not recieved.",
    				new Dictionary<string, string>() { });
    			var output = resp.ToString();
    			Console.WriteLine(output);
    
    		}
    	}
    }
    
    
    
    //<Response>
    //  <GetDigits action = "http://www.foo.com/gather_pin/" 
    //    method="POST">
    //    <Speak>Enter PIN number.</Speak>
    //  </GetDigits>
    //  <Speak>Input not recieved.</Speak>
    //</Response>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    
    // Example for getdigits - phone tree
    package main
    
    import "github.com/plivo/plivo-go/xml"
    
    func main() {
    	response := xml.ResponseElement{
    		Contents: []interface{}{
    
    			new(xml.GetDigitsElement).
    				SetAction("http://www.foo.com/gather_pin/").
    				SetMethod("POST").
    				SetContents([]interface{}{
    
    					new(xml.SpeakElement).
    						SetContents("\tEnter pin number followed by hash key"),
    				}),
    
    			new(xml.SpeakElement).
    				SetContents("Input not received. Thank you."),
    		},
    	}
    	print(response.String())
    }