Branch at the beginning of a flow
There may be cases where we, depending on the input, want to give out different answers. For cases like this, it's important to know how to branch at the beginning of a flow. In this case we want edit previously created flow User asks about coffees we offer to recognize coffee types when mentioned by the user.
User: What kinds of coffees do you serve?
Bot: We offer a variety of handcrafted coffee drinks - from espressos to macchiatos to flat whites and more.User: Do you serve brewed coffee?
Bot: Yes, we do indeed serve brewed coffee in our stores!
Here you'll learn how to add a branch at the beginning of your flow and to specify different paths depending on what the user said:
- if the user asks about coffee types we serve,
- if the user asks if we serve a specific coffee type,
These are the steps you'll need to take:
- Extend the flow structure:
- Add a junction, and set it to be start-node
- Add one new output node.
- Link the junction to the output nodes
- Populate the output and transition for the coffee type response
The final version of the flow will look like this:
Create a new variable
As a first step we need to create a new flow variable that will store the coffee type the user mentions.
- Open or create the 'User asks about coffees we offer' flow.
- Inside the flow, click on the Variables icon underneath the minimap.
- Add a variable and name it
mentionedCoffee
. - Put
""
in the 'Evaluation Script' field. This initializes the variable with the empty string. - Click on 'Confirm'.
Add an After Match to the Intent Trigger
In order to store the coffee type we need to add an After Match to the Intent Trigger. This will take the coffee type from our previously created entity and store it inside the flow variable 'mentionedCoffee'.
- Click on the Plus icon under the trigger.
- Click on 'After Match' and select 'Entity'.
- Select
COFFEES_SERVED
by typing or pasting it in and selecting it from the dropdown. - Choose 'Add Variable Mapping'.
- The first dropdown represents the source, in this case the value of the NLU variable of the entity 'COFFEES_SERVED' that we want to store. Select 'coffeeType' from the dropdown menu.
- The second dropdown represents the target, i.e. the name of the variable where the extracted value is to be stored. Select 'mentionedCoffee' from the dropdown menu.
Extend the flow structure
Follow these steps to re-draw the structure of the flow:
- Add a junction by clicking on the Plus icon above the output node.
- Hover over 'with 'Split Path' and select 'transaction element', 'Output'.
Populate the new output and transition to recognize Coffee types
We will add a different route for when the user mentions its coffee type:
- Using the Plus icon, add a Match for 'Flow Variable' above the newly created output.
- From the dropdown, make sure 'mentionedCoffee' is selected.
- Navigate to the new output node and name it
We serve the coffee type!
. Add the following answer text:Yes, we do indeed serve ${mentionedCoffee}!
. - Hit 'Save'.
Try it out!
Now go ahead, open the 'Tryout' panel and give it a go!
User: What kinds of coffees do you serve?
Bot: We offer a variety of handcrafted coffee drinks - from espressos to macchiatos to flat whites and more.User: Do you serve brewed coffee?
Bot: Yes, we do indeed serve brewed coffee!