gami

package module
v0.0.0-...-5bbeb2a Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2015 License: MIT Imports: 7 Imported by: 0

README

GAMI

GO - Asterisk AMI Interface

communicate with the Asterisk AMI, Actions and Events.

Example connecting to Asterisk and Send Action get Events.

package main
import (
	"log"
	"github.com/xytis/gami"
	"github.com/xytis/gami/event"
)

func main() {
	ami, err := gami.Connect("127.0.0.1:5038", "admin", "root")
	if err != nil {
		log.Fatal(err)
	}

	//install manager
	go func() {
		for {
			select {
			case ev, ok := <-ami.Events:
				if !ok {
					return
				}
				log.Println("received an event", ev, ok)
				log.Println("event type:", event.New(ev))
			case err, ok := <-ami.Errors:
				log.Println("received an error", err, ok)
			case fatal, ok := <-ami.Fatal:
				log.Println("ami stack died with", fatal, ok)
				log.Println("should try to recover...")
				return
			}
		}
	}()

	if rs, err = ami.Action("Ping", nil); err != nil {
		log.Fatal(rs)
	}

	//async actions
	rsPing, rsErr := ami.AsyncAction("Ping", gami.Params{"ActionID": "pingo"})
	if rsErr != nil {
		log.Fatal(rsErr)
	}

	if rs, err = ami.Action("Events", ami.Params{"EventMask":"on"}); err != nil {
		log.Fatal(err)
	}

	log.Println("ping:", <-rsPing)

	ami.Close()
}

CURRENT EVENT TYPES

The events use documentation and struct from PAMI.

use xytis/gami/event.New() for get this struct from raw event

EVENT ID TYPE TEST
Newchannel YES
Newexten YES
Newstate YES
Dial YES
ExtensionStatus YES
Hangup YES
PeerStatus YES
PeerEntry YES
VarSet YES
AgentLogin YES
Agents YES
AgentLogoff YES
AgentConnect YES
RTPReceiverStats YES
RTPSenderStats YES
Bridge YES

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAMI = errors.New("Server not AMI interface")

Raise when not response expected protocol AMI

Functions

This section is empty.

Types

type AMIAction

type AMIAction struct {
	Response chan AMIResponse
	Error    chan error
}

AMIAction

type AMIClient

type AMIClient struct {
	Events chan *AMIEvent
	Errors chan error
	Fatal  chan error
	// contains filtered or unexported fields
}

AMIClient a connection to AMI server

func Connect

func Connect(address string, user string, secret string) (client *AMIClient, err error)

Create a new connection to AMI

func (*AMIClient) Action

func (client *AMIClient) Action(action string, params Params) (*AMIResponse, error)

Action send with params

func (*AMIClient) AsyncAction

func (client *AMIClient) AsyncAction(action string, params Params) (<-chan *AMIResponse, error)

AsyncAction returns chan for wait response of action with parameter *ActionID* this can be helpful for massive actions,

func (*AMIClient) Close

func (client *AMIClient) Close() error

Close the connection to AMI

type AMIEvent

type AMIEvent struct {
	ID        string
	Privilege []string
	Params    Params
}

AMIEvent it's a representation of Event readed

type AMIResponse

type AMIResponse struct {
	ID     string
	Status string
	Params Params
}

AMIResponse from action

type MIMEReadWriteCloser

type MIMEReadWriteCloser interface {
	PrintfLine(format string, args ...interface{}) error
	ReadMIMEHeader() (textproto.MIMEHeader, error)
	Close() error
}

sub-interface that is user by this lib

type Params

type Params map[string]string

Params for the actions

Directories

Path Synopsis
Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event decoder This Build Type of Event received Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI
Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event decoder This Build Type of Event received Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI Package event for AMI

Jump to

Keyboard shortcuts

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