Remove custom keyboard after contact sharing in Telegram bot

I’m working with a Telegram bot using Node.js and need help with keyboard management.

What I want to achieve:

  1. Display a custom keyboard with a contact sharing button
  2. Hide the keyboard completely after the user shares their contact

Current implementation:

telegramBot.sendMessage({
    text: 'We need your contact information',
    reply_markup: JSON.stringify({
        keyboard: [[
            {
                text: 'Send Contact Details',
                request_contact: true
            }
        ]],
        resize_keyboard: true,
        one_time_keyboard: true
    })
});

Issues I’m facing:

  • The keyboard stays visible after contact is shared, even with one_time_keyboard: true
  • Without request_contact, the one_time_keyboard works but users can still access the hidden keyboard through the menu icon

Any suggestions on how to properly remove the keyboard after contact sharing?

use remove_keyboard: true in ur msg after u get the contact. try bot.sendMessage(chatId, 'thanks for sharing!', {reply_markup: {remove_keyboard: true}}) - that shld work. one_time_keyboard doesn’t really work well with contact requests.

Had this exact issue building a customer onboarding bot. request_contact buttons work differently than regular keyboard buttons in Telegram’s API. Here’s what fixed it for me: set up a proper event listener for contact messages, then immediately respond with keyboard removal. In your contact handler, add bot.on('contact', (msg) => { bot.sendMessage(msg.chat.id, 'Contact received successfully', {reply_markup: {remove_keyboard: true}}); }); This removes the keyboard right after they share contact info. You’ve got to handle the contact event separately from regular text messages or the keyboard won’t go away.

Yeah, this is normal Telegram behavior. The one_time_keyboard parameter doesn’t work with contact requests - they’re handled differently than regular button presses. I hit this same issue last year building a registration bot. Here’s what fixed it: explicitly remove the keyboard in your contact handler. When you get the contact message, immediately send a follow-up with reply_markup: {remove_keyboard: true}. So after receiving the contact event, just send a confirmation message with the remove_keyboard flag. This’ll make the keyboard disappear completely so users can’t bring it back through the keyboard icon. Just make sure you’re listening for the contact event specifically, not regular messages.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.