Reputation: 83
if (update.Message.Text == "/hi" || update.Message.Text == "hi")
{
bot.MakeRequestAsync(new SendMessage(update.Message.Chat.Id, "TEST!")).Wait();
}
telegram api for .net have type of keyboardmuckup but never user in any example i see it. can i implement custom keyboard in telegram bot api to get command from user from button instead command text .
Upvotes: 2
Views: 2521
Reputation: 59
in c# you can do this:
using NetTelegramBotApi.Types;
enter code here
ReplyKeyboardMarkup myKeyboard = new ReplyKeyboardMarkup()
{
Keyboard = new string[][]
{
new string[] { "raw1 key1", "raw1 key2","raw1 key3 " },
new string[] { "raw2 key1", "raw2 key2","raw2 key3 " }
}
};
first array of string shows in first raw and second array shows in second raw ... and you can send this key board to user via sendMessage:
var req =new SendMessage(chatId,"Text if you want") { ReplyMarkup = myKeyboard };
await bot.MakeRequestAsync(req);
Upvotes: 0
Reputation: 1980
Absolutely yes. You never see ReplyKeyboardMarkup
in codes but in telegram bot documnetation. If you look at this documentation, you see many parts( for example ReplyKeyboardMarkup
and each part have some Field
. you must send those fields( specially those Required
fields) with their value, Telegram would recognize that those fields without mentioning titel(title is for example ReplyKeyboardMarkup
) you must not mention these titles in your code.
you can see a working keyborad in php here.
Every thing is simple as sending a message, the main point in keybords is to use triple arrays nested in each other
pseudo code:
keyboard = [[ [key element 1 data] , [key element 2 data] ,[key element 3 data] ]]
Upvotes: 2