InlineMenu<CTX extends Context> constructor

InlineMenu<CTX extends Context>({
  1. String? name,
})

Constructs a InlineMenu

The InlineMenu represents a Inline Keyboard with the action to be done.

The actions parameter is a list of rows, each row is a map of InlineMenuData and Handler. The InlineMenuData represents the text and the data to be sent to the bot when the button is pressed. The Handler is the function to be executed when the button is pressed. The name parameter is the name of the menu.

Example:

Future<void> answer(Context ctx, String text) async {
  final callbackQuery = ctx.callbackQuery!;
  await ctx.api.answerCallbackQuery(
    callbackQuery.id,
    text: "Hello!",
  );
}

final menu = InlineMenu()
  ..text('Hello', (ctx) => answer(ctx, 'Hello!'))
  ..row()
  ..text('World', (ctx) => answer(ctx, 'World!'));

Attach & Use

Now you can attach the menu to the bot and you can use it as a reply markup.

bot.attachMenu(menu);

bot.start((ctx) async {
 await ctx.api.sendMessage(ctx.id, 'Choose an option', replyMarkup: menu);
});

Implementation

InlineMenu({
  String? name,
})  : _buttons = [],
      inlineKeyboard = [],
      name = name ?? _getRandomID();