First of all, you need to initialize the object of TelegramBotClient and run.
var botClient = new TelegramBotClient(token);
...
var me = await botClient.GetMeAsync();
Initialize your list of objects
List<MenuButtonModel> buttonModels = new()
{
new MenuButtonModel("Button1", "Button1Value"),
new MenuButtonModel("Button2", "Button2Value"),
new MenuButtonModel("Button3", "Button3Value"),
new MenuButtonModel("Button4", "Button4Value"),
new MenuButtonModel("Button5", "Button5Value"),
new MenuButtonModel("Button6", "Button6Value"),
new MenuButtonModel("Button7", "Button7Value"),
new MenuButtonModel("Button8", "Button8Value"),
new MenuButtonModel("Button9", "Button9Value"),
};
Use GetPaginationInlineKeyboard
method for get InlineKeyboardMarkup and send telegram message
const int columnCount = 2;
const int rowCount = 3;
var replyMenu = botClient.GetPaginationInlineKeyboard(buttonModels, columnCount, rowCount);
await botClient.SendTextMessageAsync(chatId, "YourMessage", replyMarkup: replyMenu);
You have to send clickedNavigation
// clickedNavigation - Data from CallbackQuery
var replyMenu = client.GetPaginationInlineKeyboard(buttonModels, columnCount, rowCount, clickedNavigation);
await botClient.EditMessageReplyMarkupAsync(chatId, messageId, replyMenu);
In addition to navigation, you can send child elements to the constructor for a tree-like architecture.
var childrenItems = new List<MenuButtonModel>() { new MenuButtonModel("ButtonInside", "InsideData") };
var item = new MenuButtonModel("Button1", "Button1Value", childrenItems);
You can change the text of the navigation buttons.
// Default values
public static class Settings
{
public static string ButtonNextText = "»";
public static string ButtonPrevText = "«";
public static string ButtonUpText = "« up";
public const string PaginationData = "toPage";
}
...
// Custom values
Settings.ButtonNextText = "👉";
Settings.ButtonPrevText = "👈";
-> Click Button5 ->
For a more detailed analysis, see the TelegramBotMenu.Tests