4. Contextual Cells

This session demonstrates how to use contextual cells to improve the dialogs.

The Problem

In the previous sessions, we created two cells as below.

Cell 1. Customizing response to Hello.

    • Hello
    • Hi, there!

Cell 2. Saying Hello proactively.

    • myApp sayHello
    • Hello!

Each of them works perfectly but together they may bring a problem, as the below chat log demonstrate.

    • myApp sayHello
    • Hello!
    • Hello!
    • Hi, there!

Hmmm, the bot shouldn't say "Hi, there!" when user says "Hello!" in responding to bot's "Hello!" as greeting. She should reply something else like "How is the weather there?", right?!

The Solution

To address the issue above, you need contextual cell, which specifies not only an Input but also a Context field. Follow the steps below to create Cell 3.

Cell 3. Contextual Hello.

    • Hello
    • Hello
    • How is the weather there?
  1. Click Cells tab.
  2. Click Add icon.
  3. Click Context.
  4. In Context field, enter "How is the weather there?"
  5. Click Save button.

Now go back to Training page. Simulate the dialogs again and the results are a bit different.

    • myApp sayHello
    • Hello!
    • Hello!
    • How is the weather there?

Our Tutor works much better this time. What's the magic? Where cells have same Input, BrainShop will check their Context field further and choose one matching not only Input but also Context, if any. When processing Context, BrainShop ignores its points and caps, same as Input.

So what is Context on earth? By default it's the last sentence the bot previously sends to user. Later you will learn you can set the context as a different value but now you can simply take it as the last sentence of previous message sent by bot. In the above example, the context for the user's message "Hello!" is "Hello."

We often say the same text may delivery different meaning in different "context." That's what the context literately means here.

Things to Keep in Mind

  • The Context is the last sentence of previous message sent by bot.
  • Points and caps are ignored when processing Context.
  • Use Context where you want to give different Output for the same Input.
  • Don't use Context unless you have more than one cells with same Input.