Consider the following dialog tree
ask confirmation of pizza order
confirm order - Intent: positive (yes)
change order - Intent: negative (no)
second joke - Intent: positive (yes)
no more jokes - Intent: negative (no)
We have two separate conversation in this tree. The first one orders a pizza and ends in asking the user to confirm the order. The second conversation tells a user jokes and asks if he or she would like to hear another one.
When in the
ask confirmation of pizza order bot dialog, you want the user to be able to answer with something like yes, confirm or that looks good. On the other hand when you are in the
another joke? bot dialog, you also want the user to be able to answer with yeah sure or looks good or a similarly positive expression.
To achieve that behaviour, we need to reuse the Yes intent for both bot dialogs. However, we need to give the bot a hand in determining where the user wants to go by saying that intent at that point in the flow. In Chatlayer.ai, you can guide the bot using context.
Set the output context of the
ask confirmation of pizza order bot dialog to confirmingpizza. The default value of the lifespan will be 1, you can leave that for now.
Next, in the bot dialog
confirm order, specify that confirmingpizza needs to be the input context.
Similarly, you can specify the output context of the
another joke? bot dialog to joking and require joking as a required context for the bot dialog
Now, when the 'yes' intent is recognized, the bot will check which context is active. Depending on the context, a user will be routed to either the
confirm order bot dialog (confirmingpizza context was active) or to the
second joke bot dialog (joking context was active)
We can repeat this configuration for the 'no' intent. In the end, we would get a configuration like this
ask confirmation of pizza orde- Output context: confirmingpizza
confirm order - Required context: confirmingpizza, Intent: positive
change order - Required context: confirmingpizza, Intent: negative
another joke? - Output context: joking
second joke - Required context: joking, Intent: positive
no more jokes - Required context: joking, Intent: negative
Of course, we don't want the user to be limited to this context for the rest of the conversation. After saying yes to the initial question, every other yes expression can be an answer to a different question.
To configure this you can define the lifespan of the output context. Each time the user enters a dialog state with an output configured this context is added to his session with an initial lifespan value as defined in the bot dialog settings. For each user message the lifespan of a context is decreased by one. When the value is 0 the context is removed from the session.
All of this means that: a user is redirected to a dialog state when
The NLP model result has a top scoring intent with a value higher than the NLP intent recognition threshold value, and
This intent is linked to a bot dialog and the optional context linked to this bot dialog is available in the user session