Reputation: 147
I'm new in telegram bot, and want to create the custom keyboard for my bot, for that purpose write this code:
var rkm = new ReplyKeyboardMarkup();
rkm.Keyboard =
new KeyboardButton[][]
{
new KeyboardButton[]
{
new KeyboardButton("1-1"),
new KeyboardButton("1-2")
},
new KeyboardButton[]
{
new KeyboardButton("2")
},
new KeyboardButton[]
{
new KeyboardButton("3-1"),
new KeyboardButton("3-2"),
new KeyboardButton("3-3")
}
};
WebRequest req = WebRequest.Create("https://api.telegram.org/bot" + "282189232:AAGdsdsdsdVOrsxy2rzU75QUAnWL_F2vo" + "/sendMessage?chat_id=" + chat_id + "&text=" + message + "&reply_markup=" + rkm);
req.UseDefaultCredentials = true;
var result = req.GetResponse();
req.Abort();
but when i run that code in this line:
var result = req.GetResponse();
get this error:
The remote server returned an error: (400) Bad Request.
How can I solve that problem?
Upvotes: 0
Views: 324
Reputation: 1867
As suggested use the library by MrRoundRobin. here is how you would do it:
var keyboard = new ReplyKeyboardMarkup(new [] {
new [] // 1st row
{
new KeyboardButton("1"),
new KeyboardButton("2"),
},
new [] // 2nd row
{
new KeyboardButton("3"),
new KeyboardButton("4"),
}
});
await Bot.SendTextMessageAsync(message.Chat.Id, "Choose", replyMarkup: keyboard);;
Upvotes: 0