Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telegram bot: How do I send message with inline keyboard and hide custom keyboard simultaneously?

Tags:

telegram-bot

  • Step 1: Send user a message with ReplyKeyboardMarkup with few buttons (for example ["Yes", "No"])
  • Step 2: If user click one of the buttons (for example "Yes") I want to display a message with inline keyboard and hide the buttons sent at step 1.

Is it possible to do? The message has just single reply_markup property and can be either InlinkeKeyboardMarkup or ReplyKeyboardHide. The only way to do that I see is to send 2 messages (first to hide keyboard and 2nd with inline keyboard) but that would not be best solution from user experience point of view. I'm OK to do couple of request but want to have just 1 message visible to user.

Any thoughts?

like image 463
Alexander Trakhimenok Avatar asked Jun 16 '16 11:06

Alexander Trakhimenok


People also ask

What is inline keyboard in Telegram bot?

Inline keyboards are available for messages sent both in chat mode and inline mode. Unlike with custom reply keyboards, pressing buttons on inline keyboards doesn't result in messages sent to the chat.

How can I send a message to someone with my telegram bot using their username?

Getting StartedOpen the telegram app and search for @BotFather. Click on the start button or send “/start”. Then send “/newbot” message to set up a name and a username. After setting name and username BotFather will give you an API token which is your bot token.

Can I send message by bot in telegram?

In order to send a message to "@Username", you will need them to start your bot, and then store the username with the user_id. Then, you can input the username to find the correct user_id each time you want to send them a message.

Can Telegram bots send private?

On Telegram, you can send messages in private chats and groups without making your phone number visible.


2 Answers

There isn't any logical solution. but there's a trick. you can send a message to remove the previous keyboard, then remove this message, finally send the next message with it's keyboard.

// send a fake message
Message sentMsg = bot.SendTextMessageAsync(chatID, ".", replyKeyboardMarkup: new ReplyKeyboardRemove()).Result;

// remove the fake message
bot.DeleteMessageAsync(chatID, sentMsg.MessageId);

// send the main message with it's keyboard
bot.SendTextMessageAsync(chatID, "the next message", replyKeyboardMarkup: new ReplyKeyboardMarkup(keyboardData));
like image 93
Emad Armoun Avatar answered Sep 21 '22 12:09

Emad Armoun


It's impossible right now. Telegram Bot API currently allows sending only one type of keyboard: inline or simple (including KeyboardHide and other).

like image 30
ihoru Avatar answered Sep 21 '22 12:09

ihoru