Skip to main content
  • Node
  • Ruby
  • Python
  • PHP
  • .NET
  • Java
  • Go

Overview

This guide shows how to receiving incoming calls on a Plivo number and greet callers with a text-to-speech message. Managing incoming calls is a key part of the call flow in many common use cases, such as interactive voice response (IVR), call forwarding, and conference calling.You can handle incoming calls 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 use a Plivo XML document that handles incoming calls on a Plivo number by playing a text-to-speech message to the caller.

How it works

Inbound Call Flow
Plivo requests an answer URL when it answers the call (step 2) and expects the file at that address to hold a valid XML response from the application with instructions on how to handle the call. In this example, when an incoming call is received, Plivo’s text-to-speech engine plays a message using the Speak XML element.

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 MVC controller to handle incoming calls

In Visual Studio, create a new project. Use the template for Web Application (Model-View-Controller).
Create an MVC app
Give the project a name — we used Receivecall.
Configure the MVC app
Navigate to the Controllers directory in the Receivecall project. Create a controller named ReceivecallController.cs and paste into it this code.
using System;
using Plivo.XML;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;

namespace Receivecall
{
    public class ReceivecallController : Controller
    {
        public IActionResult Index()
        {
            Plivo.XML.Response resp = new Plivo.XML.Response();
            resp.AddSpeak("Hello, you just received your first call",
                new Dictionary<string, string>() {
        {
        "loop",
        "3"
        }
                });
            var output = resp.ToString();
            Console.WriteLine(output);

            return this.Content(output, "text/xml");
        }
    }
}

Create a Plivo application to receive calls

Associate the 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 ours Receive_call. Enter the server URL you want to use (for example https://<yourdomain>.com/receive_call/) in the Answer URL field and set the method to POST. Click Create Application to save your application.
Create 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, select XML Application.From the Plivo Application drop-down, select Receive_call (the name we gave the application).Click Update Number to save.
Assign Phone Number to Receive Call App

Test

Make a call to your Plivo number using any phone. Plivo will send a request to the answer URL you provided requesting an XML response and then process the call according to the instructions in the XML document the server provides. You should hear the text-to-speech message, “Hello, you just received your first call.”