When defining a chatbot conversation, some topics have to be considered (Intents, Triggers, Messages, Entities, and Flows).
An Chatbot Intent is always represented by a Flow, and the Flow can be associated to a GeneXus object through the Conversational Object property.
Here we explain how to define an Intent using a Flow whose Conversational Object is a procedure.
To add a Flow to the Conversational Flows instance, select the Add -> Flow of the contextual menu.
Next, enter a Name for the Flow, some Trigger Messages, and select the GeneXus object which will be triggered after the intent is recognized and the user finishes entering all the required input (the conversational object).
In this example, the conversational object is a procedure called "Lighting2".
In the Chatbot Provider (e.g., Watson), an Intent will be defined for the dialog using the given Flow name.
It's important to define Trigger Messages for this Intent to be detected by the Artificial Intelligence (AI).
Once the Intent has been detected, the user will be asked to provide some information to comply with this Intent. The information to be asked from the user is displayed under the User Input node of the structure.
The User Inputs are added automatically to the structure and are inferred from the In parameters of the Conversational Object.
Each parameter can be set as an Entity in the Chatbot provider's workspace. The benefits of setting a parameter as an Entity include that its value will be checked against the Entity values. Besides, a try limit can be specified in case the user fails to enter a valid value.
Note that in this example, the UserIdentification is set to match with an entity, whose name is "UserIdentification".
The Ask Messages property allows specifying the message to be shown to the final user in order to ask him to enter that input.
The On Error Messages property value is thrown when the input entered is not valid.
Inside the On Error Messages property you can include the reference of what the user has entered: &GXUserInput. For more information see HowTo: Reference context parameters in a conversation.
The "Lighting2" procedure has the following parm rule:
parm(in:&UserIdentification, in:&ComplaintDescription, in:&ComplaintAddress, in:&ComplaintPhoto,out:&response);
The output parameter is used to send an answer to the chatbot. The code is as follows:
&complaint = new()
&complaint.UserIdentification = &UserIdentification
&complaint.ComplaintAddress = &ComplaintAddress
&complaint.ComplaintDescription = &ComplaintDescription
&complaint.ComplaintReason = ComplaintReason.Lighting
if not &ComplaintPhoto.IsEmpty()
&complaint.ComplaintPhoto = &ComplaintPhoto
&response = !"Thanks for your feedback. It was successfully added and it will be processed asap!"
&response = !"There was an error, try again later please!"
The output parameters are also detected, so a Response node is added automatically, including that parameter.
The Message node determines the way that this output is going to be shown; in this case, since the Style property is set to Text Message, it will be displayed as text only:
Note that in the Messages property you configure the message text which is going to be displayed, in this case, is the &response variable which is in the dialog context (the output of the Conversation object).
In sum, the Intent is defined as follows in the Conversationals Flows instance structure:
At runtime, it looks as shown below: