Context
Need to reuse the same intent twice or more? The answer is context.
Context makes it possible to reuse the same intent in several bot dialogs, an important feature in bot building! Let's learn how to use context with this short example:
So, we've built a bot that can help users place a food order. At one point in the conversation, the bot will ask the user if they'd like a free dessert. The user can reply with 'yes' or 'no'. A bit later in the conversation, the bot will ask the user if they're ready to place their order. Again, the user can reply with 'yes' or 'no'.
First, for the bot to understand the user's 'yes' or 'no', we need to create two bot dialogs and link each one to one of the following intents:
- general_yes
- general_no

Two bot dialogs, one for each possible user response

In the screenshot above, you can see that we've added the
general_yes
and general_no
intent nodes to the canvas and linked them to the bot dialogs. Now all we have to do is connect these dialogs to the bot message Ask a question
, so the bot knows which question is being answered. We can do this by creating
output context
for the bot dialog containing the question. Open the Ask a question
dialog and go to the NLP
section. Create an output context
that you will later link to the dialogs containing the general_yes
and general_no
intents:.png?alt=media&token=5550302f-561c-4c50-890a-399a29dfe69b)
Adding an output context to a bot dialog
You can tell the bot how often this context can be repeated throughout the entire bot conversation. For example: If the bot offers free dessert twice in one conversation, we should put the
lifespan
at 2 because the user can say 'yes' or 'no' twice to this question. In this example, we'll only offer free dessert once, so we'll keep the lifespan
at 1.
The last thing to do is make sure that the two bot dialogs containing the
general_yes
and general_no
intents are linked correctly to the dialog containing the question. To do so, we have to open each intent nodes, go to the NLP section, and add the required context
we defined earlier as required context
:
Adding a required context to an intent
Once you click 'save', the bot can understand a 'yes' or 'no' response to the question of booking a ticket.
By hovering over the input context next to the intent title, you can instantly view the 'required context' that you just configured. This gives you a clear picture of the context requirements for your intent, enabling you to make any necessary adjustments.

Hovering an icon to see all required context linked to an intent
To improve visualization, you can link the 'ask a question' bot dialog as a 'parent' to the intent. This creates a clear visual connection, represented by an arrow, from the 'ask a question' dialog to the 'general_yes' and 'general_no' intent nodes.

Linking a bot message as 'parent' to the intents
By establishing this connection, you can easily understand the flow of the conversation and identify which intents are associated with specific dialogues. This makes it easier to make adjustments to your bot's conversation flow and ensure that it operates smoothly.

Parent-child arrow visualization
Later in the conversation, the bot will again ask a 'yes' or 'no' question to its user:
"Can I help you with anything else?"
To make sure the user can reply 'yes' or 'no' to this question as well, we'll need to use
output context
again:
Using different output context so we can use the yes/no intent again
Now, when the
general_yes
intent is recognized, the bot will know which question this answer belongs to checking the output context
. Depending on this context, a user will be directed to either the Yes book a ticket
bot dialog (when the book_ticket context is active) or to the Yes book a new ticket
bot dialog (if the do_anything_else context is active).A user can have multiple contexts when navigating between different conversation flows. When multiple intents and input context combinations are found, the user's context with the highest lifespan value is taken.
Last modified 4mo ago