0

I have a bot with inline keyboards. The bot has a text with a button to make an order. After pressing the bot asks the name of the person and below there is a button to cancel the operation. If I enter the name of the person, I rightly load the new text with the new buttons, but the old cancel button is not deleted and remains visible. I would like to be able to remove the button after writing the text.

this code is for insert the name:

String answer = "Insert the Name";

                EditMessageText new_message = new EditMessageText()
                        .setChatId(chat_id)
                        .setMessageId(message_id)
                        .setText(answer).setParseMode("HTML");

                markupInline = new InlineKeyboardMarkup();
                List<List<InlineKeyboardButton>> bottoni_totali = new ArrayList<>();
                List<InlineKeyboardButton> riga1 = new ArrayList<>();

                riga1.add(createButton("annulla", emoji_annulla+" Annulla"));

                bottoni_totali.add(riga1);

                // Add it to the message
                markupInline.setKeyboard(bottoni_totali);

                new_message.setReplyMarkup(markupInline);

                try {
                    execute(new_message); 
                } catch (TelegramApiException e) {
                    e.printStackTrace();
                }

When I insert the name, I show the surname but the old button CANCEL is visible.

String answer = "Now insert the surname";

                sendMessage = new SendMessage().setChatId(update.getMessage().getChatId());
                sendMessage.setText(answer).setParseMode("HTML");

                markupInline = new InlineKeyboardMarkup();
                List<List<InlineKeyboardButton>> bottoni_totali = new ArrayList<>();
                List<InlineKeyboardButton> riga1 = new ArrayList<>();

                riga1.add(createButton("annulla", emoji_annulla+" Annulla"));

                bottoni_totali.add(riga1);

                // Add it to the message
                markupInline.setKeyboard(bottoni_totali);
                sendMessage.setReplyMarkup(markupInline);
                try {
                    execute(sendMessage);
                } catch (TelegramApiException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
Luca
  • 23
  • 4
  • Possible duplicate of [How to hide ReplyKeyboardMarkup after user click in Telegram Bot API](https://stackoverflow.com/questions/38696771/how-to-hide-replykeyboardmarkup-after-user-click-in-telegram-bot-api) – M. Prokhorov Feb 12 '18 at 12:04
  • While the message which I have linked refers to API in other language, it should still have enough information to identify an adequate answer. – M. Prokhorov Feb 12 '18 at 12:05
  • When I tried to edit at first time - EditMessage (with InlineKeyboardMarkup) method working fine, but when I trying to modify this message at second time I got "Bad Request: message is not modified" Why??? – Luca Feb 17 '18 at 14:10

1 Answers1

0

Firstly I would say about this link: How to hide ReplyKeyboardMarkup after user click in Telegram Bot API

Question above is about InlineKeyboardMarkup and question by link is about ReplyKeyboardMarkup. These two are different things, don't mix them.

Secondly, you have to clarify your question.

but the old cancel button is not deleted and remains visible

What do you mean by that? (screenshots is the best way to explain)

In second snippet of code you use SendMessage instead of EditMessageText (as in first snippet). It means that message with text Now insert the surname will not replace message with text Insert the Name. Now insert the surname will appear as new message.

Seems like you should use EditMessageText in second case too.