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

Fix conversation with global middleware #32

Merged
merged 4 commits into from
Jan 18, 2021
Merged

Fix conversation with global middleware #32

merged 4 commits into from
Jan 18, 2021

Conversation

sergix44
Copy link
Collaborator

At first glance this may seem unnecessary given the last pr, but explained with an example it is simpler:
I would like for example to have a global middleware that takes from the database the user by telegram_id and puts it in the context, and if it is not there in the database, it asks him a question that he has to answer (so opening a mini conversation with nextStep(...)) and then saves it to database.
This is not possible anymore, since now all global middleware is always applied to all conversation handlers, and basically you enter the loop where the bot asks you always the same question, because the middleware is called before the conversation handler. You can avoid this by not using global middleware, but that means having to apply it to every listener by hand (with ->middleware(...)), which makes the code redundant and defeats the benefit of global middleware.

In this pr is what I came up with to make middlewares optional for certain conversation flows.

It also add some _ in the cache keys because now are kinda hard to read when debugging

@cheeghi
Copy link
Collaborator

cheeghi commented Jan 18, 2021

Ok, very edge case 😅 but can happen. I made ttl configurable

@cheeghi cheeghi merged commit 25e30e3 into badfarm:develop Jan 18, 2021
@sergix44 sergix44 deleted the fix-conversation-with-middleware branch January 25, 2021 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants