- Node
- Ruby
- Python
- PHP
- .NET
- Java
- Go
Overview
You can use voicemail to capture a caller’s message if a call recipient is unavailable. This guide shows how to set up voicemail, either by using our PHLO visual workflow builder or our APIs and XML documents. Follow the instructions in one of the tabs below.- Using XML
Here’s how to implement voicemail using XML.
Save the file and run it.You should see your basic server application in action at http://localhost:3000/voicemail/.

How it works

Prerequisites
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 Node.js development environment and a web server and safely expose that server to the internet.Create an Express server to implement voicemail
Create a file calledvoicemail.js and paste into it this code.Copy
Ask AI
var plivo = require('plivo');
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({extended: true}));
app.set('port', (process.env.PORT || 5000));
app.post('/voicemail/', function(request, response) {
var r = plivo.Response();
var params;
params = {
'action': "https://<yourdomain>.com/get_recording/",
'finishOnKey': "*",
'maxLength': "20"
};
r.addRecord(params);
var second_speak_body = "Recording not received";
r.addSpeak(second_speak_body);
console.log(r.toXML());
response.set({'Content-Type': 'text/xml'});
response.send(r.toXML());
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
Copy
Ask AI
$ node voicemail.js
Create a Plivo application for voicemail
Associate the Express server you created with Plivo by creating a Plivo application. Visit Voice > Applications in the Plivo console and click on Add New Application, or use Plivo’s Application API.Give your application a name — we called oursVoicemail. Enter the server URL you want to use (for example https://<yourdomain>.com/voicemail/) in the Answer URL field and set the method to GET. Click Create Application to save your application.
Assign a Plivo number to your application
Navigate to the Numbers page and select the phone number you want to use for this application.From the Application Type drop-down, selectXML Application.From the Plivo Application drop-down, select Voicemail (the name we gave the application).Click Update Number to save.
Test
Make a call to your Plivo number and leave yourself a voicemail message.Overview
You can use voicemail to capture a caller’s message if a call recipient is unavailable. This guide shows how to set up voicemail, either by using our PHLO visual workflow builder or our APIs and XML documents. Follow the instructions in one of the tabs below.- Using XML
Here’s how to implement voicemail using XML.
This command generates a controller named plivo_controller in the app/controllers/ directory and a respective view in app/views/plivo. We can delete the view as we do not need it.Edit app/controllers/plivo_controller.rb and paste this code into the PlivoController class.Start the Rails serverYou should see your basic server application in action at http://localhost:3000/plivo/voicemail/.

How it works

Prerequisites
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 Ruby development environment and a web server and safely expose that server to the internet.Create a Rails controller to implement voicemail
Change to the project directory and run this command to create a Rails controller for inbound calls.Copy
Ask AI
$ rails generate controller Plivo voice
Copy
Ask AI
$ rm app/views/plivo/voice.html.erb
Copy
Ask AI
include Plivo
include Plivo::XML
include Plivo::Exceptions
class PlivoController < ApplicationController
def voicemail
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)
render xml: xml.to_xml
end
end
Add a route
To add a route for the inbound function in the PlivoController class, edit config/routes.rb and add this line after the inbound route.Copy
Ask AI
get 'plivo/voicemail'
Copy
Ask AI
$ rails server
Create a Plivo application for voicemail
Associate the Rails controller you created with Plivo by creating a Plivo application. Visit Voice > Applications in the Plivo console and click on Add New Application, or use Plivo’s Application API.Give your application a name — we called oursVoicemail. Enter the server URL you want to use (for example https://<yourdomain>.com/voicemail/) in the Answer URL field and set the method to GET. Click Create Application to save your application.
Assign a Plivo number to your application
Navigate to the Numbers page and select the phone number you want to use for this application.From the Application Type drop-down, selectXML Application.From the Plivo Application drop-down, select Voicemail (the name we gave the application).Click Update Number to save.
Test
Make a call to your Plivo number and leave yourself a voicemail message.Overview
You can use voicemail to capture a caller’s message if a call recipient is unavailable. This guide shows how to set up voicemail, either by using our PHLO visual workflow builder or our APIs and XML documents. Follow the instructions in one of the tabs below.- Using XML
Here’s how to implement voicemail using XML.
Save the file and run it.You should see your basic server application in action at http://localhost:5000/voicemail/.

How it works

Prerequisites
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 Python development environment and a web server and safely expose that server to the internet.Create a Flask server to implement voicemail
Create a file calledvoicemail.py and paste into it this code.Copy
Ask AI
# -*- coding: utf-8 -*-
from flask import Flask, Response, request, url_for
from plivo import plivoxml
app = Flask(__name__)
@app.route('/voicemail/', methods=['GET','POST'])
def voicemail():
response = plivoxml.ResponseElement()
response.add(
plivoxml.SpeakElement(
'Please leave a message. Press the star key 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'))
return Response(response.to_string(), mimetype='application/xml')
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
Copy
Ask AI
$ python voicemail.py
Create a Plivo application for voicemail
Associate the Flask server you created with Plivo by creating a Plivo application. Visit Voice > Applications in the Plivo console and click on Add New Application, or use Plivo’s Application API.Give your application a name — we called oursVoicemail. Enter the server URL you want to use (for example https://<yourdomain>.com/voicemail/) in the Answer URL field and set the method to GET. Click Create Application to save your application.
Assign a Plivo number to your application
Navigate to the Numbers page and select the phone number you want to use for this application.From the Application Type drop-down, selectXML Application.From the Plivo Application drop-down, select Voicemail (the name we gave the application).Click Update Number to save.
Test
Make a call to your Plivo number and leave yourself a voicemail message.Overview
You can use voicemail to capture a caller’s message if a call recipient is unavailable. This guide shows how to set up voicemail, either by using our PHLO visual workflow builder or our APIs and XML documents. Follow the instructions in one of the tabs below.- Using XML
Here’s how to implement voicemail using XML.
This generate a controller named VoicemailController in the app/http/controllers/ directory. Edit app/http/controllers/VoicemailController.php and paste into it this code.Start the Laravel server.You should see your basic server application in action at http://localhost:8000/voicemail.

How it works

Prerequisites
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 PHP development environment and a web server and safely expose that server to the internet.Create a Laravel controller to implement voicemail
Change to the project directory run this command to create a Laravel controller for inbound calls.Copy
Ask AI
$ php artisan make:controller VoicemailController
Copy
Ask AI
<?php
namespace App\Http\Controllers;
require '../../vendor/autoload.php';
use Plivo\RestClient;
use Plivo\XML\Response;
use Illuminate\Http\Request;
class VoicemailController extends Controller
{
// Record XML to handle the incoming call
public function voicemailMain()
{
$response = new Response();
$first_speak_body = "Please leave a message . Press the star key when you're done";
$response->addSpeak($first_speak_body);
$params = array(
'action' => "https://<yourdomain>.com/get_recording/",
'finishOnKey' => "*",
'maxLength' => "20"
);
$response->addRecord($params);
$second_speak_body = "Recording not received";
$response->addSpeak($second_speak_body);
Header('Content-type: text/xml');
echo $r->toXML();
}
}
Add a route
To add a route for the inbound function in the VoicemailController class, edit routes/web.php file and add this line.Copy
Ask AI
Route::match(['get', 'post'], '/voicemail', 'VoicemailController@voicemailMain');
Copy
Ask AI
$ php artisan serve
Create a Plivo application for voicemail
Associate the Laravel controller you created with Plivo by creating a Plivo application. Visit Voice > Applications in the Plivo console and click on Add New Application, or use Plivo’s Application API.Give your application a name — we called oursVoicemail. Enter the server URL you want to use (for example https://<yourdomain>.com/voicemail/) in the Answer URL field and set the method to GET. Click Create Application to save your application.
Assign a Plivo number to your application
Navigate to the Numbers page and select the phone number you want to use for this application.From the Application Type drop-down, selectXML Application.From the Plivo Application drop-down, select Voicemail (the name we gave the application).Click Update Number to save.
Test
Make a call to your Plivo number and leave yourself a voicemail message.Overview
You can use voicemail to capture a caller’s message if a call recipient is unavailable. This guide shows how to set up voicemail, either by using our PHLO visual workflow builder or our APIs and XML documents. Follow the instructions in one of the tabs below.- Using XML
Here’s how to implement voicemail using XML.
Save the file. Edit Properties/launchSettings.json and set the applicationUrl.“applicationUrl”: “http://localhost:5000/”Run the project and you should see your basic server application in action at http://localhost:5000/voicemail/.

How it works

Prerequisites
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.Create an MVC controller to implement voicemail
In Visual Studio, create a controller calledVoicemailController.cs and paste into it this code.Copy
Ask AI
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
namespace Receivecall.Controllers
{
public class VoicemailController : Controller
{
// GET: /<controller>/
public IActionResult Index()
{
Plivo.XML.Response resp = new Plivo.XML.Response();
resp.AddSpeak("Please leave a message. Press the star key when you're done",
new Dictionary<string, string>() { });
resp.AddRecord(new Dictionary<string, string>() {
{"action", "https://<yourdomain>.com/get_recording/"},
{"finishOnKey", "*"},
{"maxLength", "20"},
{"playBeep", "true"},
{"timeout", "15"}
});
resp.AddSpeak("Recording not received",
new Dictionary<string, string>() { });
var output = resp.ToString();
return this.Content(output, "text/xml");
}
}
}
Create a Plivo application for voicemail
Associate the MVC controller you created with Plivo by creating a Plivo application. Visit Voice > Applications in the Plivo console and click on Add New Application, or use Plivo’s Application API.Give your application a name — we called oursVoicemail. Enter the server URL you want to use (for example https://<yourdomain>.com/voicemail/) in the Answer URL field and set the method to GET. Click Create Application to save your application.
Assign a Plivo number to your application
Navigate to the Numbers page and select the phone number you want to use for this application.From the Application Type drop-down, selectXML Application.From the Plivo Application drop-down, select Voicemail (the name we gave the application).Click Update Number to save.
Test
Make a call to your Plivo number and leave yourself a voicemail message.Overview
You can use voicemail to capture a caller’s message if a call recipient is unavailable. This guide shows how to set up voicemail, either by using our PHLO visual workflow builder or our APIs and XML documents. Follow the instructions in one of the tabs below.- Using XML
Here’s how to implement voicemail using XML.
Save the project and run it. You should see your basic server application in action at http://localhost:4567/voicemail/.

How it works

Prerequisites
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 Java development environment and a web server and safely expose that server to the internet.Create a Spark application to implement voicemail
Create a Java class calledVoicemail and paste into it this code.Copy
Ask AI
import static spark.Spark.*;
import com.plivo.api.xml.GetInput;
import com.plivo.api.xml.Play;
import com.plivo.api.xml.Response;
import com.plivo.api.xml.Speak;
public class Voicemail {
public static void main(String[] args) {
post("/voicemail/", (request, response) -> {
response.type("application/xml");
Response response = new Response()
.children(
new Speak("Please leave a message. Press the star key when you're done"),
new Record("https://<yourdomain>.com/get_recording/")
.finishOnKey("*")
.maxLength(20),
new Speak("Recording not received")
);
resp.children(new Speak(NoinputMessage));
return resp.toXmlString();
});
}
}
Create a Plivo application for voicemail
Associate the Spark application you created with Plivo by creating a Plivo application. Visit Voice > Applications in the Plivo console and click on Add New Application, or use Plivo’s Application API.Give your application a name — we called oursVoicemail. Enter the server URL you want to use (for example https://<yourdomain>.com/voicemail/) in the Answer URL field and set the method to GET. Click Create Application to save your application.
Assign a Plivo number to your application
Navigate to the Numbers page and select the phone number you want to use for this application.From the Application Type drop-down, selectXML Application.From the Plivo Application drop-down, select Voicemail (the name we gave the application).Click Update Number to save.
Test
Make a call to your Plivo number and leave yourself a voicemail message.Overview
You can use voicemail to capture a caller’s message if a call recipient is unavailable. This guide shows how to set up voicemail, either by using our PHLO visual workflow builder or our APIs and XML documents. Follow the instructions in one of the tabs below.- Using XML
Here’s how to implement voicemail using XML.
Save the file and run it.You should see your basic server application in action at http://localhost:8080/voicemail/.

How it works

Prerequisites
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 Go development environment and a web server and safely expose that server to the internet.Create a Go server to implement voicemail
Create a file calledvoicemail.go and paste into it this code.Copy
Ask AI
package main
import (
"github.com/go-martini/martini"
"github.com/plivo/plivo-go/v7/xml"
"net/http"
)
func main() {
m := martini.Classic()
m.Post("/voicemail/", func(w http.ResponseWriter, r *http.Request) string {
w.Header().Set("Content-Type", "application/xml")
response := xml.ResponseElement{
Contents: []interface{}{
new(xml.SpeakElement).
AddSpeak("Please leave a message. Press the star key when you're done"),
new(xml.RecordElement).
SetAction("https://<yourdomain>.com/get_recording/").
SetFinishOnKey("*").
SetMaxLength(20),
new(xml.SpeakElement).
AddSpeak("Recording not received"),
},
}
return response.String()
})
m.Run()
}
Copy
Ask AI
$ go run voicemail.go
Create a Plivo application for voicemail
Associate the Go application you created with Plivo by creating a Plivo application. Visit Voice > Applications in the Plivo console and click on Add New Application, or use Plivo’s Application API.Give your application a name — we called oursVoicemail. Enter the server URL you want to use (for example https://<yourdomain>.com/voicemail/) in the Answer URL field and set the method to GET. Click Create Application to save your application.
Assign a Plivo number to your application
Navigate to the Numbers page and select the phone number you want to use for this application.From the Application Type drop-down, selectXML Application.From the Plivo Application drop-down, select Voicemail (the name we gave the application).Click Update Number to save.