Plivo C#.NET Helper Library simplifies the process of making Plivo API calls and generating Plivo XML.
- Windows 7
- Microsoft Visual Studio 2010
- NuGet Package Manger
NOTE: NuGET Package Manager installation procedure can be found in the NuGet Documentation here
This helper library can be installed / used in two ways,
- From Source.
- From the NuGet Package Manager (recommended).
To use this library from source follow the instructions below,
- Get the source from Github using
git clone
or using the download link. - Open the solution file in Visual Studio.
- Install NuGet Package Manager.
- Go to
Tools -> Library Package Manager -> Packager Manager Console
. - Enter the following command in the console to install RestSharp (Simple REST and HTTP API Client that Plivo uses),
PM> Install-Package RestSharp -Version 104.4.0
- Once the RestSharp package is successfully installed, close the console. Right Click on the solution (in this case Plivo) in the Solution Explorer and click Clean and then Build.
- Next, to start using it in your project, Right Click on your Project Name in the Solution Explorer and click Add Reference. In the dialog box which appears, go to the Browse tab and Navigate to
plivo-dotnet\Plivo\bin\Debug
and select thePlivo.dll
and click OK. - Now, you can use Plivo in your code!
- Install NuGet Package Manager.
- Go to
Tools -> Library Package Manager -> Packager Manager Console
. - Enter the following commands in the console to install RestSharp (Simple REST and HTTP API Client that Plivo uses) and Plivo,
PM> Install-Package RestSharp -Version 104.4.0
PM> Install-Package Plivo
If you already have RestSharp installed, its best to uninstall it before installing the specific version.
PM> Uninstall-Package RestSharp -Force
PM> Install-Package RestSharp -Version 104.4.0
PM> Install-Package Plivo
using System;
using System.Collections.Generic;
using System.Reflection;
using RestSharp;
using Plivo.API;
namespace SampleApplication
{
class Program
{
static void Main(string[] args)
{
string auth_id = "XXX"; // obtained from Plivo account dashboard
string auth_token = "YYY"; // obtained from Plivo account dashboard
// Creating the Plivo Client
RestAPI plivo = new RestAPI(auth_id, auth_token);
// Making a Call
string from_number = "XXXXXXXXXXX";
string to_number = "YYYYYYYYYYY";
IRestResponse<Call> response = plivo.make_call(new Dictionary<string, string>() {
{ "from", from_number },
{ "to", to_number },
{ "answer_url", "http://some.domain.com/answer/" },
{ "answer_method", "GET" }
});
// The "Outbound call" API response has four properties -
// message, request_uuid, error, and api_id.
// error - contains the error response sent back from the server.
if (response.Data != null)
{
PropertyInfo[] properties = response.Data.GetType().GetProperties();
foreach (PropertyInfo property in properties)
Console.WriteLine("{0}: {1}", property.Name, property.GetValue(response.Data, null));
}
else
{
// ErrorMessage - contains error related to network failure.
Console.WriteLine(response.ErrorMessage);
}
Console.Read();
}
}
}
using System;
using System.Collection.Generic;
using Plivo.XML;
namespace SampleApplication
{
class Program
{
static void Main(string[] args)
{
Response response = new Response();
// add 'Speak' element to 'Response'
response.AddSpeak("Go green, go Plivo",
new Dictionary<string, string>() {
{ "loop", "3" },
{ "language", "en-US");
});
// or you can add as below
// Speak speak = new Speak("Go green, go Plivo",
// new Dictionary<string, string>() {
// { "loop", "3" },
// { "language", "en-US");
// });
// response.Add(speak);
Console.WriteLine(response.ToString());
Console.Read();
}
}
}
The MIT License (MIT)
Copyright (c) 2013 Plivo Inc
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.