Phone tree

    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.

    Response

    <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>
    

    Return this XML to gather department:

    <Response>
        <GetDigits action="https://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='https://www.foo.com/gather_pin/', method='POST').add(
                plivoxml.SpeakElement(
                    'Enter your 4-digit PIN, followed by the hash key')))
    response.add(plivoxml.SpeakElement('Input not received.'))
    print(response.to_string())
    
    # XML to gather department
    get_dept_digits_response = plivoxml.ResponseElement()
    get_dept_digits_response.add(
        plivoxml.GetDigitsElement(
            action='https://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, followed by the hash key'
      get_digits.addSpeak(input_received_speak)
    
      input_not_received_speak = 'Input not received.'
      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, followed by the hash key";
    get_digits.addSpeak(input_received_speak);
    
    var input_not_received_speak = "Input not received.";
    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, followed by the hash key</Speak>
        </GetDigits>
        <Speak>Input not received.</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, followed by the hash key";
        $get_digits->addSpeak($input_received_speak);
    
        $input_not_received_speak = "Input not received.";
        $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, followed by the hash key</Speak>
            </GetDigits>
            <Speak>Input not received.</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("https://www.foo.com/gather_pin/")
                                    .method("POST")
                                    .children(
                                            new Speak("Enter PIN followed by hash key")
                                    ),
    
    
                            new Speak("Input not received.")
                    );
            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", "https://www.foo.com/gather_pin/"},
    				{ "method", "POST" }
    			});
    			resp.Add(get_digits);
    
    			get_digits.AddSpeak("Enter PIN.",
    				new Dictionary<string, string>() { });
    			resp.AddSpeak("Input not received.",
    				new Dictionary<string, string>() { });
    			var output = resp.ToString();
    			Console.WriteLine(output);
    
    		}
    	}
    }
    
    
    
    //<Response>
    //  <GetDigits action = "https://www.foo.com/gather_pin/" 
    //    method="POST">
    //    <Speak>Enter PIN.</Speak>
    //  </GetDigits>
    //  <Speak>Input not received.</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("https://www.foo.com/gather_pin/").
    				SetMethod("POST").
    				SetContents([]interface{}{
    
    					new(xml.SpeakElement).
    						SetContents("\tEnter PIN followed by hash key"),
    				}),
    
    			new(xml.SpeakElement).
    				SetContents("Input not received."),
    		},
    	}
    	print(response.String())
    }