Documentation ¶
Overview ¶
Package prompt is the utility section for working with asterisk prompts.
Index ¶
- Variables
- func MatchLenFunc(length int) func(string) (string, Status)
- func MatchLenOrTerminatorFunc(length int, terminator string) func(string) (string, Status)
- func MatchSetFunc(set string) func(string) (string, Status)
- func MatchTerminatorFunc(terminator string) func(string) (string, Status)
- type Options
- type Result
- type Status
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultFirstDigitTimeout is the maximum time to wait for the // first digit after a prompt, if not otherwise set. DefaultFirstDigitTimeout = 4 * time.Second // DefaultInterDigitTimeout is the maximum time to wait for additional // digits after the first is received. DefaultInterDigitTimeout = 3 * time.Second // DefaultOverallTimeout is the maximum time to wait for a response // regardless of the number of received digits or pattern matching. DefaultOverallTimeout = 3 * time.Minute )
var Logger = log15.New()
Logger defaults to a discard handler (null output). If you wish to enable logging, you can set your own handler like so:
ari.Logger.SetHandler(log15.StderrHandler)
Functions ¶
func MatchLenFunc ¶
MatchLenFunc returns a MatchFunc which returns Complete if the given number of digits are received and Incomplete otherwise.
func MatchLenOrTerminatorFunc ¶
MatchLenOrTerminatorFunc returns a MatchFunc which returns Complete if the given number of digits are received or the given terminal string is received. Otherwise, it returns Incomplete.
func MatchSetFunc ¶ added in v3.0.16
MatchSetFunc returns a MatchFunc which will match any digit in the provided set of digits
Types ¶
type Options ¶
type Options struct { // FirstDigitTimeout is the maximum length of time to wait // after the prompt sequence ends for the user to enter // a response. // If not specified, the default is DefaultFirstDigitTimeout. FirstDigitTimeout time.Duration // InterDigitTimeout is the maximum length of time to wait // for an additional digit after a digit is received. // If not specified, the default is DefaultInterDigitTimeout. InterDigitTimeout time.Duration // OverallTimeout is the maximum length of time to wait // for a response regardless of digits received. // If not specified, the default is DefaultOverallTimeout. OverallTimeout time.Duration // EchoData is the flag for saying each digit as it is input EchoData bool // MatchFunc is an optional function which, if supplied, returns // a string and an int. // // The string is allows the MatchFunc to return a different number // to be used as `result.Data`. This is commonly used for prompts // which look for a terminator. In such a practice, the terminator // would be stripped from the match and this argument would be populated // with the result. Otherwise, the original string should be returned. // NOTE: Whatever is returned here will become `result.Data`. // // The int parameter indicates the result of the match, and it should // be one of: // Incomplete (0) : insufficient digits to determine match. // Complete (1) : A match was found. // Invalid (2) : A match could not be found, given the digits received. // If this function returns a non-zero int, then the prompt will be stopped. // If not specified MatchAny will be used. MatchFunc func(string) (string, Status) // Which type of word to use when playing '#' SoundHash string // pound or hash }
Options describes options for the prompt
type Result ¶
type Result struct { // Data is the received data (digits) during the prompt Data string // Status is the status of the prompt play Status Status }
Result describes the result of a prompt operation
type Status ¶
type Status int
Status indicates the status of the prompt operation.
const ( // Incomplete indicates that there are not enough digits to determine a match. Incomplete Status = iota // Complete means that a match was found from the digits received. Complete // Invalid indicates that a match cannot be found from the digits received. // No more digits should be received. Invalid // Canceled indicates that matching was canceled Canceled // Timeout indicates that the matching failed due to timeout Timeout // Hangup indicates that a match could not be made due to // the channel being hung up. Hangup // Failed indicates that matching could not be completed // due to a failure (usually an error) Failed )
func MatchAny ¶
MatchAny is a MatchFunc which returns Complete if the pattern contains any characters.