This guide shows how to initiating call recordings for outbound API calls, Dial XML-connected calls, and conference calls. You can record inbound calls to a Plivo number too when the application associated with the number returns an XML document with a Dial and a Record element.
To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. You must have a voice-enabled Plivo phone number to receive incoming calls; you can rent numbers from the Numbers page of the Plivo console, or by using the Numbers API. If this is your first time using Plivo APIs, follow our instructions to set up a .NET development environment and a web server and safely expose that server to the internet.
You can record a complete call session using the Record XML element in conjunction with a Dial element response that’s returned by an answer URL. Recording a complete call is useful in applications such as virtual voicemail boxes and automated speech surveys.
The XML might look like this:
<Response>
<Record action="https://<yourdomain>.com/get_recording/" startOnDialAnswer="true" redirect="false" maxLength="3600" />
<Dial>
<Number>12025551234</Number>
</Dial>
</Response>
When the number specified in the Dial XML element answers the call, Plivo records the complete call session. Recording details are sent to the action URL as soon as the recording starts. You can use the attributes available in the Record XML element to control the recording behavior.
Create an MVC controller and paste into it this code.
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
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.AddRecord(new Dictionary < string, string > () {
{
"action",
"Https://<yourdomain>.com/get_recording/"
},
{
"startOnDialAnswer",
"true"
},
{
"redirect",
"false"
}
});
Plivo.XML.Dial dial = new Plivo.XML.Dial(new
Dictionary < string, string > () {});
dial.AddNumber("<phone_number>", new Dictionary < string, string > () {});
resp.Add(dial);
var output = resp.ToString();
Console.WriteLine(output);
}
}
}
Replace the phone number placeholder with an actual phone number (for example, 12025551234).
You can record a complete conference call initiated using a Conference XML element by using an XML response like this:
<Response>
<Conference callbackUrl="https://<yourdomain>.com/confevents/" callbackMethod="POST" record="true" recordFileFormat="wav">My Room</Conference>
</Response>
Plivo will record the complete audio of a conference call connected via this XML document. Recording details are sent to the action URL and callback URL as soon as the recording starts. The parameter ConferenceAction=record is also sent to the callback URL when the recording starts.
Create an MVC controller and paste into it this code.
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.AddConference("<conference_room_name>", new Dictionary < string, string > () {
{
"record",
"true"
},
{
"recordFileFormat",
"mp3"
},
{
"callbackUrl",
"https://<yourdomain>.com/confevents/"
},
{
"callbackMethod",
"POST"
},
{
"waitSound",
"https://<yourdomain>.com/waitmusic/"
}
});
var output = resp.ToString();
Console.WriteLine(output);
}
}
}
You can start and stop voice recordings for outbound API calls, Dial XML-connected calls, and conference calls using the Record API and Record Conference API.
To start recording using the Record API, you must use the CallUUID of the particular call that you want to record.
You can get the CallUUID of a call connected via the Outbound API and Dial XML from any of these arguments:
Once you have the CallUUID of the call you want to record, you can call the record API and specify the CallUUID in the payload.
For example, if you want to record an outbound API call, you can use the code below to record the call once the destination number answers the call. The recording will stop automatically once the call is completed.
Create an MVC controller and paste into it this code.
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
64
65
66
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Plivo;
using Plivo.XML;
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace Recordcall.Controllers {
public class RecordController: Controller {
// GET: /<controller>/
public IActionResult Index() {
var resp = new Response();
Plivo.XML.GetInput get_input = new
Plivo.XML.GetInput("", new Dictionary < string, string > () {
{
"action",
"https://<yourdomain>.com/record/action/"
},
{
"method",
"POST"
},
{
"digitEndTimeout",
"5"
},
{
"finishOnKey",
"#"
},
{
"inputType",
"dtmf"
},
{
"redirect",
"false"
},
});
resp.Add(get_input);
get_input.AddSpeak("Press 1 to record this call", new Dictionary < string, string > () {});
var output = resp.ToString();
return this.Content(output, "text/xml");
}
// Action URL
public String Action() {
String digits = Request.Query["Digits"];
String uuid = Request.Query["CallUUID"];
Debug.WriteLine("Digit pressed : {0}, Call UUID : {1}", digits, uuid);
if (digits == "1") {
string auth_id = "<auth_id>";
string auth_token = "<auth_token>";
var api = new PlivoApi(auth_id, auth_token);
var resp = api.Call.StartRecording(
callUuid: uuid);
Debug.WriteLine(resp);
}
else {
Debug.WriteLine("Invalid input");
}
return "OK";
}
}
}
Replace the auth placeholders with your authentication credentials from the Plivo console.
You can stop recording a call by using the CallUUID — see our API reference documentation.
To start recording conference calls using the Record Conference API, use the name of the conference you want to record. If you want to start recording a conference call once a participant has entered the conference room, you can use this code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
using System;
using System.Collections.Generic;
using Plivo;
using Plivo.Exception;
namespace PlivoExamples {
internal class Program {
public static void Main(string[] args) {
var api = new PlivoApi("<auth_id>","<auth_token>");
try {
var response = api.Conference.StartRecording("<conference_room_name>");
Console.WriteLine(response);
}
catch(PlivoRestException e) {
Console.WriteLine("Exception: " + e.Message);
}
}
}
}
Replace the auth placeholders with your authentication credentials from the Plivo console.
You can stop recording a conference call by using the conference name — see our API reference documentation.
Recordings hosted on Plivo servers are accessible only via unique, hard to guess, long URLs that Plivo shares in recording callbacks and API responses. By default, we do not enforce authentication on GET recording media requests to allow for easy implementation of use cases that involve playing recordings on a web or mobile front end.
For enhanced security, we recommend enabling basic authentication for retrieving recording media assets in your Plivo account. You can enable Basic Auth for Recording URLs from the Voice > Other Settings page of the Plivo console.