Outbound Call API - .Net SDK/Helper library

Voice2Phone Server-side SDKs

Server-side SDKs make it easy for you to use Voice2Phone's Outbound Phone Calling REST APIs. These helper libraries are available in a variety of popular server-side programming languages.

Voice2Phone C#/.Net Helper Library

The Voice2Phone Outbound-Calling-Api .Net helper library lets you write C# code (or code in any .NET language) to make HTTP requests to the Voice2Phone Outbound Phone Calling API. This library is open source, so if you find a feature missing or a bug, we encourage you to contribute back to the Voice2Phone Outbound-Calling-Api project hosted on GitHub.

Installation

Adding Outbound Phone Calling API .NET Library to your .NET project

The best and easiest way to add the Outbound Phone Calling API .NET Library to your .NET project is to use the NuGet package manager. NuGet is a Visual Studio extension that makes it easy to install and update third-party libraries and tools in Visual Studio. NuGet is included in Visual Studio 2012 and later and available for download for Visual Studio 2010. You can find instructions for installing the NuGet extension on the NuGet.org website. Once you have installed the NuGet extension, you can choose to install the Outbound Phone Calling API Library using either the Package Manager dialog, or using the Package Manager console.

Installing via the Package Manager Console

To install a library using the Package Manager console, first open the console, then Use the Install-Package command to install the Voice2Phone Outbound Phone Calling API package :

PM> Install-Package Voice2Phone.Api.Client

To install a Voice2Phone library using the Package Manager dialog, first open the dialog by right-clicking the References folder in your project and selecting the package manager option:

Manage NuGet Packages context menu

When the package manager dialog opens simply search the online catalog for ‘Voice2Phone’. The screen shot below shows the results returned from the NuGet catalog:

NuGet Package Manager Dialog

Simply click the Install button next to the Voice2Phone package you want to add to your project and watch as NuGet downloads the Voice2Phone library package (and its dependencies) and adds the proper references to your project.

Voice2Phone NuGet References

Usage Example

Try calling yourself, like this:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Voice2Phone.Api;
using Voice2Phone.Api.Responses;
namespace TestApp
{
    class Program
    {
        public static MakeCallResponse MakeCall(
            string secretKey, 
            string phone, 
            string country)
        {
            Dictionary dtmf = new Dictionary();
            dtmf.Add("1", "You have pressed one");
            dtmf.Add("2", "You have pressed two");
            var ret = 
                Client.MakeCallAsync(
                    secretKey, 
                    phone, 
                    country, 
                    "Please press one or two", 
                    dtmf);
            ret.Wait();
            
            return ret.Result;
        }
        public static  void PrintCallStatus(
            string secretKey, 
            Guid callId)
        {
            Taskres = null;
            do
            {
                res =  Client.GetStatusAsync(secretKey, callId);
                res.Wait();
                
                if (res.Result.Status == System.Net.HttpStatusCode.OK)
                    Console.WriteLine(
                        string.Format("{0} {1}   {2}", 
                        res.Result.CallStatus, 
                        res.Result.CreatedDateUtc, 
                        res.Result.UpdatedDateUtc));
                else
                {
                    Console.WriteLine(
                        string.Format("ERROR: {0}, {1}", 
                        res.Result.Status, 
                        res.Result.Message));
                    break;
                }
            } while (res != null && res.Result.CallStatus <= 1);
        }
        static  void Main(string[] args)
        {
           string yourSercretApiCode = "< Your Secret Api Key >";
           string yourPhone = "< Your Phone Number >";
           string yourCountryCode = "< Two letter country code >";

           var response =  MakeCall(
                yourSercretApiCode, 
                yourPhone, 
                yourCountryCode);
            if (response.Status == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine(string.Format("CallId is: {0}", response.CallId));
                PrintCallStatus(yourSercretApiCode,
                    response.CallId);
            }
            else           
                Console.WriteLine(
                    string.Format("ERROR: {0}, {1}", 
                    response.Status,
                    response.Message));
                
          
        }
    }
}