How to hide ReplyKeyboardMarkup after user click in Telegram Bot API
28,154
Solution 1
Found it.
Here is a solution:
bot.sendMessage({
chat_id: message.chat.id,
text: 'Some text...',
reply_markup: JSON.stringify({
hide_keyboard: true
})
});
Solution 2
hide_keyboard
has been renamed to remove_keyboard
since API 2.3.
bot.sendMessage({
chat_id: message.chat.id,
text: 'Some text...',
reply_markup: JSON.stringify({
remove_keyboard: true
})
});
Author by
Nazar
Senior JavaScript Developer with 6+ years of experience. Client side: Backbone.js Marionette Require.js jQuery WebSockets Jasmine Server side: Node.js (Express, Sails.js) MySQL, Oracle, MongoDB, Redis Mocha Other: Issue tracking: JIRA, Redmine VCS: GIT (Bitbucket, Stash, Github, Gitlab), SVN CI: Bamboo Documentation: Confluence, Github/Redmine Wiki oDesk: https://www.odesk.com/users/~01ce18fdbd206767ae GitHub: https://github.com/leestex LinkedIn: http://ua.linkedin.com/in/nazarkuzmenko
Updated on July 27, 2020Comments
-
Nazar almost 4 years
I am using Node.js telegram-bot-api.
Idea:
- Show a custom keyboard with one button - "Share my phone number".
- When user clicks this button, contact should be sent and button should be removed from screen.
Here is a code I am using right now:
bot.sendMessage({ text: 'Please give us your phone number', reply_markup: JSON.stringify({ keyboard: [ [{ text: 'Share my phone number', request_contact: true }] ], resize_keyboard: true, one_time_keyboard: true }) });
Problems:
- When user clicks "Share my phone number" button, it shares his contact but button is visible even after that.
- When I am not using
request_contact
flag,one_time_keyboard
works correctly (hides the button after its usage), but even in that case it just hides the button, so user can click an icon to bring it back to screen, which is not good at all.
Please tell me if I am doing something wrong here. Thanks
-
Nazar almost 8 yearshere is what I am getting now:
{ ok: false, error_code: 400, description: 'Bad Request: Message can\'t be edited' }
-
Seyfi almost 8 yearsyou should provide message id too. Last Message Id that you have sent and have contained the keyboard markup
-
Saman Mohamadi almost 6 yearshide_keyboard has been renamed to remove_keyboard since API 2.3.
-
Peter over 2 yearsNotice it seems not to work if you send and empty message or even only 1 space.