Context

Need to reuse the same intent twice or more within the same bot? Set context to your flows and make sure the bot provides the right answer.

Context makes it possible to reuse the same intent in several blocks, an important feature in bot building!

Example

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'.

We need context so that the 'yes' or 'no' lead to different flows depending on where they are said in the conversation.

Add context to your flow

To use context in an intent:

  1. Make sure that you created intents and linked them to blocks. In this example, we'll use general_yes and general_no intents.

  1. Open the block containing the question.

  2. Go to the NLP section.

  3. Under Give output context and livespan, Ccreate an output context. For this example, we will call it book_ticket with a lifespan of 1.

The lifespan designates how many times a context can be set throughout the whole conversation. For instance: 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.

  1. Click Save.

  2. Open your intent block. For instance, open the general_yes intent block.

  3. Navigate to the NLP tab.

  4. Under Required context, look for the context that you just created. In this example it will be book_ticket.

  1. Click Save.

Tips on visualizing context in the canvas

From your bot canvas, visualizing context at first sight can be not so straightforward.

  • Hover to see context

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.

  • Use parent connections

To improve visualization, you can set the Ask a question block as a parent to the intent block. This creates a clear visual connection that improves readability.

  1. Follow the same process for other places in the conversation where those intents are used. That way, you can be sure that the bot provides the right answer!

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