Record a voice mail

This is an example of a simple voice mail recording. The caller is asked to leave a message after the beep. The Record element beeps and begins recording up to 30 seconds of audio.

If the caller remains silent, the Record element exits after 15 seconds, falling through to the next element. In this case, it would fall through to the Speak element.

After the voice mail has been recorded, Plivo will POST the recorded URL to the action URL.

Response

<Response>
  <Speak>Please leave a message after the beep. Press the star key when done.</Speak>
  <Record action="http://foo.com/get_recording/" finishOnKey="*" maxLength="30"></Record>
  <Speak>Recording not received.</Speak>
</Response>

Example Request

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

response = plivoxml.ResponseElement()
response.add(
    plivoxml.SpeakElement(
        'Please leave a message after the beep. Press the star key when done.'))
response.add(
    plivoxml.RecordElement(
        action='http://foo.com/get_recording/',
        max_length=30,
        finish_on_key='*'))
response.add(plivoxml.SpeakElement('Recording not received.'))
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
24
25
26
27
require 'rubygems'
require 'plivo'

include Plivo::XML
include Plivo::Exceptions

begin
  response = Response.new

  first_speak_body = 'Please leave a message after the beep. Press the star key when done.'
  response.addSpeak(first_speak_body)

  params = {
      action: 'https://www.foo.com/get_recording/',
      maxLength: '30',
      finishOnKey: '*'
  }
  response.addRecord(params)

  second_speak_body = 'Recording not received.'
  response.addSpeak(second_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
var plivo = require('plivo');

var response = plivo.Response();

var first_speak_body ="Please leave a message after the beep. Press the star key when done.";
response.addSpeak(first_speak_body);

var params = {
    'action': "https://www.foo.com/get_recording/",
    'maxLength': "30",
    'finishOnKey': "*"
};
response.addRecord(params);

var second_speak_body = "Recording not received.";
response.addSpeak(second_speak_body);

console.log(response.toXML());

/*
Sample Output
<Response>
    <Speak>Please leave a message after the beep. Press the
    star key when done.</Speak>
    <Record action="https://www.foo.com/get_recording/" maxLength="30" finishOnKey="*"/>
    <Speak>Recording 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
25
26
27
28
29
30
31
32
33
34
<?php
    require '../vendor/autoload.php';
    use Plivo\XML\Response;

    $response = new Response();

    $first_speak_body = "Please leave a message after the beep. Press the star key when done.";

    $response->addSpeak($first_speak_body);

    $params = array(
        'action' => "https://www.foo.com/get_recording/",
        'maxLength' => "30",
        'finishOnKey' => "*"
    );

    $response->addRecord($params);

    $second_speak_body = "Recording not received.";
    $response->addSpeak($second_speak_body);

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

    /*
    Sample Output

    <Response>
        <Speak>Please leave a message after the beep. Press the star key when done.</Speak>
        <Record action="https://www.foo.com/get_recording/" maxLength="30" finishOnKey="*"/>
        <Speak>Recording 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
25
26
27
28
29
// Example for record - record a voicemail
package com.plivo.api.xml.samples.record;

import com.plivo.api.exceptions.PlivoXmlException;
import com.plivo.api.xml.Record;
import com.plivo.api.xml.Response;
import com.plivo.api.xml.Speak;


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


                        new Speak("Leave message. Press star key when done"),


                        new Record("http://foo.com/get_recording/")
                                .finishOnKey("*")
                                .maxLength(20),


                        new Speak("Recording 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
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.AddSpeak("Leave message after the beep.",
				new Dictionary<string, string>() { });
			resp.AddRecord(new Dictionary<string, string>() {
				{"action", "http://foo.com/get_recording/"},
				{"maxLength", "30"},
				{"finishOnKey", "*"}
			});
			resp.AddSpeak("Recording not received.",
				new Dictionary<string, string>() { });

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

		}
	}
}



//<Response>
//  <Speak>Leave message after the beep.</Speak>
//  <Record action = "http://foo.com/get_recording/" 
//    maxLength="30" finishOnKey="*" />
//  <Speak>Recording 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
// Example for record - record voicemail
package main

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

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

			new(xml.SpeakElement).
				SetContents("Leave message.Press star key when done"),

			new(xml.RecordElement).
				SetAction("http://foo.com/get_recording/").
				SetFinishOnKey("*").
				SetMaxLength(20),

			new(xml.SpeakElement).
				SetContents("Recording not received."),
		},
	}
	print(response.String())
}