prompt

package
v3.0.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2016 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package prompt is the utility section for working with asterisk prompts.

Index

Constants

This section is empty.

Variables

View Source
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
)
View Source
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

func MatchLenFunc(length int) func(string) (string, Status)

MatchLenFunc returns a MatchFunc which returns Complete if the given number of digits are received and Incomplete otherwise.

func MatchLenOrTerminatorFunc

func MatchLenOrTerminatorFunc(length int, terminator string) func(string) (string, Status)

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 MatchTerminatorFunc

func MatchTerminatorFunc(terminator string) func(string) (string, Status)

MatchTerminatorFunc is a MatchFunc which returns Complete if the pattern contains the character and Incomplete, otherwise.

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

func Prompt

func Prompt(ctx context.Context, p audio.Player, opts *Options, sounds ...string) (ret *Result, err error)

Prompt plays the given sound and waits for user input.

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

func MatchAny(pat string) (string, Status)

MatchAny is a MatchFunc which returns Complete if the pattern contains any characters.

func MatchHash

func MatchHash(pat string) (string, Status)

MatchHash is a MatchFunc which returns Complete if the pattern contains a hash (#) character and Incomplete, otherwise.

func (Status) String

func (i Status) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL