avayacpaas-dotnet
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: https://www.zang.io/products/cloud
To read the official documentation visit https://docs.avayacloud.com/aspx/docs
Installation
Windows
1. Using Visual Studio and NuGet Package Manager
- 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
Usage
REST
See the Avaya CPaaS REST API Documentation for more information.
Make Call Example
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);
}
}
}
Configuration (3 ways)
First, a configuration must be created by using provided configuration class APIConfiguration
or by creating your own implementation of IAPIConfiguration
interface.
1. Create APIConfiguration with parameters AccountSid and AuthToken
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.
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}
Next, you'll have to create a CPaaSService and pass the configuration
var service = new CPaaSService(configuration)
2. Use a custom HttpManager
Another way to create CPaaSService is to pass a custom HttpManager which implements IHttpManager.
var service = new CPaaSService(myHttpManager)
3. Use configuration parameters from app.config
file
Create CPaaSService with empty APIConfiguration
var service = new CPaaSService(new APIConfiguration("", ""));
Configure service
service.InitFromConfig();
Request parameters
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});
Methods with optional parameters
Optional parameters are used as named parameters like transcribe:true
, e.g:
var call = service.CallsConnector.MakeCall("+12345", "+112233", "testUrl", transcribe:true, transcribeCallback:"transcribeCallback");
Response data
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
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
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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>
Pending updates to this document