Teneo Developers

Hands-on

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:
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 flows's main window, move to the 'FLOW' tab, and select 'Variables'.
  2. Add a variable and name it mentionedCoffee.
  3. Put "" in the 'Evaluation Script' field. This initializes the variable with the empty string.

Add an After Match to the Intent Trigger

In order to store the coffee type we need to add a 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'.

  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 configuration panel, go to 'After Match', click 'Add', and click on 'Entity'.
  3. Paste in COFFEES_SERVED and hit 'Enter' on your keyboard.
  4. Click the 'Add Mapping' button.
  5. The 'Source' field denotes the value of the NLU variable of the entity 'COFFEES_SERVED' that we want to store. Select 'coffeeType' from the dropdown menu.
  6. The 'Target' field denotes 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:

  1. Add a junction by clicking on the Plus icon above the output node.
  2. Hover over 'Continue With' and select a 'Junction'.
  3. Select the Plus icon under the newly created Junction, followed up with 'Split Path' and 'Transaction'.

Populate the new output and transition to recognize Coffee types

We will add a different route for when the user mentions their 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. Add a Match for 'Flow Variable'.
  4. From the dropdown, make sure 'mentionedCoffee' is selected (it will be chosen by default).
  5. Make sure 'Get Input before continuing' is unselected.
  6. This transition should be tested first. You can change its order in the 'Triggering' panel: change it to 1. Notice how the output nodes change place once the ordering is changed.
  7. 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 in our stores!

Next page
Add a script to your flow
Was this page helpful?