Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "github.com/ivahaev/amigo"
- )
- // Creating hanlder functions
- func asyncAgiHandler(m map[string]string) {
- if m["Event"] == "AsyncAGIStart" {
- fmt.Printf("EEEEEEEEEEEEEEEE %v\n",m)
- }
- }
- func main() {
- fmt.Println("Init Amigo")
- settings := &amigo.Settings{Username: "unix", Password: "unixcrm", Host: "localhost"}
- 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("ASYNCAGI", asyncAgiHandler)
- // 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
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement