Reputation: 28621
In Telegram bot you can send a message with the reply keyboard using the sendMessage method.
The keyboard is getting displayed instead of normal qwerty one.
We can remove the displayed keyboard by sending another message and by passing ReplyKeyboardRemove object with it. However, this requires some extraneous message to be sent.
Is it possible to remove the keyboard without actually sending any real message?
I'm aware of one_time_keyboard
option, but it will only hide the keyboard without removing it.
Upvotes: 11
Views: 35006
Reputation: 5425
As Andrew Savinykh pointed out, there are no way to edit the message which has a markup other than inline_keyboard
or nothing (official docs: https://core.telegram.org/bots/api#updating-messages):
Please note, that it is currently only possible to edit messages without reply_markup or with inline keyboards.
The possible kludge is to send a message which clears the keyboard, and than delete it immediately.
Aiogram helper:
async def remove_chat_buttons(chat_id: int,
msg_text: str = r"_It is not the message you are looking for\.\.\._"):
"""Deletes buttons below the chat.
For now there are no way to delete kbd other than inline one, check
https://core.telegram.org/bots/api#updating-messages.
"""
msg = await bot.send_message(chat_id,
msg_text,
reply_markup=aiogram.types.ReplyKeyboardRemove(),
parse_mode="MarkdownV2")
await msg.delete()
It is not the answer we want, but for now I never noticed this dummy message - it disappear instantly.
Upvotes: 8
Reputation: 2987
When you create a keyboard, you use a sendMessage
. Save the message_id
from response. And, then, to remove the keyboard, delete the message by calling deleteMessage(message_id)
Upvotes: -1
Reputation: 1506
I was using node-telegram-bot-api and I was able to do it using remove_keyboard
.
There is a way to do this in all the languages.
return bot.sendMessage(chatId, data, {
parse_mode: 'HTML',
reply_markup: { remove_keyboard: true },
});
Upvotes: 4
Reputation: 5038
You could edit the message using editMessageText or editMessageReplyMarkup and simply not pass a reply_markup
to make it disappear.
Upvotes: 8