func playAndGetOneDigit( sound string, c *eventsocket.Connection, uuid string) string { c.Send("filter Unique-ID " + uuid) c.Send("event plain CHANNEL_EXECUTE_COMPLETE") { _, err := c.ExecuteUUID( uuid, "play_and_get_digits", "1 1 1 400 # "+ sound+" silence_stream://250 result \\d") if err != nil { fmt.Println("Error executing play_and_get_digits: ", err) return "" } } finished := false ret := "" for !finished { ev, err := c.ReadEvent() if err != nil { finished = true } else { if ev.Get("Event-Name") == "CHANNEL_EXECUTE_COMPLETE" && ev.Get("Application") == "play_and_get_digits" { ret = ev.Get("Variable_result") finished = true } } } c.Send("noevents") c.Send("filter delete Unique-ID " + uuid) return ret }
func handler(c *eventsocket.Connection) { fmt.Println("new client:", c.RemoteAddr()) c.Send("connect") c.Send("myevents") c.Execute("answer", "", false) ev, err := c.Execute("playback", audioFile, true) if err != nil { log.Fatal(err) } ev.PrettyPrint() for { ev, err = c.ReadEvent() if err != nil { log.Fatal(err) } fmt.Println("\nNew event") ev.PrettyPrint() if ev.Get("Application") == "playback" { if ev.Get("Application-Response") == "FILE PLAYED" { c.Send("exit") } } } }