Nodejs Telegram Bot: Removing Persistent Custom Keyboard

I'm having a weird problem with my Nodejs Telegram bot. I used to have a custom keyboard that wasn't an inline one. I switched to inline keyboards, but the old keyboard keeps showing up for users when they open the chat.

Here's what my current code looks like:

const keyboardOptions = {
  parse_mode: 'Markdown',
  disable_web_page_preview: true,
  reply_markup: JSON.stringify({
    inline_keyboard: [
      [
        { text: '🇬🇧 English', callback_data: 'LANG_EN' },
        { text: '🇪🇸 Español', callback_data: 'LANG_ES' }
      ]
    ]
  })
};

chatBot.sendMessage(chatId, 'Select your preferred language', keyboardOptions);

The inline keyboard works fine, but that old custom keyboard is still there. It's super annoying for my users. I've looked into ReplyKeyboardRemove and editMessageReplyMarkup, but I'm not sure how to use them to get rid of this pesky keyboard.

Any ideas on how to fix this? Thanks for the help!

I had a similar experience with persistent keyboards and found that the issue often comes from the client side storing the old keyboard layout. Instead of just switching to an inline keyboard, I needed to explicitly signal Telegram to remove the previous custom keyboard. What helped me was creating a removal object where the property remove_keyboard is set to true. I then sent this in a message before sending the new inline keyboard. This method forces Telegram to clear the old keyboard. Sometimes, it may take a moment for the changes to appear, or in rare cases, a client restart might be necessary.

yo, i ran into this too. super annoying right? try this:

bot.sendMessage(chatId, ‘clearing keyboard…’, {
reply_markup: {
remove_keyboard: true
}
});

wait a sec, then send ur new inline keyboard. should do the trick. if not, tell users to restart telegram app

I’ve encountered this issue before, and it can be quite frustrating. The problem likely stems from the custom keyboard being stored client-side. To resolve this, you need to explicitly tell Telegram to remove the old keyboard before introducing the new inline one.

Try adding this code before sending your new inline keyboard:

const removeKeyboard = {
reply_markup: JSON.stringify({
remove_keyboard: true
})
};

chatBot.sendMessage(chatId, ‘Removing old keyboard…’, removeKeyboard);

This should clear the persistent keyboard. After a short delay, send your new message with the inline keyboard. If users still see the old keyboard, they might need to restart their Telegram client. It’s a rare occurrence, but it can happen due to caching on the client side.