How to remove (not to hide) ReplyKeyboardMarkup in Telegram.Bot using C#?
Asked Answered
U

6

9

I'm using Telegram.Bot library in C# for developing telegram bots.

I post a text message using SendTextMessageAsync() method and sent a Keyboard with it :

bot.SendTextMessageAsync(chatId, "sample msg", ParseMode.Default, false, false, 0, new InlineKeyboardMarkup(keyboardData));

I want to remove (not to hide) the keyboard, after click of any user on one of the keyboard buttons, so I use this instruction :

int msgId = bot.SendTextMessageAsync(chatId, "sample msg", ParseMode.Default, false, false, 0, new InlineKeyboardMarkup(keyboardData)).Result;
...
bot.EditMessageReplyMarkupAsync(chatId, msgId, new ReplyKeyboardRemove());

But it doesn't work. Please help me about it.

Meanwhile if I set oneTimeKeyboard to true in ReplyKeyboardMarkup, the keyboard will be hide after user click, but it doesn't removed, only it will be hide and user can make it visible using keyboard button of telegram.

Unifilar answered 1/9, 2017 at 7:13 Comment(0)
K
5

You can use ReplyKeyboardRemove method to do that.

Kobi answered 1/9, 2017 at 9:10 Comment(2)
It's not a method. it's a class that is used in EditMessageReplyMarkupAsync() method or SendTextMessageAsync(). if I use it in 1st method, it doesn't work and if I use it in the 2nd method, there will be an extra message.Unifilar
Please open issue in your libraryKobi
I
5

I'm afraid, it's too late, but you can use ReplyKeyboardRemove

var send = new SendMessage(update.Message.Chat.Id, "your_text")
{
    ReplyMarkup = new ReplyKeyboardRemove() { RemoveKeyboard = true }
};
await bot.MakeRequestAsync(send);
Idocrase answered 16/11, 2017 at 20:17 Comment(0)
C
1

For Python users, according to Sean`s comment (telegram documentation):

    import telebot
    bot = telebot.TeleBot('YOUR TELEGRAM API CODE HERE')
    bot.send_message(message.chat.id, text="YOUR MESSAGE HERE", reply_markup=telebot.types.ReplyKeyboardRemove())
Ctesiphon answered 23/3, 2022 at 12:38 Comment(3)
The question was about C#...Banderilla
Yes, that`s why I started the answer with "For Python users"!Ctesiphon
But this doesn't answer the question...Banderilla
S
0

Maybe this will help someone.

new TelegramBotClient("<token>").SendTextMessageAsync(chat_id, text, replyMarkup: new ReplyKeyboardRemove());
Synonymize answered 15/6, 2018 at 10:37 Comment(0)
S
0

It works for me :

public async Task RemoveRequestContactButton(string chatId, string text)
        {
            var tgBot = GetClient();
            await tgBot.SendTextMessageAsync(chatId, text, replyMarkup: new ReplyKeyboardRemove()).ConfigureAwait(false);
        }

where function GetClient() returns TelegramBotClient;

Scrophulariaceous answered 22/10, 2021 at 7:29 Comment(0)
S
0
await _bot.SendTextMessageAsync(chatId, "Your text", replyMarkup: new ReplyKeyboardRemove() { Selective = true });
Slave answered 2/2, 2024 at 16:45 Comment(1)
Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. Would you kindly edit your answer to include additional details for the benefit of the community?Berneta

© 2022 - 2025 — McMap. All rights reserved.