This .net library is an open source tool built to simplify interaction with the Avaya CPaaS telephony platform. Avaya CPaaS makes adding voice and SMS to applications fun and easy.
For more information about Avaya CPaaS, please visit: Avaya OneCloud™️ CPaaS
To read the official documentation, please visit: Avaya CPaaS Docs
- In Solution Explorer, right click on References and choose Manage NuGet Packages.
- Choose nuget.org as the Package source, click the Browse tab, search for AvayaCPaaS, select that package in the list, and click Install
- Right-click the solution in Solution Explorer and click Build Solution
See the Avaya CPaaS REST API documentation for more information.
using System;
using AvayaCPaaS;
using AvayaCPaaS.Configuration;
using AvayaCPaaS.Exceptions;
public class Program
{
static void Main(string[] args)
{
var configuration = new APIConfiguration({AccountSid}, {AuthToken});
var service = new CPaaSService(configuration);
try
{
// Make call using calls connector
var call = service.CallsConnector.MakeCall("+12345", "+12678", "http://zang.io/ivr/welcome/call", playDtmf: "ww12w3221", timeout: 100);
Console.WriteLine(call.Status);
}
catch (CPaaSException e)
{
Console.WriteLine(e.Message);
}
}
}First, a configuration must be created by using provided configuration class APIConfiguration or by creating your own implementation of IAPIConfiguration interface.
Normally you'll want to just enter your Avaya CPaaS Platform AccountSid and AuthToken, but you can also define a proxy server or change the base API URL. The default value for base API URL is set to "https://api.zang.io/v2".
The base API URL and api version for US(new) and EU deployments are: US: https://api-us.cpaas.avayacloud.com/v2 EU: https://api-eu.cpaas.avayacloud.com/v2
Basic configuration:
var configuration = new APIConfiguration({AccountSid}, {AuthToken});or if you want to define a proxy server:
var configuration = new APIConfiguration({AccountSid}, {AuthToken});
configuration.UseProxy = true;
configuration.ProxyHost = {ProxyHost}
configuration.ProxyPort = {ProxyPort}or if you want to change the base API URL:
configuration.BaseUrl = {BaseUrl}Next, you'll have to create a CPaaSService and pass the configuration
var service = new CPaaSService(configuration)Another way to create CPaaSService is to pass a custom HttpManager which implements IHttpManager.
var service = new CPaaSService(myHttpManager)Create CPaaSService with empty APIConfiguration
var service = new CPaaSService(new APIConfiguration("", ""));Configure service
service.InitFromConfig();Request parameters are passed as parameters to connector object methods as shown previously in Send SMS Example. All methods have convenience overloads which use the AccountSid parameter specified in the configuration automatically.
Explicit accountSid
var usage = service.UsagesConnector.ViewUsage({accountSid}, {UsageSid});AccountSid from configuration used automatically
var usage = service.UsagesConnector.ViewUsage({UsageSid});Optional parameters are used as named parameters like transcribe:true, e.g:
var call = service.CallsConnector.MakeCall("+12345", "+112233", "testUrl", transcribe:true, transcribeCallback:"transcribeCallback");The received data can be an object, e.g.:
var usage = service.UsagesConnector.ViewUsage({UsageSid});
Console.WriteLine(usage.TotalCost);Or a list of objects in which case the list is iterable, e.g.:
var usages = service.UsagesConnector.ListUsages(year:2017, month:5, product:Product.INBOUND_CALL, page: 3, pageSize: 40);
foreach (var usage in usages.Elements)
{
Console.WriteLine(usage.TotalCost);
}InboundXML is an XML dialect which enables you to control phone call flow. For more information please visit the Avaya CPaaS InboundXML documentation.
Example of using InboundXML builder:
using System;
using AvayaCPaaS.InboundXml;
using AvayaCPaaS.Exceptions;
public class Program
{
static void Main(string[] args)
{
try
{
var builder = new InboundXmlBuilder();
builder.GetRequestNode()
.Dial("(555)555-5555", hideCallerId:false, dialMusic:"dial music", confirmSound:"dial confirm sound", digitsMatch:"ww12w3221", record:false, recordDirection:RecordDirectionEnum.@out)
.StartInner()
.Sip("username@domain.com", "username", "password")
.EndInner()
.Gather()
.StartInner()
.Say(language: LanguageEnum.en, loop: 3, value: "Welcome to Avaya CPaaS!", voice: VoiceEnum.female)
.Pause(length: 2)
.EndInner()
.Hangup(schedule: 4, reason: HangupReasonEnum.rejected);
var result = builder.Build();
Console.WriteLine(result);
}
catch (CPaaSException e)
{
Console.WriteLine(e.Message);
}
}
}will render
<Response>
<Dial dialMusic="dial music" confirmSound="dial confirm sound" digitsMatch="ww12w3221" hideCallerId="False" record="False" recordDirection="out">
<Sip username="username" password="password">username@domain.com</Sip>
</Dial>
<Gather>
<Say loop="3" voice="female" language="en">Welcome to Avaya CPaaS!</Say>
<Pause length="2" />
</Gather>
<Hangup schedule="4" reason="rejected" />
</Response>