.NET (C#) SDK

The Plivo .NET SDK makes it simpler to integrate communications into your .NET applications using the Plivo REST APIs. Using the SDK, you’ll be able to make voice calls, send SMS messages, and generate Plivo XML documents to control your call flows.

Supported .NET versions: This SDK was written targeting at .NET Standard 1.3, and thus works with .NET Framework 4.6 and higher and .NET Core 1.0 and higher. Check here to know about all the other supported platforms.

Prerequisites

Installation

You can install this SDK either by referencing the .dll file or by using NuGet.

To install the latest SDK using the NuGet CLI:

PM> Install-Package Plivo -Version 4.1.3

To use NuGet to install the SDK in Visual Studio:

1. Run NuGet and choose Package Manager: Add Package

2. Enter package name: Plivo

3. Select package name and version

You can also use the .NET CLI to install the package:

> dotnet add package Plivo --version 4.1.3

Getting started

Authentication

To make the API requests, you need to create a PlivoApi instance and provide it with authentication credentials, which you can find on the Overview page of the Plivo console.

var api = new PlivoApi("<auth_id>","<auth_token>");

Replace the auth placeholders with your authentication credentials from the Plivo console.

The basics

The SDK uses consistent interfaces to create, retrieve, update, delete, and list resources. The pattern is:

api.Resource.Create(params);
api.Resource.Get(params);
api.Resource.Update(identifier, params);
api.Resource.Delete(identifier);
List();

Using api.Resource.List() lists the first 20 resources by default (the first page, with limit as 20, and offset as 0). Use limit and offset to get more pages of resources.

Examples

Send a message

internal class Program
{
    public static void Main(string[] args)
    {
        var api = new PlivoApi("<auth_id>","<auth_token>");
        var response = api.Message.Create(
            src:"<source_number>",
            dst:"<destination_number>",
            text:"Hello, world!"
        );
        Console.WriteLine(response);
    }
}

Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phone number placeholders with actual phone numbers in E.164 format (for example, +12025551234).

Make a call


internal class Program
{
    public static void Main(string[] args)
    {
        var api = new PlivoApi("<auth_id>","<auth_token>");
        var response = api.Call.Create(
            to:new List<String>{"<destination_number>"},
            from:"<caller_id>",
            answerMethod:"GET",
            answerUrl:"https://<answer.url>"
        );
        Console.WriteLine(response);
    }
}

Generate Plivo XML


class MainClass
{
    public static void Main(string[] args)
    {
        Plivo.XML.Response response = new Plivo.XML.Response();
        response.AddSpeak("Hello, world!",
                          new Dictionary<string, string>() { });
        Console.WriteLine(response.ToString());
    }
}

This generates the following XML:

<Response>
  <Speak>Hello, world!</Speak>
</Response>

More examples

Refer to the Plivo API Reference documentation for more examples.

Reporting issues

Report feedback or problems with this SDK by opening an issue on GitHub.