08 – How To Design Conversation Bot That Ask Questions | Video Course

How to Design a Conversation Bot that Asks Questions

What you will learn?

As you may know, a good conversation bot is an automation that occurs between users and chatbots when they are capable to understand each other messages.

While you need to build bots capable of answering users’ questions, you should also be concerned with building bots capable of asking the right questions and accurately collecting data.

How to check user input in your chatbot

You have already learned how you can use the Generic Input Action to make first-quality validations on the input we receive from users.

Basic Input

Text detection can happen in two different ways: using simple text or using a Regular Expression.

Simple text

The text you enter in Control Expression is directly matched with the user input. For example, entering “this is cool” will match any sentence containing that exact text.
You can use a pipe (|) symbol to match multiple sentences. So to match “this is cool” and “this is great”, you can enter “this is cool | this is great” in Control Expression.

Regular Expression

A regular expression is a pattern that the regular expression engine attempts to match in the input text. A pattern consists of one or more character literals, operators, or constructs.
Xenioo supports standard Regular Expression notation. The input text will be matched against the regular expression specified in Control Expression.

As an example, I’m creating a chatbot for a clothes shop where there are different colors available. If the user is allowed to buy a dress available in 3 colors only (green, red, and black), so the chatbot cannot accept any other response from the user.
As you can see in the image below, I’ve played with the Control Expression of Generic Input Action to specify the only required values:

The magic happens thanks to the character “|” that separates the different values I want to accept in this input request.

Specialized Input Actions

Xenioo offers many different and specialized types of input actions.

You can find them opening up the action dialog like shown in the image below:

If you want to ask for simple information like a first name, the Generic Input Action is enough and you don’t need any specific validation check.

In the image above, I just added the word “Cancel” as a term to skip the question and go ahead into the flow.

Any word except “cancel” will then be considered valid input and it will trigger the Go To action. However, if the user will enter “cancel”, the text message “Ok, if you’ll change your idea I’ll be there for you.” will be shown.

How to make a chatbot ask for numbers

Now let’s see how to handle questions when you expect a numerical answer.
In this case, you need to use the Number Input Action which, as you will see, introduces some important features.

First, you can specify the minimum and the maximum value (1,2) of the asked number. A number outside this range will generate the Wrong User Input Reply.

For example, in a booking flow for a restaurant, you can use minimum and maximum value to set limits on the request for seats.

As you can see, I’m using the keyword “Cancel” (4) to skip the question and ending the booking process.

Ignore extra text in reply” (3) flag is an interesting one and something you wouldn’t find on other platforms.

Once switched on, Xenioo will use this flag to accept responses that are not strictly numerical but contains numbers. Just look at the image below:

If a user replies: “We should be 6 people” instead of just the number “6”, Xenioo will still accept the answer as valid, extracting the number 6 and saving it into the numeric variable. Awesome, isn’t it?

How to make a chatbot ask for a Phone number?

The telephone number is one of the most desired information when it comes to marketing. This is why it is important to be sure the number you’re receiving is correct, at least on a formal level.

No problem, Xenioo takes care of it, thanks to the Phone Number Action.

This action will expect the user to input the correct phone number.

If your chatbot is for the Facebook channel you also have another option: the Phone Quick Reply Action. This action displays a button that once clicked will automatically retrieve the user’s phone number from his Facebook account(based on its privacy settings) and send it back to the chatbot.

How to make a chatbot ask for email?

Something similar to the phone number happens when you have to ask for email addresses: they are important and must be checked!
Building a logic that validates an email could be a nightmare. Luckily, Xenioo provides the Email Input Action, a specific input action that include all the logics that formally validate an email address.

If your chatbot is for the Facebook channel, you also have another option: the Email Quick Reply Action.

This action displays a button requesting the user email that once clicked will automatically retrieve the user email address from Facebook (based on its privacy settings) and send it back to the chatbot.

How to make a chatbot ask for video, images, and audio content?

If your chatbot needs to ask for any kind of media content, you should use the Media Attachment Input Action.

This action is very powerful because it allows the chatbot receiving images, audio, video, documents, and user position.

For example, if you want to ask a user for a photo, you’ll set up the action as follows:

Let’s test this interaction to see what happens. I’m using the Preview panel inside the flow designer to test it out.

As you can see, this action will save the URL of the media attachment in a specific variable named user_attachment variable. Automatically, other variables are generated by Xenioo and available in the flow, such as user_attachment_type, user_latitude, user_longitude, user_location, and user_location_name.

The variable user_attachment_type contains the type of attachment sent by the user and can be useful just to figure out if it is an image, a video, or something else.

For example, in the flow below I used it to thank the user with a specific message based on the type of media received.

How to catch user location?

The user’s location can be requested with 2 different methods.

The first is through the Media Attachment Input Action, as you have just seen, which includes “Position” among the supported media. The second method requires the use of the Location Quick Reply Button Action.

If we use the Media Attachment Input action with Position selected, the user should select the location type attachment in their app (for example Telegram).

Xenioo will get the location information and put that information in specific variables: user_latitude, user_longitude, user_location and  user_location_name. Just keep in mind that some channels do not support sending back location information or provide only basic information like latitude and longitude.

The Location Quick Reply Button action works proactively, just by showing the user a button that will send back the location information. Even in this case, this type of button is supported on a limited number of channels.

As you can usually do with other variables, you can use location variables values to change the flow path. You can see an example in the image below.

If both conditions are ok and so the user is within the available area for the delivery, the chatbot will confirm the availability of the delivery service.

How to use Regular Expression to validate inputs

A regular expression (in short form, regexp, regex, or RE) defines a function that takes a string as input, and returns a yes / no value, depending on whether the string follows a certain pattern or not.

For example, all e-mail addresses must be made up as follows: start with a sequence of alphanumeric characters, followed by the @ symbol, followed by other alphanumeric characters, followed by a dot, followed by other few letters that make up the domain extension.

This informal rule would become a regex if it were encoded according to a precise syntax recognized by a program capable of analyzing strings, like Xenioo.

[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}

So, to validate an email address, you can use a regex like this in your Control Expression:

Regular expressions are a very powerful tool for working on strings. They consist of a sequence of characters and can be used both to validate data and to search within a text

If you want to learn more about regex, you can take a look at this website.

To Sum Things Up…

As you have seen, the Input Actions are really powerful components Xenioo provides us to help to build chatbots. With such actions, you can ask users information you need, minimizing any input errors and validating data.