Giter Site home page Giter Site logo

aringo's Introduction

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
}

aringo's People

Contributors

adragusin avatar cgrates avatar danbogos avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.