Telegram.Bot
Telegram.Bot copied to clipboard
Custom Dynamic Keyboard
Hi, I have some command in my BOT (look like bellow sample), how can define custom keyboard? (I need a keyboard with 4 row, each button in a row) please help me :)
Sample: /start /GetNext /Status /DayInfo /Help
see this comment
@MrRoundRobin thanxxxxx
using Telegram.Bot.Types?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telegram.Bot.Types;
namespace TelegramBot
{
public static class KeyBoardHelper
{
public static ReplyKeyboardMarkup CreateMainMenu()
{
return new ReplyKeyboardMarkup
{
Keyboard = new[]
{
new KeyboardButton[] // First Row
{
"A",
"B",
},
new KeyboardButton[] // Second Row
{
"C",
"D",
},
}
};
}
}
}
Solved. "KeyboardButton[]" changed to "string[]" and worked fine!
var rkm = new ReplyKeyboardMarkup();
var rows = new List<KeyboardButton[]>();
var cols = new List<KeyboardButton>();
for (var Index = 1; Index < 17; Index++)
{
cols.Add(new KeyboardButton("" + Index));
if (Index%4 != 0) continue;
rows.Add(cols.ToArray());
cols = new List<KeyboardButton>();
}
rkm.Keyboard = rows.ToArray();
await botClient.SendTextMessageAsync(
message.Chat.Id,
"Choose",
replyMarkup: rkm);
https://stackoverflow.com/a/49364380/1770868