Z
Z
Zestr2020-10-09 08:21:43
Java
Zestr, 2020-10-09 08:21:43

How to handle the second response without exiting the loop?

Hello. I decided to write my own bot, but ran into a problem. Here is a piece of code

public void onUpdateReceived(Update update)
    if (message != null && message.hasText()) {
                    switch (message.getText()) {
                        case "/start":
    sendMsg(message, "Hi!");
                            System.out.println(message.getText());
                            break;
    case "partial":
                            sendMsg(message, "starting \ninput number");
                            while(true){
                           
                            if(update.getCallbackQuery().getMessage().getText().equals(g)) {
                                
                                sendMsg(message,"ok, go");
                                try {
                                    Scraper.scrape(partial);
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            break;}}
                            System.out.println(message.getText());
                            break;


The problem is that when I just start talking to the bot and write the first message to it, let's say partial, but I want to set up the logic for the second response, let's say this is a project, and then the bot should ask me - "ok, what version are we running ", and when I answer the second question, he again starts to go through the switch and compare cases, how to set up several levels of communication?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2020-10-09
@sergey-gornostaev

Use a state machine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question