How to hide ReplyKeyboardMarkup after user clicked in Telegram Bot API

I am using Node.js telegram-bot-api .

Idea:

  • Show the user keyboard with one button - "Share your phone number."
  • When the user clicks this button, the contact must be sent, and the button must be removed from the screen.

Here is the code I'm 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 the user clicks the "Share your phone number" button, he shares his contact, but the button is visible even after that.
  • When I do not use the request_contact flag, one_time_keyboard works correctly (hides the button after using it), but even then it just hides the button, so the user can click the icon to return it to the screen, which is not very good.

Please tell me if I am doing something wrong. Thanks

+6
source share
2 answers

Found.

Here is the solution:

 bot.sendMessage({ chat_id: message.chat.id, text: 'Some text...', reply_markup: JSON.stringify({ hide_keyboard: true }) }); 
+9
source

You must use editMessageReplyMarkup and update this replyMarkup message replyMarkup null string ( '' ) after the click user has access.

UPDATE , this applies to built-in keyboards.

0
source

All Articles