Capture information with input validation

So far, our content was limited to simple conversation. In a lot of use cases, you will need to ask the user for input. That input can then be stored in a database, for calling an API service, or for making personalised messages.

Adding an Input Validation

In our Choo Choo example, our user has shown the intention to book a train ticket. Before we can do that, we need some information from the user like:

  • Origin

  • Destination

  • Departure time

  • Departure date

  • First class or second class

Text input

Let's start by asking for the departure location.

  • Add a new bot dialog of type Input Validation by hovering over the + icon underneath the bot dialog book train ticket

  • Name this bot dialog arrival location.

  • On the Input Validation tab go to the Bot Message properties pane.

  • Add a new text message with the text "Where do you want to go?".

Input validation (aka plugins) can automatically parse certain types of data like dates, addresses, numbers, hours, currency, ... This will convert the users response into a more structured format. We are simply asking for any string here, so we use input type 'Any' which will accept all values as valid input. More info about Plugin Parser Types

Next add a validation

  • Goto the Validation pane.

  • Select Any as the Format type.

  • Type destination as the variable.

  • Select or type Confirm booking in the Go to field. Because Confirm booking bot dialog doesn't exist you get the option to create a new one. Pick Create Bot Message 'Confirm booking'

The end result should look like this.

Once created you will see the following flow.

The parent - child relation between dialog state nodes has no functional conversation meaning. It is only a visual representation.

Using input in text messages

All the session variables are stored in the user session. To access a variable in any displayed text, you can put the variable name between curly brackets.

  • Go to the Confirm booking bot dialog

  • Enter a new text message Okay you want to go to {destination}. We can do that.

NLP & input plugin

You want to make sure your users don't get stuck in a loop asking them for some input. Because of this, by default, Chatlayer makes sure that if an intent is detected in the answer to the input plugin, users leave the input plugin and go to the relevant part of the conversation.

In some cases, you might want to make sure your users remain in the input plugin, no matter which intent is triggered. To do this, you can select the "Disable NLP" checkmark in the input plugin.

Linking bot dialogs

We have not defined an intent to get to the Destination bot dialog. That makes sense as we only want to reach this state whenever we are in a specific part of the conversational flow: while booking train tickets. We want this input bot dialog to only be reachable as a next step when users have stated their intention to book a train ticket.

  • Edit the book train ticket bot dialog

  • Go to the Bot Message properties pane

  • On the Go to pane click on + to add a Go to next bot dialog

  • Choose arrival location bot dialog from the drop down list

  • Click on Save

  • And test

If you forget to define the 'Go to' and you test your conversation flow, the flow will just stop. The conversation flow will only continue if you correctly set the 'Go to' on each dialog state.

Add remaining dialog states

Repeat the previous steps for the following required user input variable.

  • Origin (bot dialog name: departure location)

  • Departure time (bot dialog name: departure time)

  • Departure date (bot dialog name: departure date)

Combining input plugins with buttons

In a previous example we requested user input by sending a text message but it is also possible to use buttons, lists, carousels and other UI components to support user input as text or clicks.

Let's use a carousel component to request the user his preferred train class.

  • Add an input validation

  • Add a text message in this plugin

  • Add a Carousel and a Carousel Card for first and second class

  • Configure the button with a next dialog state 'Confirm Booking' and create a value 'first' for the variable 'class'.

It's important to use an identical variable name for the input variable, the NLP entity and the button variable.

Depending on the user input different actions are executed:

  1. When the user has defined an entity class in his sentence which had a book intention as result (for example: "i need a first class train ticket'), the 'class' variable is stored in the user session with a value 'first' and the bot dialog 'first or second class' is skipped because the value for the input variable is already available in the user session.

  2. When the user is asked to input his preferred train class and he inputs 'first', this value will be added in the input variable 'class' in the user session.

  3. When the user clicks the button 'First Class', the value 'first' will be added to the variable 'class' in the user session.

It also possible to define an extra intent 'Input train class' with expressions and entity values

  • I prefer first class

  • I would like to have a first class ticket

  • Second class please

Linking this intent to the bot dialog 'First or second class' would support different sentences for preferred train class input.

As an alternative solution it is possible to request a custom parser for input plugins. You can request all kinds of input type parsers for parsing custom domain related data such as customer numbers, vehicle parameters, .... Please Get in contact with our Support team or your project manager for these requests.

In the next tutorial we will learn how we can use context for reusing intents. A good example are yes and no, which can be used in association with more than one specific dialog state.