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 conversations in this tree. The first one orders a pizza and ends by asking the user to confirm the order. The second conversation tells our user a joke and asks if they 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 make that happen, we need to reuse the 'Yes' intent for both bot dialogs. However, we need to give the bot a hand in understanding where the user wants to go by saying that intent at that point in the flow. For that, you can help 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 directed to either the
confirm order bot dialog (when the confirmingpizza context is active) or to the
second joke bot dialog (if the joking context was active)
You can repeat this configuration for the 'no' intent as well. In the end, you would get a configuration like this:
ask confirmation of pizza order- 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, you 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 expression similar to 'yes' 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 bot dialog 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