feat: Add FluentDialog as a flexible alternative to WaterFallDialog #4864
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.
fixes #4866
Description
The pull request introduces the
FluentDialog
class, which uses event sourcing to handle complex user interactions in bot applications. This approach allows for an uninterrupted execution flow similar to a durable function.High-level design
The design leverages JScript's generator functions to separate the conversation flow from the underlying state management.
Behind the scenes, the
yield
operator in the dialog flow function yields control of the execution thread back to a dialog flow dispatcher. The dispatcher then commits new actions scheduled by the dialog flow (such as starting a child dialog, receiving an activity, or making an async call) to storage. This commit action updates the dialog flow's execution history by appending new events into the dialog state, like an append-only log. When the dialog is later resumed, the dispatcher re-executes the entire function to rebuild the local state. During this replay, if the code tries to begin a child dialog or perform async work, the dispatcher consults the execution history, replays that result, and the function continues to run until it finishes or yields a new suspension task.Specific Changes
FluentDialog
, related interfaces, and their implementation classes.Basic Usage
Testing
Unit tests included
Developer Experience
FluentDialog
provides a straightforward way to define complex conversation flows using a generator function, making the implementation more intuitive.