KeyboardMenu<CTX extends Context> class
A reply keyboard menu with text handlers.
This class provides a fluent API for building reply keyboards where each button can have an associated handler function. When the menu is attached to a bot, the handlers are automatically registered.
Example:
final menu = KeyboardMenu<Context>()
.text('Hello', (ctx) async {
await ctx.reply('You said hello!');
})
.text('Goodbye', (ctx) async {
await ctx.reply('You said goodbye!');
})
.row()
.requestContact('Share Contact', (ctx) async {
await ctx.reply('Thanks for sharing your contact!');
})
.resized()
.oneTime();
// Attach to bot
bot.attachMenu(menu);
// Use in message
await ctx.reply('Choose an option:', replyMarkup: menu);
- Inheritance
-
- Object
- TeleverseMenu<
CTX> - KeyboardMenu
- Implemented types
- Available extensions
Constructors
- KeyboardMenu({String? name})
- Creates a new keyboard menu.
Properties
- $type → String
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- inputFieldPlaceholder → String?
-
Optional. The placeholder to be shown in the input field when the
keyboard is active; 1-64 characters
no setter
- isPersistent → bool?
-
Optional. Requests clients to always show the keyboard when the regular
keyboard is hidden. Defaults to false, in which case the custom keyboard
can be hidden and opened with a keyboard icon.
no setter
-
keyboard
→ List<
List< KeyboardButton> > -
Array of button rows, each represented by an Array of KeyboardButton
objects
no setter
- name → String
-
The unique name/identifier for this menu.
finalinherited
- oneTimeKeyboard → bool?
-
Optional. Requests clients to hide the keyboard as soon as it's been
used. The keyboard will still be available, but clients will
automatically display the usual letter-keyboard in the chat – the user
can press a special button in the input field to see the custom keyboard
again. Defaults to false.
no setter
- resizeKeyboard → bool?
-
Optional. Requests clients to resize the keyboard vertically for optimal
fit (e.g., make the keyboard smaller if there are just two rows of
buttons). Defaults to false, in which case the custom keyboard is always
of the same height as the app's standard keyboard.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selective → bool?
-
Optional. Use this parameter if you want to show the keyboard to
specific users only. Targets:
no setter
Methods
-
chat(
String text, int requestId, MenuHandler< CTX> handler, {bool chatIsChannel = false, bool? chatIsForum, bool? chatHasUsername, bool? chatIsCreated, ChatAdministratorRights? userAdministratorRights, ChatAdministratorRights? botAdministratorRights, bool? botIsMember}) → KeyboardMenu<CTX> - Adds a chat request button to the current row.
-
makeSelective(
[bool selective = true]) → KeyboardMenu< CTX> - Makes the keyboard selective.
-
map<
TResult extends Object?> ({required TResult forceReply(ForceReply value), required TResult inlineKeyboard(InlineKeyboardMarkup value), required TResult keyboard(ReplyKeyboardMarkup value), required TResult keyboardRemove(ReplyKeyboardRemove value)}) → TResult -
Available on ReplyMarkup, provided by the ReplyMarkupPatterns extension
Aswitch-like method, using callbacks. -
mapOrNull<
TResult extends Object?> ({TResult? forceReply(ForceReply value)?, TResult? inlineKeyboard(InlineKeyboardMarkup value)?, TResult? keyboard(ReplyKeyboardMarkup value)?, TResult? keyboardRemove(ReplyKeyboardRemove value)?}) → TResult? -
Available on ReplyMarkup, provided by the ReplyMarkupPatterns extension
A variant ofmapthat fallback to returningnull. -
maybeMap<
TResult extends Object?> ({TResult forceReply(ForceReply value)?, TResult inlineKeyboard(InlineKeyboardMarkup value)?, TResult keyboard(ReplyKeyboardMarkup value)?, TResult keyboardRemove(ReplyKeyboardRemove value)?, required TResult orElse()}) → TResult -
Available on ReplyMarkup, provided by the ReplyMarkupPatterns extension
A variant ofmapthat fallback to returningorElse. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
oneTime(
[bool oneTime = true]) → KeyboardMenu< CTX> - Makes the keyboard appear only once.
-
persistent(
[bool persistent = true]) → KeyboardMenu< CTX> - Makes the keyboard persistent.
-
placeholder(
String placeholder) → KeyboardMenu< CTX> - Sets the input field placeholder.
-
poll(
String text, MenuHandler< CTX> handler, {PollType? type}) → KeyboardMenu<CTX> - Adds a poll request button to the current row.
-
requestContact(
String text, MenuHandler< CTX> handler) → KeyboardMenu<CTX> - Adds a contact request button to the current row.
-
requestLocation(
String text, MenuHandler< CTX> handler) → KeyboardMenu<CTX> - Adds a location request button to the current row.
-
resized(
[bool resize = true]) → KeyboardMenu< CTX> - Makes the keyboard resize to fit optimally.
-
row(
) → KeyboardMenu< CTX> - Starts a new row.
-
text(
String text, MenuHandler< CTX> handler) → KeyboardMenu<CTX> - Adds a text button to the current row.
-
toJson(
) → Map< String, dynamic> - Serializes this ReplyMarkup to a JSON map.
-
toReplyMarkup(
) → ReplyMarkup -
Converts this menu to a reply markup that can be sent with messages.
override
-
toString(
) → String -
A string representation of this object.
override
-
users(
String text, int requestId, MenuHandler< CTX> handler, {bool? userIsBot, bool? userIsPremium, int? maxQuantity}) → KeyboardMenu<CTX> - Adds a user request button to the current row.
-
webApp(
String text, String url) → KeyboardMenu< CTX> - Adds a web app button to the current row.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited