ivahaev/amigo
Fork: 46 Star: 104 (更新于 2024-10-29 16:50:41)
license: MIT
Language: Go .
Asterisk AMI connector in golang
最后发布版本: v0.1.10 ( 2020-05-16 01:40:48)
amigo
Asterisk AMI connector on golang.
Attention! API has been changed in v0.1.2. Please read the godoc.
Usage is pretty simple.
Installation:
go get github.com/ivahaev/amigo
Using
Import module to your project:
import "github.com/ivahaev/amigo"
Then use:
package main
import (
"fmt"
"github.com/ivahaev/amigo"
)
// 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)
a.Connect()
// 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.
a.RegisterDefaultHandler(DefaultHandler)
// Optionally create channel to receiving all events
// and set created channel to receive all events
c := make(chan map[string]string, 100)
a.SetEventChannel(c)
// 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)
<-ch
}
SIC!
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.
最近版本更新:(数据更新于 2024-10-02 06:45:36)
2020-05-16 01:40:48 v0.1.10
2017-07-11 16:01:54 v0.1.9
2017-07-11 03:05:14 v0.1.8
2017-03-19 00:22:32 v0.1.7
2017-03-09 04:29:47 v0.1.6
2017-02-27 06:07:02 v0.1.5
2017-02-27 05:45:00 v0.1.4
2017-02-26 16:46:47 v0.1.3
ivahaev/amigo同语言 Go最近更新仓库
2024-11-06 07:46:48 dolthub/dolt
2024-11-06 03:37:39 containerd/containerd
2024-11-05 20:42:00 aurora-develop/aurora
2024-11-05 08:55:31 XTLS/Xray-core
2024-11-05 00:03:47 SagerNet/sing-box
2024-11-04 20:34:19 Permify/permify