Skip to content

zang-cloud/zang-go

Repository files navigation

zang-go

This golang package is an open source tool built to simplify interaction with the Avaya CPaaS telephony platform. Avaya OneCloud™️ 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.

Installation

Clone the repo, and install via go get:

$ go get -u github.com/zang-cloud/zang-go

Usage

Authorization ----In order to authorize against Avaya OneCloud™️ CPaaS services you'll have to define authentication credentials.

export ZANG_CLOUD_ACCOUNT_SID="{YourAccountSid}"
export ZANG_CLOUD_AUTH_TOKEN="{YourAccessToken}"

You can also change the base API url in /constants.go.

The default value is set as follows:

const (
// ZangApiUrl -
ZangApiUrl = "https://api.zang.io"
// ZangApiVersion -
ZangApiVersion = "v2"
// DefaultResponseContentType -
DefaultResponseContentType = "json"
)

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

For example, if you want to use EU deployments:

const (
// ZangApiUrl -
ZangApiUrl = "api-eu.cpaas.avayacloud.com"
// ZangApiVersion -
ZangApiVersion = "v2"
// DefaultResponseContentType -
DefaultResponseContentType = "json"
)

Import ----

import (
    zang "github.com/zang-cloud/zang-go"
)

Logging ----

In order to use the Avaya OneCloud CPaaS library, logging must be initialized:

package main
import (
    log "github.com/sirupsen/logrus"
    zang "github.com/zang-cloud/zang-go"
)
func init() {
    log.SetLevel(log.DebugLevel)
    formatter := &log.TextFormatter{
        FullTimestamp: true,
    }
    log.SetFormatter(formatter)
}

REST

See the Avaya CPaaS REST API documentation for more information.

NOTE: Please go through tests for specific endpoint to see the example

Send SMS Example

func sendsms() {
    client, err := zang.NewClient()
    if err != nil {
        log.Errorln("Client creation failed:", err)
        return
    }
    log.Debugln("Sending request")
    response, err := client.SendSms(map[string]string{
        "From": "E164 From",
        "To":   "E164 To",
        "Body": "Test Body,
    })

 func main() {
    os.Setenv("ZANG_CLOUD_ACCOUNT_SID", "{YourAccountSid}")
    os.Setenv("ZANG_CLOUD_AUTH_TOKEN", "{YourAccessToken}")
    sendsms()
}

InboundXML

InboundXML is an XML dialect which enables you to control phone call flow. For more information please visit the Zang InboundXML documentation.

<Say> Example

ixml, err := New(Response{Say: &Say{
  Voice: "female",
  Value: "Welcome to Avaya CPaaS!",
  Loop:  3,
}})

fmt.Print(ixml)

will render

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Response>
    <Say loop="3" voice="female" language="en">Welcome to Avaya CPaaS!</Say>
</Response>

Releases

No releases published

Packages

No packages published

Languages