The Menu API allows you to create inline keyboards easily.
To use this MenuAPI you need to include it in your pom.xml:
<dependency> <groupId>com.jtelegram</groupId> <artifactId>jtelegrambotapi-menus</artifactId> <version>LATEST</version> </dependency>
To build a SimpleMenu:
SimpleMenu menu = SimpleMenu.builder().bot(telegramBot).build();
With this method, you're essentially bootstrapping a Menu. Once that is done, you can add a row of buttons to this Menu using the menu#addRow method.
menu#addRow
For example:
AtomicInteger integer = new AtomicInteger(); menu.addRow(MenuRow .from(SimpleMenuButton.builder() .label("Test") .onPress((simpleMenuButton, callbackQueryEvent) -> { simpleMenuButton.setLabel("Another Test: " + integer.getAndIncrement()); return true; }) .build() ));
Once this is complete, we have to essentially tell the API who we want to display this menu to. This is simply done using:
menu.addViewer(InlineMenuViewer.builder().inlineMessageId(inlineMessageId).build());
And finally, we register it:
MenuHandler.registerMenu(menu);
There was an error while loading. Please reload this page.