robertogyn19 / amigo

Asterisk AMI connector in golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Asterisk AMI connector on golang.

Attention! API has been changed in v0.1.2. Please read the godoc.

Usage is pretty simple.


go get


Import module to your project:

import ""

Then use:

package main

import (


// Creating hanlder functions
func DeviceStateChangeHandler(m map[string]string) {
	fmt.Printf("DeviceStateChange event received: %v\n", m)

func DefaultHandler(m map[string]string) {
	fmt.Printf("Event received: %v\n", m)

func main() {
	fmt.Println("Init Amigo")

	settings := &amigo.Settings{Username: "username", Password: "password", Host: "host"}
	a := amigo.New(settings)


	// Listen for connection events
	a.On("connect", func(message string) {
		fmt.Println("Connected", message)
	a.On("error", func(message string) {
		fmt.Println("Connection error:", message)

	// Registering handler function for event "DeviceStateChange"
	a.RegisterHandler("DeviceStateChange", DeviceStateChangeHandler)

	// Registering default handler function for all events.

	// Optionally create channel to receiving all events
	// and set created channel to receive all events
	c := make(chan map[string]string, 100)

	// Check if connected with Asterisk, will send Action "QueueSummary"
	if a.Connected() {
		result, err := a.Action(map[string]string{"Action": "QueueSummary", "ActionID": "Init"})
		// If not error, processing result. Response on Action will follow in defined events.
		// You need to catch them in event channel, DefaultHandler or specified HandlerFunction
		fmt.Println(result, err)
	ch := make(chan bool)


You should not modify received events, because it can be read in another amigo goroutine. If you need to modify, you should copy all values to another map and modify it.


Asterisk AMI connector in golang


Language:Go 100.0%