Skip to content

Commit

Permalink
Add GetEvents function to decode and receive events from AMI
Browse files Browse the repository at this point in the history
  • Loading branch information
heltonmarx committed Jan 16, 2014
1 parent 57d86b4 commit dac9469
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ami/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,3 +443,16 @@ func ShowDialPlan(socket *Socket, actionID, extension, context string) (map[stri
}
return getMessage(socket, command, actionID)
}

// GetEvents
// Get events from current socket connection
// It is mandatory set 'events' of ami.Login with "system,call,all,user", to received
// events
//
func GetEvents(socket *Socket) (map[string]string, error) {
message, err := decode(socket)
if err != nil {
return nil, err
}
return message, nil
}
52 changes: 52 additions & 0 deletions example/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2014 Helton Marques
//
// Use of this source code is governed by a LGPL
// license that can be found in the LICENSE file.
//

package main

import (
"fmt"
"github.com/heltonmarx/goami/ami"
)

func main() {
socket, err := ami.NewSocket("127.0.0.1:5038")
if err != nil {
fmt.Printf("socket error: %v\n", err)
return
}
if _, err := ami.Connect(socket); err != nil {
return
}
var ret bool

//Login
uuid, _ := ami.GetUUID()
ret, err = ami.Login(socket, "admin", "admin", "system,call,all,user", uuid)
if err != nil || ret == false {
fmt.Printf("login error (%v)\n", err)
return
}
fmt.Printf("login ok!\n")

//Events
for {
events, err := ami.GetEvents(socket)
if err != nil {
fmt.Printf("events error (%v)\n", err)
return
}
fmt.Printf("recv event: %v\n", events)
}

//Logoff
fmt.Printf("logoff\n")
ret, err = ami.Logoff(socket, uuid)
if err != nil || ret == false {
fmt.Printf("logoff error: (%v)\n", err)
return
}
fmt.Printf("goodbye !\n")
}

0 comments on commit dac9469

Please sign in to comment.