Upgrade from .NET SDK Legacy to v4.10.0 or Latest Version

Introduction

This is a major application update. Plivo recommends you always use the latest or an active version of our SDKs for guaranteed security, stability, and uptime. The active SDK versions are designed to handle intermittent and regional failures of API requests. In addition, they offer a host of security features, such as protection against DoS attacks and bot detection for suspicious user agents.

Deprecation notice: Plivo .NET SDK legacy versions lower than v4.10.0 are being deprecated on January 31, 2022. If you use a deprecated version of our SDK after that date, your API requests and voice calls may fail intermittently. Plivo will no longer provide bug fixes to these versions, and our support team may ask you to upgrade before debugging issues.

Migrate your applications

.NET version support

The Plivo .NET SDK supports .NET applications written in C# and Visual Basic that utilize the .NET Framework version 3.5 or higher or any .NET runtime supporting .NET Standard v1.4.

Use the command Update-Package Plivo -Version 4.10.0 to upgrade to the active version of the SDK, or Update-Package Plivo to upgrade to the latest version.

After you upgrade to the latest version of the SDK, you should check every program that depends on it and make changes to the syntax for several kinds of operations. Here are examples of how coding differs between the deprecated legacy version of the SDK and the latest active versions.

Import the SDK

Legacy Latest
using System;
using System.Collections.Generic;
using RestSharp;
using Plivo.API;
   
using System;
using System.Collections.Generic;
using Plivo;
   

Initialize

Legacy Latest
RestAPI plivo = new RestAPI("<auth_id>","<auth_token>");
   
var api = new PlivoApi("<auth_id>","<auth_token>");
   

Access resources

Legacy Latest
IRestResponse<Call> resp = plivo.make_call(new Dictionary<string, string>()
            {params});
   
var response = api.Call.Create(params);
   

Make a call

Legacy Latest
using System;
using System.Collections.Generic;
using RestSharp;
using Plivo.API;
namespace make_calls
{
   class Program
   {
       static void Main(string[] args)
       {
           RestAPI plivo = new RestAPI("<auth_id>", "<auth_token>");
           IRestResponse<Call> resp = plivo.make_call(new Dictionary<string, string>()
           {
               { "from", "2025551212" },
               { "to", "2025552323" },
               { "answer_url", "https://s3.amazonaws.com/static.plivo.com/answer.xml" },
               { "answer_method","GET"},
           });
           Console.Write(resp.Content);
           Console.ReadLine();
       }
   }
}
   
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.Call.Create(
                   to: new List<String> { "+12025552323" },
                   from: "+12025551212",
                   answerMethod: "GET",
                   answerUrl: "https://s3.amazonaws.com/static.plivo.com/answer.xml"
               );
               Console.WriteLine(response);
           }
           catch (PlivoRestException e)
           {
               Console.WriteLine("Exception: " + e.Message);
           }
       }
   }
}
   

Dial XML

Legacy Latest
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();
			Plivo.XML.Dial dial = new Plivo.XML.Dial(new
				Dictionary<string, string>() {
				{"dialMusic", "https://<yourdomain>.com/dial_music/"}
			});

			dial.AddNumber("12025552323",
				new Dictionary<string, string>() { });
			resp.Add(dial);
	
			var output = resp.ToString();
			Console.WriteLine(output);
	
		}
	}
}
   
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();
			Plivo.XML.Dial dial = new Plivo.XML.Dial(new
				Dictionary<string, string>() {
				{"dialMusic", "https://<yourdomain>.com/dial_music/"}
			});

			dial.AddNumber("12025552323",
				new Dictionary<string, string>() { });
			resp.Add(dial);
	
			var output = resp.ToString();
			Console.WriteLine(output);
	
		}
	}
}
   

Conference XML

Legacy Latest
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("My room", 
               new Dictionary<string, string>()
			{
				{"startConferenceOnEnter", "true"},
				{"endConferenceOnExit", "true"},
				{"waitSound", "https://<yourdomain>.com/waitmusic/"}
			});
			var output = resp.ToString();
			Console.WriteLine(output);

		}
	}
}
   
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("My room", 
               new Dictionary<string, string>()
			{
				{"startConferenceOnEnter", "true"},
				{"endConferenceOnExit", "true"},
				{"waitSound", "https://<yourdomain>.com/waitmusic/"}
			});
			var output = resp.ToString();
			Console.WriteLine(output);

		}
	}
}
   

Record API

Legacy Latest
using System;
using System.Collections.Generic;
using System.Diagnostics;
using RestSharp;
using Plivo.API;
namespace PlivoExamples
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            string auth_id = "<auth_id>";
            string auth_token = "<auth_token>";
            RestAPI plivo = new RestAPI(auth_id, auth_token);


            IRestResponse<Plivo.API.Record> resp = plivo.record(new Dictionary<string, string>()
            {
                { "call_uuid", uuid } // ID of the call
            });
            Debug.WriteLine(resp.Content);
         }
    }
}
   
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.Call.StartRecording(
                    callUuid:"10c94053-73b4-46fe-b74a-12159d1d3d60"
                );
                Console.WriteLine(response);
            }
            catch (PlivoRestException e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
        }
    }
}
   

Record XML

Legacy Latest
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("12025552323",
				new Dictionary<string, string>() { });
			resp.Add(dial);
	
			var output = resp.ToString();
			Console.WriteLine(output);
	
		}
	}
}
   
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("12025552323",
				new Dictionary<string, string>() { });
			resp.Add(dial);
	
			var output = resp.ToString();
			Console.WriteLine(output);
	
		}
	}
}