In the previous tutorial, we created a new bot and added a greeting. Now it's time to add some actual content. We will start with some basic bot responses to users' frequently asked questions.
The Natural Language Processing (NLP) engine is the underlying algorithm that allows the bot to understand what the user is saying. Since each language has its own words and grammar, we have a separate NLP engine for each language.
Understanding language isn't easy: it takes us humans about 6 years and hundreds of examples to understand the most common 20,000 words. And computers are not that different. To train an NLP engine, we need huge amounts of data. Luckily, we rely on pre-trained models that have a lot of smarts built in already.
An intent is a specific question from your user, or an action they can do. For example: an intent can be a question, a statement, an answer to a question, or a greeting. Each intent can be expressed in many different ways, we call these different ways of saying the same thing expressions.
In the example above, the user intent is "How do I sign up for a free trial?". This is then recognised by the NLP engine, which triggers the correct response.
Here are some more examples of intents and expressions:
Intent: book train ticket Expressions:
I want to book a train ticket
I need to go from Antwerp to Brussels
Can I order a ticket here?
Intent: who are you? Expressions:
What is your name?
What can you do?
What should I call you?
Intent: yes Expressions:
Intent: I want to speak to a human Expressions:
Can i speak to a real person?
I want to talk to a human
For this tutorial, we want to give Choo Choo the ability to answer basic questions about itself. To get started, we will create an intent for the question:
Who are you?
On the left side of the screen in the navigation menu, click on
NLP to navigate to the NLP module. Click the
+ Add Intent and name it
who are you
Now we have to train the NLP to recognise this Intent. We do this by adding Expressions. Expressions are different ways your users will express one Intent.
The more Expressions you add to an Intent, the more accurately it will be recognised. It is crucial for an Intent to have a wide variety of expressions to give accurate results. The more expression you can think of, the better the result of the NLP will be and the 'smarter' your bot will appear.
who are you intent in the Intents pane
+ Add Expression in the Expressions pane
Who are you? in the open text field
Your screen should look like this:
Add some more expressions:
What is your name?
Can I know your name?
Tell me more about yourself
Please, I'd like to know who I am talking to
How should I call you?
Who is Choo Choo?
Tell me what your name is
Who are ya?
What do people call you?
Are you a train?
Do you have a name?
Again, the more expression you have, the more accurate your bot will be able to respond. Later on, we will see how we can make sure that our bot gets smarter over time, by looking at actual user input once the bot is made public.
Add another intent, like
Greeting and add some expressions:
Tip: if two of your intents are very similar in terms of expressions’ syntax or content, you might want to merge them. For example, let's look at our bot responsible for booking train tickets. Imagine you'd also like to offer bus tickets. You could create an extra intent for booking bus tickets, but the expressions in each intent would be very similar, with only the transportation mode changing from time to time. It would be better to only have one intent handling reservations, and an entity to catch the requested vehicle type. We will look at entities in the next tutorial.
We have defined two intents now: who are you & greeting.
To update the bot, we now need to re-train the NLP.
Update NLP button in the top right corner of the screen:
Select the language you used to add the expressions. You can view the status of the NLP update for each language by clicking on the Update NLP icon.
Update to start the training. This can take a couple of minutes to one hour depending on the size of your chatbot. The more complex, the longer it'll take.
You have now taught the NLP to understand your query, congrats! The only thing left to do is teaching Choo Choo how to respond. You can do this by adding a new Bot dialog.
Click on Bot dialogs menu item in the navigation pane
Open the General flow
+ Bot message
who are you as the name
introduction dialog state as the parent
Link the intent to the bot dialog in the bot dialog NLP tab
Bot Message tab and add a text message that says:
I am Choo Choo, your personal assistant for booking train tickets
Your screen should look like this:
We have defined the
introduction bot dialog as the parent dialog state here. Parent bot dialogs do not limit or define the possible flow of the dialogue, they are a visual tool to structure the conversational flow and keep the overview. They make it easier to create complex conversational flows. Bot dialogs can be reached from any point in the conversation by linking a bot dialog to an intent, although you can restrict them too by using Contexts. This mimics the way humans talk, jumping from one subject to another.
As an exercise, you can now add multiple messages to the
who are you bot message. You can do this via Bot Dialogs > Flow > Edit 'Who are you' Bot Message.
Update the single message to show multiple messages:
I'am Choo Choo.
Your train traveling assistant.
You can book a train ticket or ask my support.
After your booking I'll keep you updated about train details so you don't have to worry about your journey.
This makes your bot more user-friendly and human.
Time to test your bot! Click on
Test your bot at the bottom right to test your conversational flow. To get a feel of your bot's performance, ask the same question a couple times, including different ways of asking the question that are different to the expression you used to train. If a question is not recognized correctly when it should be, you'll have to go back to the
NLP tab, add the questions as an expression, and retrain the NLP model. You can do this as many times as needed, the model will just keep on improving.
Open the Debugger and select a user message in the
Messages list to retrieve detailed information about the bot's response message, the user funnel and context, Natural Language Processing results and user session data.
To configure the translations of the secondary language message and other text, go to the
Translations module under the
Bot dialogs tab. For more information, see the Translations module in this documentation.
When you have created a multilingual bot, you will notice that you can switch the active language in quite a few pages in the menu bar at the top, upper right. You can add expressions for all intents in the secondary language (if you have one) in the NLP tab.
For more information on how to retrieve the user's preferred language, head to Multi-language bots.