Need to reuse the same intent twice or more? The answer is context.

Context makes it possible to reuse the same intent in several blocks, 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'.

Step 1: Helping the bot understand the user's reply

First, for the bot to understand the user's 'yes' or 'no', we need to create two blocks and link each one to one of the following intents:

  • general_yes

  • general_no

Step 2: Linking bot message through context

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 blocks. Now all we have to do is connect these blocks 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 block containing the question. Open the Ask a question block and go to the NLP section. Create an output context that you will later link to the blocks containing the general_yes and general_no intents:

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.

Step 3: Linking intents through context

The last thing to do is make sure that the two blocks containing the general_yes and general_no intents are linked correctly to the block 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 :

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.

To improve visualization, you can link the 'ask a question' block as a 'parent' to the intent. This creates a clear visual connection, represented by an arrow, from the 'ask a question' block to the 'general_yes' and 'general_no' intent nodes.

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

Step 4: Reusing intents in the same conversation

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:

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 block (when the book_ticket context is active) or to the Yes book a new ticket block (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 updated