Menu

The Menu class provides a fluent interface for building USSD menus and responses.

Basic Usage

protected function buildMenu(Context $context): Menu
{
    return (new Menu())
        ->text('Welcome!')
        ->option('1', 'Option 1')
        ->option('2', 'Option 2')
        ->expectsInput();
}

Menu Methods

text($text)

Sets the main text content of the menu.

option($key, $label)

Adds a numbered option to the menu. The key is what the user will input, and the label is the display text.

listing(array $items)

Adds a numbered listing of items, automatically numbering them starting from 1.

expectsInput()

Indicates that the menu expects user input (CON response).

paginate(array $items, int $perPage, int $page)

Adds a paginated listing of items with automatic "More" option if there are additional pages.

Example

protected function buildMenu(Context $context): Menu
{
    return (new Menu())
        ->text('Select an option:')
        ->option('1', 'Check Balance')
        ->option('2', 'Transfer Funds')
        ->option('3', 'View History')
        ->expectsInput();
}