Supporting milk alternatives when ordering coffee

Challenge

Now that we have an entity for milk alternatives, we can extend the User wants to order a coffee flow to take the milk alternatives into account and allow conversations like this:

User: I would like to order a medium flat white with soy milk
Bot: Ok, a medium flat white with soy milk will be ready for pickup in 5 minutes.

But if the user doesn't mention an alternative milk type, we'll asume a regular milk will suffice:

User: Can I order a large flat white
Bot: Ok, a large flat white will be ready for pickup in 5 minutes.

Would you know how to proceed?

Solution

We will want the 'User wants to order a coffee' flow to pick up a milk alternative when it is mentioned, but not explicitly ask the user for it when it wasn't mentioned. This is a way of keeping the coffee ordering process as seamless as possible, without asking for information that may not be relevant for the majority of users. To achieve this we will make the following changes to the flow:

  • Add a flow variable to store the milk alternative
  • Add a listener to the flow that listens for milk alternative
  • Update the output to include the milk alternative when it is mentioned.

Add a flow variable to store the milk alternative

  1. Open the 'User wants to order a coffee' flow in edit mode.
  2. Go the flow variables and add a variable called orderedMilkAlternative. Give it a default value of "".

Add a listener for milk alternatives

  1. Go to the listeners and add a listener called Pick up milk alternative.
  2. Give the listener the following condition:
    %LONGBERRY_MILK_ALTERNATIVES.ENTITY^{orderedMilkAlternative = lob.description}
  3. Click OK to add the listener.

Update the output to include the milk alternative

  1. Go the flow diagram and select the final output node.
  2. Replace the answer with the following: Ok, a ${orderedCoffeeSize} ${orderedCoffeeType}${orderedMilkAlternative ?: " with " + orderedMilkAlternative} will be ready for pickup in 5 minutes. If orderedMilkAlternative has a value it will insert with [alternative] into the output.

That's it! You can now save the flow and test it in Tryout.

Was this page helpful?