How to use LUIS entities

Another big advantage with LUIS^Teneo is the use of entities. Entities can capture and pass important information from the user input. LUIS provides many prebuilt entities covering common fields like person name, geography info, etc. A user can also create their own entities in LUIS. This section will show how to use LUIS entities in Teneo Studio.

We'll continue with the 'What can I get for 20 dollar?' flow created in the last page to capture the amount of money a user mentioned and calculate how many cups of coffee can user get.

This is how such a conversation could go about:

User: What can I get for 20 dollars?
Bot: For 20 dollar you can get 10 cups of coffee.

User: What can I get for 40 dollars?
Bot: For 40 dollar you can get 20 cups of coffee.

To achieve this we will do the following:

  • Add a prebuilt entity in LUIS.
  • Create a flow variable.
  • Create a flow listener.
  • Add a script node.
  • Use a flow variable in the answer text.

This is what your flow will look like: Final Version Of Flow

Add a prebuilt LUIS Entity

We will start off by adding a prebuilt entity inside our LUIS application,

  1. While inside your LUIS application, select 'Entities' located on the sidebar to the left.
  2. Select 'Add prebuilt entity' and search for 'money'.
  3. Select 'money' and press 'done'. This will add the selected entity to our LUIS application.
  4. Press 'Publish' at the top right corner.

The entity page should look like this when you are done: LUIS Entity Page

Add a flow variable

To be able to store the amount and currency mentioned by the user, we need to create two flow variables:

  1. Open 'What can I get for 20 dollars?' in edit mode.
  2. Click on the tab 'FLOW' in the top left corner of the flow window.
  3. Choose 'Variables' in the purple bar on the left.
  4. Click 'Add' in the top right of the window.
  5. Name the variable amount by replacing the word 'Variable 1'.
  6. We want to initialize this variable zero as default value, so in the text box below add 0.
  7. Add one more variable and call it money with "" as default value.

Pick up the LUIS entity using a listener

Now that we have the trigger in place it is time to pick up the amount and currency that the user mentioned. We will do so by using a flow listener:

  1. While inside 'Variables', select 'Listeners' from the purple bar on the left-hand side.
  2. Click on the little 'Add' icon at the top to add a new flow listener.
  3. Name it Get amount of money and paste %$LUIS_MONEY.ENTITY^{amount = lob.number ; money = _USED_WORDS} in the condition field. This will store the part of the user input that matched the LUIS entity in the flow variable amount and money. script_explained

  4. Hit 'Ok' to close the Listener window and then the back arrow to return to the main flow window.

Add a script node

With nothing else in the flow marked, click the 'Script' icon in the ribbon. This will add an empty script node to your flow. Give it a name that explains what the script does, like Calculate amount.

Put the script node in its place

Currently, our script node is dangling and not connected to any of the other elements in the flow. However, we want our script to be executed immediately after the flow is triggered, and right before the output is shown to the user. To achieve this we need to follow these steps:

  1. Select the script node.
  2. In the ribbon choose 'Set start node'. This points the trigger straight to the script node.
  3. Draw a line from the script node to the output node.

Populate the script node

We have added the script node, but it is still empty. Now we'll need to add the script that calculates the number of cups it can afford. Select the script node in your flow, open the 'Script Action' tab on the right sight of the screen and paste the following code into the script node:

amount = amount / 2

Configure the output node

The only thing that remains to be done now, is to configure the output node to summarize the flow.

  1. Select the output node '10 cups of coffee!'
  2. Change the answer to For ${money} you can get ${amount} cups of coffee.
  3. Change the output node name to ... cups of coffee!.
  4. Hit 'Save'.

Try it out

That's it. Now go to Try-out and give it a go! The answer should change depending on the amount provided.

User: What can I get for 20 dollars?
Bot: For 20 dollar you can get 10 cups of coffee.

User: What can I get for 40 dollars?
Bot: For 40 dollar you can get 20 cups of coffee.

Where to go next?

Now that we know how to use LUIS^Teneo its time to learn more about, Deploy your bot where you'll find documentation on our SDK's and example connectors for platforms like Microsoft Bot Framework, Slack, Facebook Messenger and Google Assistant.

Was this page helpful?