I try to create custom keyboard for telegram bot.
Use the solution by AmatuerDev: create dynamic Keyboard telegram bot in c# , MrRoundRobin API
and it looks like this :
How to place a button in a column?
Thanks You!
P.S. Source code:
private static InlineKeyboardButton[][] GetInlineKeyboard(string []
stringArray)
{
var keyboardInline = new InlineKeyboardButton[1][];
var keyboardButtons = new InlineKeyboardButton[stringArray.Length];
for (var i = 0; i < stringArray.Length; i++)
{
keyboardButtons[i] = new InlineKeyboardButton
{
Text = stringArray[i],
CallbackData = "Some Callback Data",
};
}
keyboardInline[0] = keyboardButtons;
return keyboardInline;
}
3
Answers
You need to put each button in array.
Reply markup: keyboard & inline keyboard
Notes:
GetInlineKeyboard
toInlineKeyboardMarkup
instead ofInlineKeyboardButton[][]
var
)List<InlineKeyboardButton>
instead of Array (InlineKeyboardButton[]
)IDictionary<string, string>
to get text and callback dataEvery
IEnumerable<InlineKeyboardButton>
Is single row, This means you should pass list of rows.You shouldn’t use
var keyboardInline = new InlineKeyboardButton[1][];
because this means only one row with buttons in this row!There are two ways below:
Code you wants:
I don’t suggest this code
Best way:
I suggest this code:
I’m not sure if the code has massively changed as I haven’t tried the above method(answered by Muaath), but this was the fix for me, inspiration from Muaath answer above:
Note the difference is there is now a new method:
InlineKeyboardButton.WithCallbackData()
As per documentation:
https://telegrambots.github.io/book/2/reply-markup.html