Latest Legacy

Record a voicemail

This example shows a simple voicemail 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 a default timeout of 15 seconds, falling through to the next element — in this case, the Speak element.

After the voicemail is recorded, Plivo POSTs 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="https://<yourdomain>.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. Press the star key or hang up when you're done."))
response.add(
    plivoxml.RecordElement(
        action='https://<yourdomain>.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. Press the star key or hang up when you're done."
  response.addSpeak(first_speak_body)

  params = {
      action: 'https://<yourdomain>.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
var plivo = require('plivo');

var response = plivo.Response();

var first_speak_body ="Please leave a message. Press the star key or hang up when you're done.";
response.addSpeak(first_speak_body);

var params = {
    'action': "https://<yourdomain>.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. Press the star key or hang up when you're done.</Speak>
    <Record action="https://<yourdomain>.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. Press the star key or hang up when you're done.";

    $response->addSpeak($first_speak_body);

    $params = array(
        'action' => "https://<yourdomain>.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. Press the star key or hang up when you're done.</Speak>
        <Record action="https://<yourdomain>.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("Please leave a message. Press the star key or hang up when you're done."),


                        new Record("https://<yourdomain>.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("Please leave a message. Press the star key or hang up when you're done.",
				new Dictionary<string, string>() { });
			resp.AddRecord(new Dictionary<string, string>() {
				{"action", "https://<yourdomain>.com/get_recording/"},
				{"maxLength", "30"},
				{"finishOnKey", "*"}
			});
			resp.AddSpeak("Recording not received.",
				new Dictionary<string, string>() { });

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

		}
	}
}



//<Response>
//  <Speak>Please leave a message. Press the star key or hang up when you're done.</Speak>
//  <Record action = "https://<yourdomain>.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/v7/xml"

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

			new(xml.SpeakElement).
				AddSpeak("Please leave a message. Press the star key or hang up when you're done"),

			new(xml.RecordElement).
				SetAction("https://<yourdomain>.com/get_recording/").
				SetFinishOnKey("*").
				SetMaxLength(20),

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