menu

Application Menus

Writing menus in an summit application can be very error prone and repetitive task with a lot of boiler plate code. The menu class helps to make this easier for the application author.

A typical menu looks something like the following

local digit = channel.gather({play="Press 1 to play messages.  Press 2 to delete all messages", maxDigits=1})
if digit == '1' then
    return play_messages
elseif digit == '2' then
    return delete_all_messages
else
    return invalid_input
end

Using the menu class this gets simplified to the following

local menu = require "summit.menu"
local my_menu = menu.Menu()
my_menu.add("1", "Press 1 to play messages", play_messages)
my_menu.add("2", "Press 2 to delete all messages", delete_all_messages)
my_menu.default(invalid_input)
my_menu.run()

Classes

Name Summary
Menu

A menu that can be played.

Classes : menu

Menu

A menu that can be played.

Fields
Name Type Summary
selection

string

The input that the user entered

SILENCE

string

Constant for silence. If you want to play silence, this is the tone to use

Constructor
Name Summary
Menu()

Creates an instance of Menu

Functions
Name Returns Summary
add(entry, prompt, func)

nil

Adds a user selectable entry to the menu.

attempts(attempts)

nil

Set the number of attempts at gathering input before considering it invalid.

default(func)

nil

Set the function to call when input has reached an invalid state.

digitTimeout(seconds)

nil

Set the number of seconds to wait between digits before considering the input invalid.

intro(prompt)

nil

Adds an intro to the menu.

invalid(sound)

nil

Set the sound to play on unexpected entry.

outro(prompt)

nil

Adds an outro to the menu.

run(opts)

any

Run the menu.

timeout(seconds)

nil

Set the number of seconds to wait for input before considering the input invalid.

Menu()

Creates an instance of Menu

Returns
Type Summary

Menu

An instance of Menu

Menu.add(entry, prompt, func)

Adds a user selectable entry to the menu.

Parameters
Name Type Default Summary

entry

string

The digit for the caller to enter.

prompt

string or Asset

The prompt to play for the item. Can be a URL.

func

function

The function to return when the user selects this option

Returns
Type Summary

nil

Menu.attempts(attempts)

Set the number of attempts at gathering input before considering it invalid.

Parameters
Name Type Default Summary

attempts

number

The number of attempts.

Returns
Type Summary

nil

Menu.default(func)

Set the function to call when input has reached an invalid state.

Parameters
Name Type Default Summary

func

function

The function.

Returns
Type Summary

nil

Menu.digitTimeout(seconds)

Set the number of seconds to wait between digits before considering the input invalid.

Parameters
Name Type Default Summary

seconds

number

The number of seconds to wait.

Returns
Type Summary

nil

Menu.intro(prompt)

Adds an intro to the menu. This may be called multiple times and the intros will be played in the order that there are added.

Parameters
Name Type Default Summary

prompt

string or Asset

The prompt to play as an intro. Can be a URL.

Returns
Type Summary

nil

Menu.invalid(sound)

Set the sound to play on unexpected entry. To make this silent, you can use ‘silence_stream://500’, which will play half a second of silence, or the constant SILENCE.

Parameters
Name Type Default Summary

sound

string or Asset

The file or URL to play when an invalid entry is entered.

Returns
Type Summary

nil

Menu.outro(prompt)

Adds an outro to the menu. This may be called multiple times and the outros will be played in the order that there are added.

Parameters
Name Type Default Summary

prompt

string or Asset

The prompt to play as an outro. Can be a URL.

Returns
Type Summary

nil

Menu.run(opts)

Run the menu. This function will build and run the menu, and will then call the registered function corresponding to the user’s input.

Parameters
Name Type Default Summary

opts

table

A list of additional options to pass to channel.gather.

Returns
Type Summary

any

The result of the callback function matching whatever the user input.

Menu.timeout(seconds)

Set the number of seconds to wait for input before considering the input invalid.

Parameters
Name Type Default Summary

seconds

number

The number of seconds to wait

Returns
Type Summary

nil