aringo

package module
v0.0.0-...-4956769 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 14 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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"
	HTTP_PUT    = "PUT"
)

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, body []byte) (RESTResponse, error)

Call sends a REST request over WebSocket with optional query params and JSON body.

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, body []byte) (reply RESTResponse, err error)

Call represents one REST call to Asterisk using httpClient call

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"`
	MessageBody   string        `json:"message_body,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
⌂ 换网址