callr

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2019 License: MIT Imports: 10 Imported by: 0

README

sdk-go

SDK in Go for the CALLR API.

Works with Go 1.11+ (this is a go module), using standard packages only.

Quick start

import callr "github.com/THECALLR/sdk-go"

func main() {
    // use Api Key Auth (recommended) - use the customer portal to generate keys
    api := callr.NewWithAPIKeyAuth("key")
    
    result, err := api.Call("method", params...)

Usage

Broadcast
Broadcast messages to a target
target := map[string]interface{}{
    "number": "+33123456789",
    "timeout": 30,
}
messages := []interface{}{
    131,
    132,
    "TTS|TTS_EN-GB_SERENA|Hello world! how are you ? I hope you enjoy this call. good bye."
}

options := map[string]interface{}{
    "cdr_field": "userData",
    "cli": "BLOCKED",
    "loop": 2,
}

result, err := api.Call("calls.broadcast_1", target, messages, options)
Without options
target := map[string]interface{}{
    "number": "+33123456789",
    "timeout": 30,
}

messages := []interface{}{
    131,
    132,
    134,
}

result, err := api.Call("calls.broadcast_1", target, messages, nil)

Method

Objects


REALTIME
Create a REALTIME app with a callback URL
options := map[string]interface{}{
    "url": "http://yourdomain.com/realtime_callback_url",
}

result, err := api.Call("apps.create", "REALTIME10", "Your app name", options)

Method

Objects

Start a REALTIME outbound call
target := map[string]interface{}{
    "number": "+33132456789",
    "timeout": 30,
}

callOptions := map[string]interface{}{
    "cdr_field": "42",
    "cli": "BLOCKED",
}

result, err := api.Call("calls.realtime", "appHash", target, callOptions)

Method

Objects

Inbound Calls - Assign a phone number to a REALTIME app
result, err := api.Call("apps.assign_did", "appHash", "DID ID")

Method

Objects


Sending SMS
Without options
result, err := api.Call("sms.send", "SMS", "+33123456789", "Hello, world", nil)

Method

Personalized sender

Your sender must have been authorized and respect the sms_sender format

result, err := api.Call("sms.send", "Your Brand", "+33123456789", "Hello world!", nil)

Method

If you want to receive replies, do not set a sender - we will automatically use a shortcode
result, err := api.Call("sms.send", "", "+33123456789", "Hello world!", nil)

Method

Force GSM encoding
optionSMS := map[string]interface{}{
    "force_encoding": "GSM",
}

result, err := api.Call("sms.send", "", "+33123456789", "Hello world!", optionSMS)

Method

Objects

Long SMS (availability depends on carrier)
var text bytes.Buffer

text.WriteString("Some super mega ultra long text to test message longer than 160 characters ")
text.WriteString("Some super mega ultra long text to test message longer than 160 characters ")
text.WriteString("Some super mega ultra long text to test message longer than 160 characters")

result, err := api.Call("sms.send", "SMS", "+33123456789", text.String(), nil)

Method

Specify your SMS nature (alerting or marketing)
optionSMS := map[string]interface{}{
    "nature": "ALERTING",
}

result, err := api.Call("sms.send", "SMS", "+33123456789", "Hello world!", optionSMS)

Method

Objects

Custom data
optionSMS := map[string]interface{}{
    "user_data": "42",
}

result, err := api.Call("sms.send", "SMS", "+33123456789", "Hello world!", optionSMS)

Method

Objects

Delivery Notification - set webhook endpoint to receive notifications
optionSMS := map[string]interface{}{
       	"webhook": map[string]interface{}{ 
			"endpoint":"http://yourdomain.com/webhook_endpoint", 
		},
    }


result, err := api.Call("sms.send", "SMS", "+33123456789", "Hello world!", optionSMS)

Method

Objects

Inbound SMS - set webhook endpoint to receive inbound messages (MO) and replies

Do not set a sender if you want to receive replies - we will automatically use a shortcode.

optionSMS := map[string]interface{}{
       	"webhook": map[string]interface{}{ 
			"endpoint":"http://yourdomain.com/webhook_endpoint", 
		},
    }

result, err := api.Call("sms.send", "", "+33123456789", "Hello world!", optionSMS)

Method

Objects

Get an SMS
result, err := api.Call("sms.get", "SMSHASH")

Method

Objects


DIDs
List available countries with DID availability
result, err := api.Call("did/areacode.countries")

Method

Objects

Get area codes available for a specific country and DID type
result, err := api.Call("did/areacode.get_list", "US", nil)

Method

Objects

Get DID types available for a specific country
result, err := api.Call("did/areacode.types", "US")

Method

Objects

Buy a DID (after a reserve)
result, err := api.Call("did/store.buy_order", "OrderToken")

Method

Objects

Cancel your order (after a reserve)
result, err := api.Call("did/store.cancel_order", "OrderToken")

Method

Cancel a DID subscription
result, err := api.Call("did/store.cancel_subscription", "DID ID")

Method

View your store quota status
result, err := api.Call("did/store.get_quota_status")

Method

Objects

Get a quote without reserving a DID
result, err := api.Call("did/store.get_quote", 0, "GOLD", 1)

Method

*Objects/

Reserve a DID
result, err := api.Call("did/store.reserve", 0, "GOLD", 1, "RANDOM")

Method

Objects

View your order
result, err := api.Call("did/store.view_order", "OrderToken")

Method

Objects


Media
List your medias
result, err := api.Call("media/library.get_list", nil)

Method

Create an empty media
result, err := api.Call("media/library.create", "name")

Method

Upload a media
mediaID := 0

result, err := api.Call("media/library.set_content_from_file", mediaID, "imported temporary file name")

Method

Use Text-to-Speech
mediaID := 0

result, err := api.Call("media/tts.set_content", mediaID, "Hello world!", "TTS-EN-GB_SERENA", nil)

Method

Documentation

Overview

Package callr implements the CALLR API, using JSON-RPC 2.0. See https://www.callr.com/ and https://www.callr.com/docs/.

Usage

package main

import (
    "fmt"
    "os"

    callr "github.com/THECALLR/sdk-go"
)

func main() {
    // use Basic Auth (not recommended)
    // api := callr.NewWithBasicAuth("login", "password")

    // or use Api Key Auth (recommended)
    api := api.NewWithAPIKeyAuth("key")

    // optional: set a proxy
    // api.SetProxy("http://proxy:port")

    // check for destination phone number parameter
    if len(os.Args) < 2 {
        fmt.Println("Please supply destination phone number!")
        os.Exit(1)
    }

    // Example to send a SMS
    result, err := api.Call("sms.send", "SMS", os.Args[1], "Hello, world", nil)

    // error management
    if err != nil {
        if e, ok := err.(*callr.JSONRPCError); ok {
            fmt.Printf("Remote error: code:%d message:%s data:%v\n", e.Code, e.Message, e.Data)
        } else {
            fmt.Println("Local error: ", err)
        }
        os.Exit(1)
    }

    fmt.Println(result)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API represents a connection to the CALLR API.

func NewWithAPIKeyAuth

func NewWithAPIKeyAuth(key string) *API

NewWithAPIKeyAuth returns an API object with an API Key Authentication.

func NewWithBasicAuth

func NewWithBasicAuth(login, password string) *API

NewWithBasicAuth returns an API object with Basic Authentication (not recommended). Use NewWithAPIKeyAuth auth instead.

func (*API) Call

func (api *API) Call(method string, params ...interface{}) (interface{}, error)

Call sends a JSON-RPC 2.0 request to the CALLR API, and returns either a result, or an error. The error may be of type JSONRPCError if the error comes from the API, or a native error if the error is local.

func (*API) SetProxy

func (api *API) SetProxy(proxy string) error

SetProxy sets a proxy URL to use

func (*API) SetURL

func (api *API) SetURL(url string) error

SetURL changes the URL for the API object

type JSONRPCError

type JSONRPCError struct {
	Code    int64       `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

JSONRPCError is a JSON-RPC 2.0 error, returned by the API. It satisfies the native error interface.

func (*JSONRPCError) Error

func (e *JSONRPCError) Error() string

Error implements the error interface. Returns a string with the Code and Message properties.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL