aringo

package module
v0.0.0-...-995e591 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 14 Imported by: 1

README

ARInGO

========

Simple Asterisk ARI connector from Go

Installation

go get github.com/cgrates/aringo

Support

Join CGRateS on Google Groups here.

License

ARInGO is released under the MIT License. Copyright (C) ITsysCOM GmbH. All Rights Reserved.

Sample usage code

package main

import (
        "fmt"
        "net/url"
        "time"

        "github.com/cgrates/aringo"
)

// listenAndServe will handle events received from ARInGO, mainly print them
func listenAndServe(evChan chan map[string]interface{}, errChan chan error) (err error) {
        for {
                select {
                case err = <-errChan:
                        return
                case astRawEv := <-evChan:
                        fmt.Printf("Received event from ARInGO: %+v\n", astRawEv) // your handler code goes here
                }
        }
        return fmt.Errorf("ListenAndServe out of select")
}

func main() {
        ariAddr := "127.0.0.1:8088"
        evChan := make(chan map[string]interface{}) // receive ARI events on this channel
        errChan := make(chan error)                 // receive ARI errors on this channel
        astConn, err := aringo.NewARInGO(fmt.Sprintf("ws://%s/ari/events?api_key=%s:%s&app=%s", ariAddr, "cgrates", "CGRateS.org", "cgrates_auth"),
                "http://cgrates.org", "cgrates", "CGRateS.org", "CGRateS 0.9.1~rc8", evChan, errChan, 5, 5) // connect to Asterisk ARI
        if err != nil {
                fmt.Printf("Error when connecting to ARI, <%s>", err.Error())
                return
        }
        go listenAndServe(evChan, errChan) // listen for events

        // Sample code for sending commands to ARI (originate a call)
        _, err = astConn.Call(aringo.HTTP_POST, fmt.Sprintf("http://%s/ari/channels?endpoint=PJSIP/1002&extension=1001", ariAddr),
                url.Values{})
        if err != nil {
                fmt.Printf("Error when sending originate to ARI, <%s>", err.Error())
                return
        }

        time.Sleep(20 * time.Second) // here just for testing, continue your code in the way you need
}

Documentation

Index

Constants

View Source
const (
	HTTP_POST   = "POST"
	HTTP_GET    = "GET"
	HTTP_DELETE = "DELETE"
)

Variables

View Source
var (
	ErrZeroConnectAttempts = errors.New("ZERO_CONNECT_ATTEMPTS")
)

Functions

func NewErrUnexpectedReplyCode

func NewErrUnexpectedReplyCode(statusCode int) error

Types

type ARInGO

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

ARInGO represents one ARI connection/application

func NewARInGO

func NewARInGO(wsUrl, wsOrigin, username, password, userAgent string, evChannel chan map[string]interface{},
	errChannel chan error, stopChan <-chan struct{}, connectAttempts, reconnects int,
	maxReconnectInterval time.Duration, delayFunc func(time.Duration, time.Duration) func() time.Duration) (ari *ARInGO, err error)

func (*ARInGO) Call

func (ari *ARInGO) Call(method, uri string, queryStr map[string]string, bodyParams map[string]string) (RESTResponse, error)

type ARInGOV1

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

ARInGOV1 represents one ARI connection/application

func NewARInGOV1

func NewARInGOV1(wsUrl, wsOrigin, username, password, address, userAgent string, evChannel chan map[string]interface{},
	errChannel chan error, stopChan <-chan struct{}, connectAttempts, reconnects int,
	maxReconnectInterval time.Duration, delayFunc func(time.Duration, time.Duration) func() time.Duration) (ari *ARInGOV1, err error)

func (*ARInGOV1) Call

func (ari *ARInGOV1) Call(method, uri string, queryStr map[string]string, bodyParams map[string]string) (reply RESTResponse, err error)

Call represents one REST call to Asterisk using httpClient call If there is a reply from Asterisk it should be in form map[string]interface{}

type QueryString

type QueryString struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type RESTRequest

type RESTRequest struct {
	Type          string        `json:"type"` // must be "RESTRequest"
	TransactionID string        `json:"transaction_id,omitempty"`
	RequestID     string        `json:"request_id"`
	Method        string        `json:"method"`
	URI           string        `json:"uri"`
	ContentType   string        `json:"content_type,omitempty"`
	QueryStrings  []QueryString `json:"query_strings,omitempty"`
}

RESTRequest represents an ARI REST-over-WebSocket request envelope.

type RESTResponse

type RESTResponse struct {
	Type          string `json:"type"`
	TransactionID string `json:"transaction_id,omitempty"`
	RequestID     string `json:"request_id"`
	StatusCode    int    `json:"status_code"`
	ReasonPhrase  string `json:"reason_phrase,omitempty"`
	ContentType   string `json:"content_type,omitempty"`
	Uri           string `json:"uri,omitempty"`
	MessageBody   string `json:"message_body,omitempty"`
	Timestamp     string `json:"timestamp,omitempty"`
	AsteriskID    string `json:"asterisk_id,omitempty"`
	Application   string `json:"application,omitempty"`
}

RESTResponse represents an ARI REST-over-WebSocket response envelope.

Jump to

Keyboard shortcuts

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