Hey everyone! I’m stuck with a weird problem in my Nodejs Telegram bot. I used to have a custom keyboard, but I switched to an inline keyboard. The old keyboard keeps showing up for users even though I deleted the code. It’s super annoying!
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: 'LANGUAGE_EN' },
{ text: '🇪🇸 Español', callback_data: 'LANGUAGE_ES' }
]
]
})
};
myBot.sendMessage(chatId, 'Pick your language', keyboardOptions);
The inline keyboard works fine, but that old custom keyboard keeps popping up when users open the chat. I’ve looked at the Telegram Bot API docs and some Stack Overflow posts about removing keyboards, but I can’t figure out how to get rid of this ghost keyboard.
Any ideas on how to banish this pesky keyboard for good? Thanks for any help you can give!
I’ve dealt with this issue in my Telegram bots before. The problem is that custom keyboards persist until explicitly removed. To fix it, you need to send a message with the ‘remove_keyboard’ parameter set to true. Here’s a quick solution:
const removeKeyboardOptions = {
reply_markup: JSON.stringify({
remove_keyboard: true
})
};
myBot.sendMessage(chatId, ‘Updating keyboard…’, removeKeyboardOptions);
// Wait a moment before sending the new keyboard
setTimeout(() => {
myBot.sendMessage(chatId, ‘Pick your language’, keyboardOptions);
}, 100);
This should clear the old keyboard for all users. You might want to do this when users start the bot or enter a specific command. Remember, it may take a second for the change to appear on the user’s device.
I’ve encountered a similar issue before, and it can be quite frustrating. The problem is likely that the custom keyboard is persisting on the client side, even after you’ve removed it from your code.
To resolve this, you need to explicitly remove the custom keyboard. You can do this by sending a message with a ReplyKeyboardRemove option. Here’s how you can modify your code:
const removeKeyboard = {
reply_markup: JSON.stringify({
remove_keyboard: true
})
};
myBot.sendMessage(chatId, 'Removing old keyboard...', removeKeyboard);
// Then send your new message with the inline keyboard
myBot.sendMessage(chatId, 'Pick your language', keyboardOptions);
This should clear the old custom keyboard before displaying your new inline keyboard. Make sure to do this for all users who might have the old keyboard still showing. It might take a moment for the change to reflect on the user’s device, so be patient. Hope this helps solve your ghost keyboard problem!
oh man, i feel ur pain! had the same issue b4. try this:
bot.sendMessage(chatId, ‘Bye old keyboard!’, {
reply_markup: {
remove_keyboard: true
}
});
then send ur new inline keyboard. should kick that pesky old one to the curb! lmk if it works