VoipKit is an Asterisk VOIP library implemented in the Go programming language (Golang). It provides a powerful and flexible toolkit for building scalable and high-performance VOIP applications. This user guide will walk you through the installation, requirements, and key features of VoipKit.
Go version 1.20 or higher
You can install VoipKit using one of the following methods:
go get github.com/pnguyen215/voipkit@v1.0.1
go get -u github.com/pnguyen215/voipkit@latest
VoipKit provides a comprehensive set of features for building and managing VOIP applications, including:
To start using VoipKit in your Go project, import the library:
import (
"github.com/pnguyen215/voipkit"
)
To establish a connection with the Asterisk server, you need to create an AMI instance and provide the necessary configuration:
func CreateConn() (*ami.AMI, error) {
c := ami.GetAmiClientSample().
SetEnabled(true).
SetHost("127.0.0.1").
SetPort(5038).
SetUsername("username").
SetPassword("password").
SetTimeout(10 * time.Second)
ami.D().Debug("Asterisk server credentials: %v", c.String())
return ami.NewClient(ami.NewTcp(), *c)
}
To retrieve the list of SIP peers from Asterisk, you can use the GetSIPPeers method:
func GetSIPPeers() {
c, err := CreateConn()
if err != nil {
ami.D().Error(err.Error())
return
}
c.Core().AddSession()
peers, err := c.Core().GetSIPPeers(c.Context())
if err != nil {
ami.D().Error(err.Error())
return
}
for _, v := range peers {
ami.D().Info("Peer: %v", v.Get("object_name"))
}
}
To retrieve the status of a specific SIP peer, you can use the GetSIPPeerStatus method:
func GetSIPPeerStatus() {
c, err := createConn()
if err != nil {
ami.D().Error(err.Error())
return
}
c.Core().AddSession()
peer, err := c.Core().GetSIPPeerStatus(c.Context(), "1004")
if err != nil {
ami.D().Error(err.Error())
return
}
ami.D().Info("Peer: %v| Status: %v", peer.Get("peer"), peer.Get("peer_status"))
}
To execute Asterisk CLI commands, you can use the Command method:
func ExecuteCLICommand() {
c, err := CreateConn()
if err != nil {
ami.D().Error(err.Error())
return
}
c.Socket().SetDebugMode(true)
c.Core().AddSession()
response, err := c.Core().Command(c.Context(), "sip show users")
if err != nil {
ami.D().Error(err.Error())
return
}
fmt.Println(ami.JsonString(response))
VoipKit leverages Github Actions for continuous integration and deployment. The following actions are used:
VoipKit is a powerful and flexible library for building VOIP applications using Go and Asterisk. With its rich set of features and modular architecture, it enables developers to create scalable and efficient VOIP solutions. By following this user guide and leveraging the provided resources, you can quickly get started with VoipKit and build robust VOIP applications.