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 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

Final version of the flow will look like this:
final flow

Open the flow in edit mode

First, you should open or create the 'User asks about coffees we offer' flow in edit mode:

  1. Select the flow 'User asks about coffees we offer' located inside the 'Flows' folder.
  2. Click 'Edit' in the ribbon. The flow will open in a new window.

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.

  1. In the solution's main window, move to the 'FLOW' tab located at the top left corner, and select 'Variables' in the purple navigation bar on the left-hand side.
  2. Add a variable and name it mentionedCoffee.
  3. Put "" in the 'Evaluation Script' field. This initializes the variable with the empty string.

Add a Data Action to the Trigger

In order to store the coffee type we need to add a data action to the trigger. This will take the coffee type from our previously created entity and store it inside the flow variable 'mentionedCoffee'.

  1. Go back to the flow editor page and select the trigger this will open the trigger configuration panel to the right.
  2. In the panel on the right, go to 'Data Actions', click 'Add', and hover over 'Entity' from the drop-down menu. Paste in COFFEES_SERVED.
  3. Now click into the 'Entity' field, which will make the 'Add Mapping' button clickable. Click the 'Add Mapping' button.
  4. The 'Source' field denotes the value of the NLU variable of the entity 'COFFEES_SERVED' that we want to store. In our case 'coffeeType'.
  5. The 'Target' field denotes the name of the variable where the extracted value is to be stored. In our case 'mentionedCoffee'.

Extend the flow structure

Follow these steps to re-draw the structure of the flow:

  1. Add a junction by clicking 'Junction' in the top ribbon's 'Add Node' section. Make sure nothing in your flow is selected before doing so, or the new junction will be connected to the selected item.
  2. Keep the new junction selected and click 'Set Start Node' in the ribbon's 'Flow Entry' section. The graph will be re-drawn so that the junction comes straight after the trigger.
  3. Connect the junction and the output node 'We offer a variety of handcrafted coffee drinks...' as follows: Click on the junction, and then drag the cursor to the center of the output node. If you want to cancel the transition while drawing, click Esc.
  4. Select the junction and click on 'Output' in the ribbon's 'Add Node' section. This will add a new output connected to the junction.

Populate the new output and transition to recognize Coffee types

We will add a different route for when the user mentions its coffee type:

  1. Select the new output node, name it: We serve the coffee type! and add the following answer text: Yes, we do indeed serve ${mentionedCoffee}.
  2. Now we need to make sure this answer is only given when the user is asking for coffee types we serve. Select the transition and name it Coffee type mentioned and served
  3. Set the toggle from 'unconditional' to 'conditional', and add a match requirement for 'Context'.
  4. From the dropdown, choose the global context 'Flow Variable'. Make sure 'mentionedCoffee' is selected (it will be chosen by default).
  5. This transition should be tested first. You can change its order at the bottom of the 'Triggering' panel: change it to 1. Notice how the output nodes change place once the ordering is changed.
  6. Hit 'Save'.

Try it out!

Now go ahead, open the 'Try out' 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 serve brewed coffee in our stores!

Where to go next?

Next is a page about adding a script to your flow.

Was this page helpful?