Exemplo n.º 1
0
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
}