Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.31 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.  
  6.     "github.com/ivahaev/amigo"
  7. )
  8.  
  9. // Creating hanlder functions
  10. func asyncAgiHandler(m map[string]string) {
  11.     if m["Event"] == "AsyncAGIStart" {
  12.      fmt.Printf("EEEEEEEEEEEEEEEE %v\n",m)
  13.     }
  14.    }
  15.  
  16. func main() {
  17.     fmt.Println("Init Amigo")
  18.  
  19.     settings := &amigo.Settings{Username: "unix", Password: "unixcrm", Host: "localhost"}
  20.     a := amigo.New(settings)
  21.  
  22.     a.Connect()
  23.  
  24.     // Listen for connection events
  25.     a.On("connect", func(message string) {
  26.         fmt.Println("Connected", message)
  27.     })
  28.     a.On("error", func(message string) {
  29.         fmt.Println("Connection error:", message)
  30.     })
  31.  
  32.     // Registering handler function for event "DeviceStateChange"
  33.     a.RegisterHandler("ASYNCAGI", asyncAgiHandler)
  34.  
  35.     // Optionally create channel to receiving all events
  36.     // and set created channel to receive all events
  37.     c := make(chan map[string]string, 100)
  38.     a.SetEventChannel(c)
  39.  
  40.     // Check if connected with Asterisk, will send Action "QueueSummary"
  41.     if a.Connected() {
  42.         result, err := a.Action(map[string]string{"Action": "QueueSummary", "ActionID": "Init"})
  43.         // If not error, processing result. Response on Action will follow in defined events.
  44.         // You need to catch them in event channel, DefaultHandler or specified HandlerFunction
  45.         fmt.Println(result, err)
  46.     }
  47.    
  48.     ch := make(chan bool)
  49.     <-ch
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement