The user enters the / setzavtra command, the bot sends a message with an example of how to enter data and waits for the next message, receiving records in a variable. The question is how to get a new message? I saw the getUpdates method in the api documentation, but firstly I don’t know if I need it, and secondly I just can’t call it.

public void onUpdateReceived(Update update) { Tomorrow lessons = new Tomorrow(); Message message = update.getMessage(); if(message != null && message.hasText()) { switch(message.getText()) { case "/setzavtra": sendMsg(message, "Введите информацию в следующем виде: "+"\n"+lessons.Example());//через метод класса показываю как должен выглядеть ввод //хочу считать текст следующего сообщения, но не знаю как break; default: sendMsg(message, "Я - бот"); break; } } } 
  • I tried to get a new message in this way: Message newmess = update.getMessage (); But, as expected, I also received a message. / setzavtra. - masyanolchik

2 answers 2

The onUpdateReceived(Update update) method handles all incoming messages (updates), not distinguishing whether it was “next” or something else. Their selection must be done within the method. For example, through the Map <текст входящего обновления, ответ> . If the update text matches any key, a specific answer is given, otherwise it is suggested to enter a request in the required format. Or put the logic of the answers in a separate class,

 public void onUpdateReceived(Update update) { try { sendMessage(message, messageFactory.createMessage(update)); } catch (TelegramApiException e) { //обработать исключение, например записать в лог } } 

in which any information can be stored, including previous records of conversations with any user. Analyze the correspondence and give the appropriate answer without touching the methods of the bot itself.

    The sendMessage() function is currently obsolete. It was replaced by execute() . This is the question of where this is already discussed.
    Further it is written:

     public void onUpdateReceived(Update update) { Message message = update.getMessage(); try { sendMsg(message, "Чем я могу помочь?");); } catch (TelegramApiException e) { System.out.println(e); } public void sendMsg(Message message, String s) throws TelegramApiException { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); sendMessage.setChatId(message.getChatId().toString()); sendMessage.setReplyToMessageId(message.getMessageId()); sendMessage.setText(s); execute(sendMessage); }