Skip to content

THECALLR/sdk-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚠️ DEPRECATED — Callr API v1 (JSON-RPC)

This SDK targets the legacy Callr JSON-RPC API (v1), which is deprecated and will be shut down on 30 June 2027. After that date this SDK will stop working.

➡️ Please migrate to the new Callr REST API v2.

Your existing API credentials work with REST API v2 — no new keys required.

Official Callr REST API v2 SDKs are coming in the near future. In the meantime, you can call the REST API directly, or generate a client from the OpenAPI 3.1 spec (see Generate a REST API v2 client today below).


Generate a REST API v2 client today

An official Callr REST API v2 SDK for Go is coming soon. Until then, generate a fully-typed client from the OpenAPI 3.1 spec with OpenAPI Generator (requires v7.x+ for OpenAPI 3.1):

docker run --rm -v "$PWD:/local" openapitools/openapi-generator-cli generate \
  -g go \
  -i https://api.callr.com/v2.0/openapi.json \
  -o /local/callr-v2-go

Authenticate with your API Key via the x-api-key header (or HTTP Basic: Account SID + API Key). The base URL https://api.callr.com/v2.0 is baked into the generated client — see its generated docs/ for the available endpoints.


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

About

SDK in Go for CALLR API

Resources

License

Stars

2 stars

Watchers

10 watching

Forks

Packages

 
 
 

Contributors

Languages