Fix conversation with global middleware #32
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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