xooniverse / televerse

Your gateway to seamless Telegram Bot Development 💙
https://televerse.xooniverse.com
BSD 3-Clause "New" or "Revised" License
64 stars 11 forks source link

Introducing Menu 🎲 #126

Closed HeySreelal closed 1 year ago

HeySreelal commented 1 year ago

The TeleverseMenu is a markup assist to create InlineKeyboards or Keyboards in an easy and efficient way.

For example, there will be many times you will have to show an Inline Keyboard to the user. And for all the callback queries received you might want to set up a handler by repeatedly using the bot.callbackQuery or a totally messy code with bot.onCallbackQuery.

Here comes Menus to rescue. The following is a simple example to illustrate its usage.

// Create the menu
final startMenu = InlineMenu(name: "Start Menu")
    .text("Hello", helloCallback)
    .row()
    .text("Start", firstCallback)
    .text("Finish", finishCallback);

And then we simply attach the menu to the bot and the bot will start listening for menu updates.

  // Attach it to the bot
  bot.attachMenu(startMenu);

After that, we'll show the menu to the user just like we show a Keyboard or InlineKeyboard.

 // Start the bot and listen for /start command updates
  bot.start((ctx) {
    // Reply with the menu
    ctx.reply(
      "Hello, choose an option:",
      replyMarkup: startMenu,
    );
  });

There we go, isn't that simple? 😉