Confirm to Answer Call

In the case where multiple calls are fired, the first person to answer gets connected and the rest of the calls are dropped. We need to make sure that the call is not answered by a voice mail and it is indeed a person who is connected. In such cases you would use the confirmKey and confirmSound attribute.

The example XML would require the callee to input the digit 5 after answering the call to connect.

Plivo will request the confirmSound URL using the POST HTTP method for a valid Play, Speak or a Wait XML. To play a message to input a DTMF tone to connect the call, you should return the second XML.

Response

<Response>
    <Dial confirmSound="http://foo.com/confirm_sound/" confirmKey="5">
        <Number>18217654321</Number>
        <Number>15671234567</Number>
        <Number>15671289109</Number>
    </Dial>
</Response>

Return the following XML to play a message.

<Response>
    <Speak>Enter the digit 5 to connect the call</Speak>
</Response>

Example Request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from plivo import plivoxml

response = plivoxml.ResponseElement()
response.add(
    plivoxml.DialElement(
        confirm_key='5', confirm_sound='http://foo.com/confirm_sound/').add(
            plivoxml.NumberElement('18217654321')).add(
                plivoxml.NumberElement('15671234567')).add(
                    plivoxml.NumberElement('15671289109')))
print(response.to_string())

# XML to play the message
play_message_response = plivoxml.ResponseElement()
play_message_response.add(
    plivoxml.SpeakElement('Enter the digit 5 to connect the call'))
print(play_message_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
require 'rubygems'
require 'plivo'

include Plivo::XML
include Plivo::Exceptions

begin
  response = Response.new

  params = {
      'confirmSound' => "https://www.foo.com/confirm_sound/",
      'confirmKey' => "5"
  }

  dial = response.addDial(params)
  first_number = "1111111111"
  dial.addNumber(first_number)

  second_number = "2222222222"
  dial.addNumber(second_number)

  third_number = "3333333333"
  dial.addNumber(third_number)

  xml = PlivoXML.new(response)
  puts xml.to_xml
rescue PlivoXMLError => e
  puts 'Exception: ' + e.message
end

begin
  response = Response.new

  speak_body = "Enter the digit 5 to connect the call"
  response.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
var plivo = require('plivo');

var response = plivo.Response();

var params = {
    'confirmSound': "https://www.foo.com/confirm_sound/",
    'confirmKey': "5"
};
var dial = response.addDial(params);

var first_number = "1111111111";
dial.addNumber(first_number);

var second_number = "2222222222";
dial.addNumber(second_number);

var third_number = "3333333333";
dial.addNumber(third_number);

console.log(response.toXML());

/*
Sample Output
<Response>
    <Dial confirmSound="https://www.foo.com/confirm_sound/" confirmKey="5">
        <Number>1111111111</Number>
        <Number>2222222222</Number>
        <Number>3333333333</Number>
    </Dial>
</Response>
*/


/* Code to generate XML to be returned from url at confirmSound */

var plivo = require('plivo');

var response = plivo.Response();

var speak_body = "Enter the digit 5 to connect the call";
response.addSpeak(speak_body);

console.log(response.toXML());

/*
Sample Output
<Response>
    <Speak>Enter the digit 5 to connect the call</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
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
<?php
    require '../vendor/autoload.php';
    use Plivo\XML\Response;

    $response = new Response();

    $params = array(
        'confirmSound'=>"https://www.foo.com/confirm_sound/",
        'confirmKey' => "5"
    );

    $dial = $response->addDial($params);
    $first_number = "1111111111";
    $dial->addNumber($first_number);
    $second_number = "2222222222";
    $dial->addNumber($second_number);
    $third_number = "3333333333";
    $dial->addNumber($third_number);

    Header('Content-type: text/xml');
    echo($response->toXML());

    /*
    Sample Output

    <Response>
        <Dial confirmSound = "https://www.foo.com/confirm_sound/" confirmKey="5">
            <Number>1111111111</Number>
            <Number>2222222222</Number>
            <Number>3333333333</Number>
        </Dial>
    </Response>
    */
?>

<?php
    /* XML to be returned by confirmSound */
    require '../vendor/autoload.php';
    use Plivo\XML\Response;

    $response = new Response();

    $speak_body = "Enter the digit 5 to connect the call";
    $response->addSpeak($speak_body);

    Header('Content-type: text/xml');
    echo($response->toXML());

    /*
    Sample Output

    <Response>
        <Speak>Enter the digit 5 to connect the call</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
25
26
27
28
29
30
31
32
// Example for dial - confirm to answer call
package com.plivo.api.xml.samples.dial;

import com.plivo.api.exceptions.PlivoXmlException;
import com.plivo.api.xml.Dial;
import com.plivo.api.xml.Number;
import com.plivo.api.xml.Response;


class ConfirmToAnswerCall {
    public static void main(String[] args) throws PlivoXmlException {
        Response response = new Response()
                .children(


                        new Dial()
                                .confirmKey("5")
                                .confirmSound("http://foo.com/confirm_sound/")
                                .children(
                                        new Number("18217654321"),


                                        new Number("15671234567"),


                                        new Number("15671289109")
                                )

                );
        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
41
42
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.Dial dial = new Plivo.XML.Dial(new
				Dictionary<string, string>() {
				{"confirmSound", "http://foo.com/sound/"},
				{"confirmKey", "3"}
			});

			dial.AddNumber("15551234567",
				new Dictionary<string, string>() { });
			dial.AddNumber("18217654321",
				new Dictionary<string, string>() { });
			dial.AddNumber("15671289109",
				new Dictionary<string, string>() { });
			resp.Add(dial);

			var output = resp.ToString();
			Console.WriteLine(output);

		}
	}
}



//<Response>
//  <Dial confirmSound = "http://foo.com/sound/" 
//    confirmKey="3">
//    <Number>15551234567</Number>
//    <Number>18217654321</Number>
//    <Number>15671289109</Number>
//  </Dial>
//</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
// Example for dial - confirm to answer call
package main

import "github.com/plivo/plivo-go/xml"

func main() {
	response := xml.ResponseElement{
		Contents: []interface{}{

			new(xml.DialElement).
				SetConfirmKey("5").
				SetConfirmSound("http://foo.com/confirm_sound/").
				SetContents([]interface{}{
					new(xml.NumberElement).
						SetContents("18217654321"),

					new(xml.NumberElement).
						SetContents("15671234567"),

					new(xml.NumberElement).
						SetContents("15671289109"),
				}),
		},
	}
	print(response.String())
}