-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get the response of the keyboard selection? #108
Comments
+1 var option = {
"parse_mode": "Markdown",
"reply_markup": {
"ReplyKeyboardMarkup": {
"keyboard": [
['Yes'],
['No']
]
}
}
};
bot.sendMessage(msg.chat.id, "*Some* message here.", option); Markdown works, so the 'option' object is being used. The keyboard still doesn't show. Take a look at https://core.telegram.org/bots/api#sendmessage and https://core.telegram.org/bots/api#replykeyboardmarkup |
The Telegram documentation is kind of vague, but Try this: var options = {
"parse_mode": "Markdown",
"reply_markup": {
"keyboard": [
[{ text: "Yes" }],
[{ text: "No" }]
]
}
}; If this doesn't work, try JSON.stringifying the var options = {
"parse_mode": "Markdown",
"reply_markup": JSON.stringify({
"keyboard": [
[{ text: "Yes" }],
[{ text: "No" }]
]
})
}; |
Actually, I got it working. Yay. var option = {
"parse_mode": "Markdown",
"reply_markup": { "keyboard": [["Yes"],["No"]] }
};
bot.sendMessage(msg.chat.id, "*Some* message here.", option); |
@sgkhode You can close the issue if it anything above works for you. Cheers! |
Well you've just discussed how to send the keyboard if I'm not mistaken, the original question was how to read the response from that keyboard. I would also like to see an example of how this is done. |
@jackdh Sorry about that, didn't read the question properly :P I got this working: bot.onText(/^\/selectseries/, function(msg, match) {
var seriesKB = []; // The keyboard array
bot.sendMessage(msg.chat.id, "Select a serie", {
"reply_markup": {
"keyboard": seriesKB,
"one_time_keyboard": true
}
});
bot.onText(/.+/g, function(msg, match) {
bot.sendMessage(msg.chat.id, "You selected " + match);
var selectedSerie = msg.query;
});
}); |
@rithvikvibhu Won't your |
Tested it and it seems so @ThiRaBrTNK onText(regexp, callback) {
this.textRegexpCallbacks.push({ regexp, callback });
} I'm not on my laptop right now, but someone could meddle with this and insert a line with |
@rithvikvibhu Tested .textRegexpCallbacks.pop(); and it works perfectly! |
@rithvikvibhu Thanks for your reply, but I'm afraid |
@raphaklaus How are you implementing your multi user bot? It might be possible to tag users and remove their |
Yes, I've made it changing the |
@raphaklaus I'm actually curious on how you are storing users. Is it linked to a database/file or just in variables? Could you post a snippet of your _processUpdate or anything else you've changed? Also the part where the onText is removed |
Take a look: In this line, I create a new method called Since all regex callbacks are processed specific for each user (https://gist.github.com/raphaklaus/f1b1d1d2f95a066c9e4af65b9bb1c24d#file-process-update-L27), you can remove them or not, it'll not mess things up. |
Please note that the Otherwise, the main concern in this thread would be how to hold a conversation with your bot user. There are better ways to do so in your application code, other than solely relying on As my final note, please be aware that this library is mostly focused on providing a wrapper around the Telegram Bot API, and more complex patterns, such as the one discussed above, are better implemented in your application code, or in a higher-level library! |
@GochoMugo, thanks for your concerns, but I think this issue come into this way due lack of author's support in the past. I'm glad that something is being done. Looking forward to see this Telegram Bot Forms. :) |
Well I cant believe this library allows for showing a custom keyboard but not for the reply to be read! How am I supposed to create a multi user 3 step questionnaire if I cant read the users selection?? |
@ShashankaNataraj, I managed to overcome this situation by creating an |
@ShashankaNataraj You have to implement it! This library is thin! It will NOT do everything for you! Again, that should be left for a higher-level library!!! PS: More contribution to this open-source project will help lessen work for everyone! Also, we are doing some work over at tgfancy. |
@raphaklaus @GochoMugo Got you! I implemented a set of regex's to capture button output message and respond to them with another keyboard thus implementing my questionnaire! I now have a set of 5 questions which I ask the user and then get the responses to each one and store them in memory (as of now). Only question I have now is how to dismiss the custom keyboard and allow the user to input his email address for the last question in the questionnaire! EDIT: I got my answer by going through the telegram docs: "one_time_keyboard": true will dismiss the keyboard as soon as it has been used. Im using this on the final questionnaire. My thanks to @GochoMugo on |
@ShashankaNataraj You can also just send {
"reply_markup": {
"remove_keyboard": true
}
} |
How to receive the event of it, like suppose it sent a keyboard, I selected one of the items and it sent that text to the chat from my side, what's the event catcher for this? Like bot.on('???') Edit 1: My bad, looking at the code again, it seems like there's no such event for it except the good ol message and text |
I want to use keyboard to get the selected option. How to get the selected option ? Any example?
The text was updated successfully, but these errors were encountered: