Latest Legacy

Beep detection

You can use the Wait element to aid leaving voice mails on answering machines by adding an extra parameter called beep and setting it to true.

Response

<Response>
    <Wait length="120" beep="true"/>
    <Play>https://s3.amazonaws.com/plivocloud/Trumpet.mp3</Play>
</Response>

Explanation

In this example, upon the call being answered, the Wait element waits for 120 seconds for a beep sound to be received. If a beep sound is detected before the Wait length times out, the Wait element ends and the Play verb is issued, and plays the specified MP3 file on the remote machine that sounded the beep.

If the Wait element times out after 120 seconds, the XML flow skips to the Play element.

Example Request

1
2
3
4
5
6
from plivo import plivoxml

response = (plivoxml.ResponseElement()
            .add(plivoxml.WaitElement(None).set_beep(True).set_length(10))
            .add(plivoxml.PlayElement('https://s3.amazonaws.com/Trumpet.mp3')))
print(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
require 'rubygems'
require 'plivo'

include Plivo::XML
include Plivo::Exceptions

begin
  response = Response.new

  params = {
    length: '120',
    beep: true
  }
  response.addWait(params)

  play_url = 'https://s3.amazonaws.com/plivocloud/Trumpet.mp3'
  response.addPlay(play_url)

  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
var plivo = require('plivo');

var response = plivo.Response();

var params = {
        'length': "120",
        'beep': "true"
};
response.addWait(params);

var play_url =  "https://s3.amazonaws.com/plivocloud/Trumpet.mp3";
response.addPlay(play_url);

console.log(response.toXML());

/*
Sample Output
<Response>
    <Wait length="120" beep="true"/>
    <Play>
        https://s3.amazonaws.com/plivocloud/Trumpet.mp3
    </Play>
</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
<?php
    require '../vendor/autoload.php';
    use Plivo\XML\Response;

    $response = new Response();

    $params = array(
        'length' => "120",
        'beep' => "true"
    );
    $response->addWait($params);

    $play_url = "https://s3.amazonaws.com/plivocloud/Trumpet.mp3";
    $response->addPlay($play_url);

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

    /*
    Sample Output

    <Response>
        <Wait length="120" beep="true"/>
        <Play>
            https://s3.amazonaws.com/plivocloud/Trumpet.mp3
        </Play>
    </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 wait - beep detection
package com.plivo.api.xml.samples.wait;

import com.plivo.api.exceptions.PlivoXmlException;
import com.plivo.api.xml.Play;
import com.plivo.api.xml.Response;
import com.plivo.api.xml.Wait;


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


                        new Wait()
                                .beep(true)
                                .length(10),


                        new Play("https://s3.amazonaws.com/Trumpet.mp3")

                );
        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
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();
			resp.AddWait(new Dictionary<string, string>()
			{
				{"length", "120"}, {"beep", "true"}
			});
			resp.AddPlay("https://s3.amazonaws.com/abc.mp3", 
             new Dictionary<string, string>() { });
			var output = resp.ToString();
			Console.WriteLine(output);

		}
	}
}



//<Response>
//  <Wait length = "120" beep="true" />
//  <Play>https://s3.amazonaws.com/abc.mp3</Play>
//</Response>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Example for wait - beep detection
package main

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

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

			new(xml.WaitElement).
				SetBeep(true).
				SetLength(10),

			new(xml.PlayElement).
				SetContents("https://s3.amazonaws.com/Trumpet.mp3"),
		},
	}
	print(response.String())
}