Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to stay on the same step of ReplyFlow #1348

Open
rubenlagus opened this issue Apr 7, 2024 Discussed in #990 · 0 comments
Open

How to stay on the same step of ReplyFlow #1348

rubenlagus opened this issue Apr 7, 2024 Discussed in #990 · 0 comments
Labels

Comments

@rubenlagus
Copy link
Owner

Discussed in #990

Originally posted by DUrayev November 3, 2021
Hello everyone!
Suppose I want to make kind of infinity loop of my reply until some condition is not met. For example, I'm asking user for a password in the action of my ReplyFlow. I want the same ReplyFlow to continue processing the next reply if password is incorrect.
The best option would be to add "self" reference in ".next()" method of ReplyFlow builder, but it's not possible.

Could you suggest any workaround?

Consider the following example of my request password flow:

private ReplyFlow passwordEnteredFlow() {
        return ReplyFlow.builder(db())
                .onlyIf(Flag.MESSAGE)
                .action((bot, upd) -> {
                    String password = upd.getMessage().getText();
                    SomeExternalService service = SomeExternalService.getInstance();
                    service.login(password, response -> {
                        if (response.isError()) {
                            silent().send("Incorrect password. Try again:", getChatId(upd));
                        } else {
                            sender().execute(SendMessage.builder()
                                    .text("You're successfully logged in. Select the following action:")
                                    .chatId(getChatId(upd).toString())
                                    .replyMarkup(KeyboardFactory.withOneLineButtons("Option 1", "Option 2")
                                    .build());
                        }
                    });
                })
                .next(getSuccessLoginFlow())
                .build();
    }

Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant