Checkbox
Checkbox is a built-in scenario for quick inline multi-choice flows. It sends a message with inline buttons, tracks button presses through the waiter machine, and returns the final selection as a dictionary.
This is useful for:
- short menus with multiple toggles
- setup wizards
- confirmation flows with several options
- lightweight conversational funnels
Checkbox is intentionally short-lived. It keeps the interaction inside a single scenario session and is not meant to replace persistent user state.
Recommended usage
In real bots the most convenient entrypoint is usually the Dispatch shortcut:
Reference: examples/checkbox.py
What wait() returns
wait() returns:
dict[Key, bool]with option statesmessage_idof the scenario message
The dictionary preserves your option keys, so you can use strings, enums, or other hashable values as option identifiers.
Adding options
Each option has:
keyused in the resulting dictionarydefault_textshown when the option is not pickedpicked_textshown when the option is picked- optional
is_pickedinitial state - optional
icon_id - optional
style
Example:
Constructor parameters
The current Checkbox constructor accepts:
The most commonly used arguments are:
messagefor the text above the checkboxmax_in_rowfor layoutready_textto customize the submit buttoncancel_textto add a cancel buttonparse_modeif the scenario message uses formatting
Button styles
Checkbox buttons use regular InlineButton under the hood, so style-aware buttons are supported through the scenario parameters and option styles.
That means you can visually distinguish:
- the ready action
- the cancel action
- individual options
via KeyboardButtonStyle values.
Direct construction
If you do not want to use bot.dispatch.checkbox(...), you can instantiate the scenario directly:
Then call .add_option(...) and .wait(api) the same way.
The important detail is that Checkbox needs a WaiterMachine. The dispatch shortcut already provides the correct one for you, which is why it is the recommended path.
Cancellation behavior
If cancel_text is provided, the checkbox renders a separate cancel button.
When the cancel action is pressed:
- the internal option list is cleared
- the wait loop ends
- the returned dictionary is empty
That makes cancellation easy to distinguish from a normal completed selection.
When to use Checkbox vs Choice
Use Checkbox when multiple items may be selected.
Use Choice when only one item should be selected at the end of the interaction.
Both scenarios are built on the same general mechanism, but Choice gives a more natural API for single-select flows.