I’m developing a simple telegram bot with node.js telegram-bot.
https://github.com/yagop/node-telegram-bot-api
For now I want user to stop typing messages (with letters), just pressing one of a few buttons. And when he clicks on the button, his telegram’s client has to send back to my bot another message (something like “clicked yes” or “clicked no”).
I’ve found that it can be made with
var options = {
reply_markup: JSON.stringify({
inline_keyboard: [
[{ text: 'Some button text 1', callback_data: '1' }],
[{ text: 'Some button text 2', callback_data: '2' }],
[{ text: 'Some button text 3', callback_data: '3' }]
]
})
};
bot.sendMessage(msg.chat.id, "answer.", option);
So user receives 3 kind of messages, and when he clicks them, he doesn’t send me back anything.
I need another type of buttons (which will be in the bottom of client’s app).
3
Answers
You need to listen for the
callback_query
.. As outlined :More info can be found in the library itself. : https://github.com/yagop/node-telegram-bot-api/blob/0174b875ff69f6750fc80a049315c9a0d7a5e471/examples/polling.js#L78
Some further reading indicates : https://core.telegram.org/bots/api#callbackquery
This relates to this documentation here : https://core.telegram.org/bots/api#callbackquery
If the button was attached to a message sent via the bot (in inline mode), the field
inline_message_id
will be present.Exactly one of the fields
data
orgame_short_name
will be present.You are using inline keyboard, instead you can try reply keyboard markup which appears in the bottom of telegram screen as you said.
It is implemented easily and you can find some useful information about it here and here.
I’ve used
telegraf
library while working ontelegram-bot
, most of the libraries are same so you can consider it for reference.You will get
callback_data
as an input when user click on the button