First steps to create a Chatbot with GeneXus Web - Part 5. Defining flows in a Conversational Flows

Official Content
This documentation is valid for:

The Conversational Flows object has two flows called Greetings and Hello World already initialized.

Focus on the Greetings flow to set the greeting and welcome intent. Click on it and you will see, in the right window, three sections:

1. Trigger Messages

2. User Input

3. Responses

GeneXus Web_chatbot_GreetingsFlow

Every flow you select or create contains these three sections.

 1.    Trigger Messages

These are the messages you expect users might type; that is, the possible scenarios.
As for a chatbot with NLP assistant, you can think of them as synonyms.

When it comes to a Scripted chatbot, the user is going to enter a single value out of several possible values offered. Therefore, a single Trigger Message is usually indicated. However, entering more than one Trigger Message is supported.

A Scripted chatbot checks that the message entered by the user matches one of the options that were set as Trigger messages.

On the other hand, a chatbot with NLP assistant uses artificial intelligence to expand and interpret what the user typed, regardless if it is exactly the same as what was defined in the Trigger Messages section.

In the flow called Greetings, you will see two Trigger Messages: “Hi” and “Hello.”

To delete one of them, for example, “Hi”, just click on the “X” to the right of it.

 GeneXus Web_Chatbot_Delete flow

To edit a Trigger Message in the flow, just click on the text box and type what you want.

For this example, leave it unchanged.

GeneXus Web_Chatbot_Edit a Flow

2.    User Input

The value or values entered by the user (in one or several variables, as appropriate) are stored here. They are used as parameters sent to the GeneXus object (Data Provider or        Procedure) that queries the database to obtain the data to be displayed, filtering by those parameters.

3.    Responses

In this section, you need to enter the responses that the chatbot should give to the flow intention.
This section cannot be left empty. If you try to save the flow without a response, an error will be displayed.

Continuing with the example of the Greetings flow, you need to enter the response that the chatbot will give when the user types one of the Trigger Messages “Hi” or “Hello.”

To do so, click on the Greetings flow. On the right, you will see the Responses (1) section.

GeneXus Web_Chatbot_GreetingsResponses

In it, there is a response named RESPONSE 1.

GeneXus Web_Chatbot_GreetingsResponse1

Click on the little arrow in the upper right corner (next to the trash bin image) to expand the dialog.

GeneXus Web_Chatbot_Edit_Response1

In the RESPONSE MESSAGES(1) section, click on the little arrow on the left:

GeneXus Web_Chatbot_GreetingsResponse2

You will see an automatic reply: “Hello! Welcome to your very own chatbot.” You can use that one, edit it, or add a new one.

In this example, edit the automatically offered message and type: “Welcome to our Travel Agency Chatbot! Type “Menu” to access the options.

GeneXus Web_Chatbot_GreetingsResponse3

Save your Conversational Flows object (TravelAgencyBot) by pressing the Ctrl + S keys.

Now press F5 on your keyboard to generate the necessary code and view your first flow running. Another way to do the same is to select the menu options: Build > Run.

An Impact Analysis will be displayed indicating that a reorganization should be performed.

Click on the Reorganize button.

GeneXus Web_Chatbot_Reorganize_ImpactAnalysis

Next, a tab will open in your browser showing the Developer Menu (menu for the developer to test the application being built).

To run the chatbot, click on the TravelAgencyBotChatbot.Travel Agency Bot Web UI link.

GeneXus Web_chatbot_DeveloperMenu

The application will open:

GeneXus Web_ChatbotTest

Test how it works by typing “Hi” in the text box and it will show you the response you have indicated.

GeneXus Web_ChatbotTest1

You have just created the first flow (Greetings) of the chatbot (TravelAgencyBot).

To delete the Hello World flow, which is created by default when creating a Conversational Flows object (or another flow), just click on the trash bin next to the flow name.

GeneXus Web_Chatbot_DeleteFlow

To create flows, you are offered the action + Add another Flow.

Creating a flow: Menu

Next, in the Conversational Flows TravelAgencyBot object, create a new flow called Menu to inform the user of the options available to choose from.

To do this, click on + Add another flow. Select the text “New Flow”, edit it, and give it a name.

GeneXus Web_Chatbot_NewFlow

Name it “Menu.”

GeneXus Web_Chatbot_MenuFlow

The objective of this new flow is to inform the user about the options they can choose from.

Defining the Trigger Message

The Trigger Message of this new flow must be Menu. That is to say, when the person types the word Menu in the chatbot, it will display the possible options.

To do so, when positioned on the Menu flow, to the right, you can see the TRIGGER MESSAGES section. Click on the little arrow in the upper right corner to expand the TRIGGER MESSAGES section.

GeneXus Web_Chatbot_TriggerMessage_Menu

Click on +Add another sample Trigger Message.

GeneXus Web_Chatbot_NewTriggerMessage_Menu

GeneXus shows, as Trigger Message, the word “Menu.” It infers that this must be the Trigger Message corresponding to this flow and it is correct. Leave it as offered.

GeneXus Web_Chatbot_TriggerMessage_Menu1

Defining a Response


Now you must add a response that will be the message shown to the user after typing the word Menu.

Look at the section Responses (1).

In it, there is a response named RESPONSE 1.

Click on the little arrow in the upper right corner to expand that section.

GeneXus Web_Chatbot_Responses_Menu

Go to the RESPONSE MESSAGES(1) section and click on the little arrow to the left.

Then click on +Add an alternative response message and add the following text:

“Please indicate the option number you want: \n *1* - Most visited attraction. \n *2* - Flights on sale. \n *3* - Attractions by trip type.”

GeneXus Web_Chatbot_Edit_Responses_Menu

You are giving the user three options to choose from.


Option 1 - View the most popular attraction.

Option 2 - View the flights on sale.

Option 3 - View attractions by trip type.

Save the Menu flow you have created using the Ctrl + S keys on your keyboard.

The next step is to create a new flow for each of the options that were offered to the user.

Here is an example of how to define the flow whose intention is to solve option 2 of the Menu: View flights on sale.

Creating the “FlightsOnSale” flow

In the Conversational Flows TravelAgencyBot object, create a new flow with the name: FlightsOnSale.

To implement an intent for this flow, it will be necessary to create a Procedure object that navigates the FLIGHT table, filters the flights on sale, and loads an output parameter with the data of those flights.

Create a transaction called “Flight” with the following structure:

GeneXus Web_Chatbot_FlightTransaction

The “Flight” Transaction will cause the creation of a table named FLIGHT in the Database.

Now create a Procedure, name it GetsFlightsOnSale, and define its code as shown:

GeneXus Web_chatbot_ProcedimientoGetsFlightsOnSale

After creating the GetsFlightsOnSale Procedure, you must associate it with the FlightsOnSale flow of the Conversational Flows TravelAgencyBot object.

To achieve this, while positioned in the FlightsOnSale flow, click on + Conversational Object:

GeneXus Web_chatbot_FlightsOnSale_ConversationalObject

A Conversational Object is a GeneXus object that implements the action of the flow.

The dialog box opens so that you can select the Procedure and associate it with the flow:

GeneXus Web_chatbot_KBObjectSelector

Once you have located and selected it, click OK to associate the Procedure with the flow. In the following image, you can see that the Procedure is now associated as a Conversational Object:

GeneXus Web_chatbot_FlightsOnSale_ConversationalObject1

The inputs and outputs of the Procedure are automatically inferred in the flow. In this example, an output.

Defining Trigger Messages

Now you must add a Trigger Message to the FlightsOnSale flow. You will be offered the name of the flow by default, but you must edit it and type number 2. It will be the option that the user will type to ask the chatbot for the trips on sale from the Menu.

GeneXus Web_chatbot_FlightsOnSale_TriggerMessage

Defining a Response

You need to configure the response that the chatbot will give to the user when they request option 2 in the Menu.

To do so, go to the RESPONSES section and, as you have done before, add the following text: “The Flights on Sale available are:\n &FlightsOnSaleList”

GeneXus Web_chatbot- Flightsonsale_responses

Save the changes (CTRL + S) and select Build > Run.

An Impact Analysis will be shown indicating that a reorganization (the creation of the FLIGHT table in the database) must be performed.

GeneXus Web_chatbot_Flight_Reorganization

Click on the Reorganize button.

Next, a tab will open in your browser and show the Developer Menu.

GeneXus Web_chatbot_DeveloperMenu1

Click on the Flight link to enter some flight data using the Flight Transaction.

Then, click on the last link to run the chatbot.

GeneXus Web_chatbot_DeveloperMenu2

It will be displayed as shown below:

GeneXus Web_chatbot_DeveloperMenu3

Note: If instead of showing the data of the flights on sale the chatbot shows the variable name (&FlightsOnSale), you must define the variable manually in the Source of the Conversational Flows TravelAgencyBot object, as shown below:

GeneXus Web_chatbot_variables

Save the Conversational Flows object and run.

What if the chatbot doesn't understand the user's input?

If the chatbot doesn't understand the option entered by the user—that is, if the user types something that doesn't trigger any flow (in this example, pretend the user types the number 5)—you need to redirect it somewhere. In this example, you will direct it to the Menu flow.

To do so, find the Input Not Understood Redirection property in the properties window and among the available options select: Menu.

To open the properties window, click on Properties in the upper left corner (above the flows).

GeneXus Web_chatbot_Input

Once positioned on the Input Not Understood Redirection property, expand its options and select Menu.

GeneXus Web_chatbot_Input1

This will return to the start of the Menu flow when the wrong command is entered.

You can type the message that will go with this redirection in the Input Not Understood Message property.

Type the following: “Welcome to TravelAgencyBot. Thank you for communicating with our self-management system.”

GeneXus Web_chatbot_Input2

What you write in these properties will work for all the flows you have created when the chatbot doesn't understand a command entered by the user.

You have successfully created your first chatbot! Congratulations!