asterisk

module
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2023 License: Apache-2.0

README

Asterisk library for GO

downloads last-release last-commit go-version License

Libs for Golang to work with Asterisk

  • AMI
  • AGI (coming soon)

AMI

  • Async Action
  • Sync Action
  • Event Subscribe
  • Auto Reconnect
package main

import (
	"fmt"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/parsidev/asterisk/ami"
	"github.com/parsidev/asterisk/ami/actions"
)

var msg chan *ami.Message

func main() {
	msg = make(chan *ami.Message)

	go func() {
		for {
			select {
			case d := <-msg:
				fmt.Println(d)
			}
		}
	}()

	conn, err := ami.Connect("172.16.202.129:5038",
		ami.WithAuth("parsa", "password"),
		ami.WithOnConnected(onConnected), ami.WithOnConnectError(onConnectError),
		ami.WithSubscribe(ami.SubscribeChan(msg, "FullyBooted", "StatusComplete", 
			"SuccessfulAuth", "SessionTimeout")))

	if err != nil {
		panic(err)
	}

	response, err := conn.Request(actions.StatusAction{}, ami.RequestTimeout(2*time.Second))
	if err != nil {
		panic(err)
	}

	fmt.Println(response.Format())

	exit := make(chan os.Signal, 1)
	signal.Notify(exit, os.Interrupt, syscall.SIGTERM)

	<-exit
}

func onConnected(c *ami.Conn) {

}

func onConnectError(c *ami.Conn, err error) {
	fmt.Println(err)
}

Directories

Path Synopsis
agi
ami

Jump to

Keyboard shortcuts

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