i am starting to develop telegram bot application. i am using custom keyboard while sending messages to the users. what i need to know is how can i receive the reply from the keyboard button click and how can i response to the user for that particular button click.
After reading telegram bot api i got the idea that i have to getUpdates from the telegram api which are in json, i am finding it difficult to Deserialize json object received through getUpdate method.
I want to know that on users keyboard button click i will receive update by json getUpdate method, by deserialising it i have to response that user_id with particular message with help of c# code, Is this is a right flow i am heading to. I red the github stuff but i didn’t got it.
public async Task sndmsg()
{
var Bot = new Api("MY_TELEGRAM_TOKEN");
var rkm = new Telegram.Bot.Types.ReplyMarkups.ReplyKeyboardMarkup();
//rkm.ResizeKeyboard = true;
rkm.Keyboard = new Telegram.Bot.Types.KeyboardButton[][]
{
new Telegram.Bot.Types.KeyboardButton[]
{
new Telegram.Bot.Types.KeyboardButton("button 1")
},
new Telegram.Bot.Types.KeyboardButton[]
{
new Telegram.Bot.Types.KeyboardButton("button 2")
},
new Telegram.Bot.Types.KeyboardButton[]
{
new Telegram.Bot.Types.KeyboardButton("button 3")
},
new Telegram.Bot.Types.KeyboardButton[]
{
new Telegram.Bot.Types.KeyboardButton("button 4")
}
};
string cht_id = "201520743";
string txt = "this is keyboard in reply";
await Bot.SendTextMessage(cht_id, txt, false, false, 0, rkm);
}
I have this which i want to response when user click particular button.
I want to know:
-
whether i am in right direction or not?
-
How request response flow work while chatting with bot?
-
How can i receive response of keyboard button click and reply to the user for that button click. If using json it will be helpful if someone guide with an example for that in c#?
-
Is there a way to trigger a callback url for keyboard button click which can be resolved on server and in then particular reply send to user according to that button click?
Can someone guide me in right direction?
2
Answers
Please see this example:
Telegram.Bot.Example in c#
Unfortunately, You can’t do this in
ReplyKeyboardMarkup
like what do you want.Becuase this type of keyboard on click will send message with same text on clicked buttons.
If user click button 1 the telegram will send message with text "button 1".
But
ReplyKeyboardMarkup
is useful when you need to request contact, poll or location.I Suggest you to use
InlineKeyboardMarkup
that you will receive data inOnCallbackQuery
event