package main
import (
"fmt"
"log"
"github.com/heltonmarx/goami/ami"
)
var username, secret, host string = "test", "test", "127.0.0.1:5038"
func main() {
//flag.Parse()
socket, err := ami.NewSocket(host)
orig := ami.OriginateData{}
////////////////////////////////////////////////
orig.Channel = "Local/1000@leg1"
orig.Exten = "2000"
orig.Context = "leg2"
orig.Priority = 1
//orig.Application = ""
orig.Data = ""
orig.Timeout = 10
//orig.CallerID = "bot"
//orig.Variable = ""
//orig.Account = "bot"
orig.Async = "true"
//orig.Codecs = "alaw&ulaw&g729"
////////////////////////////////////////////////
socket, err := ami.NewSocket(host)
if err != nil {
log.Fatalf("socket error: %v\n", err)
}
if _, err := ami.Connect(socket); err != nil {
log.Fatalf("connect error: %v\n", err)
}
//Generate UUID for AMI requests
uuid, _ := ami.GetUUID()
if err := ami.Login(socket, username, secret, "Off", uuid); err != nil {
log.Fatalf("login error: %v\n", err)
}
fmt.Printf("login ok!\n")
if res, err := ami.Originate(socket, uuid, orig); err != nil {
println("ERROR: ", err)
println("Response: ", res)
}
println("Call originated Successfully")
//time.Sleep(5 * time.Second)
if ami.Logoff(socket, uuid) != nil {
println("Logoff Failed")
} else {
println("Logoff successful")
}
}
/// Asterisk Dialplan
/etc/asterisk/extensions.conf
//////////////////////////////////////////////////////
[leg1]
exten =>1000,1,NoOp(leg1)
same=>n,Answer()
[leg2]
exten =>2000,1,NoOp(leg2)
same=>n,playback(tt-monkies)
// Asterisk Manager configuration
//////////////////////////////////////////
/etc/asterisk/manager.conf
[test]
secret=test
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.0
read=system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate
write=system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate
import (
"fmt"
"log"
"github.com/heltonmarx/goami/ami"
)
var username, secret, host string = "test", "test", "127.0.0.1:5038"
func main() {
//flag.Parse()
socket, err := ami.NewSocket(host)
orig := ami.OriginateData{}
////////////////////////////////////////////////
orig.Channel = "Local/1000@leg1"
orig.Exten = "2000"
orig.Context = "leg2"
orig.Priority = 1
//orig.Application = ""
orig.Data = ""
orig.Timeout = 10
//orig.CallerID = "bot"
//orig.Variable = ""
//orig.Account = "bot"
orig.Async = "true"
//orig.Codecs = "alaw&ulaw&g729"
////////////////////////////////////////////////
socket, err := ami.NewSocket(host)
if err != nil {
log.Fatalf("socket error: %v\n", err)
}
if _, err := ami.Connect(socket); err != nil {
log.Fatalf("connect error: %v\n", err)
}
//Generate UUID for AMI requests
uuid, _ := ami.GetUUID()
if err := ami.Login(socket, username, secret, "Off", uuid); err != nil {
log.Fatalf("login error: %v\n", err)
}
fmt.Printf("login ok!\n")
if res, err := ami.Originate(socket, uuid, orig); err != nil {
println("ERROR: ", err)
println("Response: ", res)
}
println("Call originated Successfully")
//time.Sleep(5 * time.Second)
if ami.Logoff(socket, uuid) != nil {
println("Logoff Failed")
} else {
println("Logoff successful")
}
}
/// Asterisk Dialplan
/etc/asterisk/extensions.conf
//////////////////////////////////////////////////////
[leg1]
exten =>1000,1,NoOp(leg1)
same=>n,Answer()
[leg2]
exten =>2000,1,NoOp(leg2)
same=>n,playback(tt-monkies)
// Asterisk Manager configuration
//////////////////////////////////////////
/etc/asterisk/manager.conf
[test]
secret=test
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.0
read=system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate
write=system,call,log,verbose,command,agent,user,config,command,dtmf,reporting,cdr,dialplan,originate