Skip to content

TelegramBotExtensions/Telegram.Bot.Extensions.KeyboardBuilders

Repository files navigation

Keyboard builders

license

Branch Status
master Build status
develop Build status

This library is supposed to be used with Telegram.Bot.

Usage

Reply keyboard markup:

var keyboard = new ReplyKeyboardBuilder();

keyboard.AddRow(row =>
    {
        row.AddButton(new KeyboardButton("Hello"))
            .AddTextButton("World");
    })
    .AddRow(row =>
    {
        row.AddContactButton("Send your contact")
            .AddLocationButton("Sens your location");
    });

// You can then either use implicit convertion to  appropriate reply markup type:

ReplyKeyboardMarkup implicitReplyMarkup = keyboard;

// Or pass it as a parameter to markup constructor:
var replyMarkup = new ReplyKeyboardMarkup(keyboard);

Inline keyboard markup:

var inlineKeyboard = new InlineKeyboardBuilder();

inlineKeyboard.AddRow(row =>
    {
        row.AddPaymentButton("Pay");

        var button = InlineKeyboardButton
            .WithCallbackData("Button text", "callback data");

        row.AddButton(button);
            .AddCallbackDataButton("Do something", "{callback data}");
    })
    .AddRow(row =>
    {
        row.AddContactButton("Send your contact")
            .AddLocationButton("Sens your location");
    });


InlineKeyboardMarkup implicitReplyMarkup = inlineKeyboard;

var replyMarkup = new InlineKeyboardMarkup(inlineKeyboard);