The purpose of the Chatbot generator is to automatically build and deploy a chatbot to any of the supported Chatbot providers.
A Pattern called Conversational Flows exists under the Patterns node of the Preferences view in GeneXus.
You have to define a Conversational Flows instance to create your chatbot, and configure the least necessary settings: NLP Provider property and the Provider credentials depending on the AI provider you're using. See Configuring GeneXus for using the Chatbot Generator.
Then, define the Flow of a Conversational instance which setup the conversation.
You can create as many instances as needed by your application.
To create a chatbot, you just need to design the model and the pattern will generate automatically all the objects needed to solve the conversation between the user and the AI provider.
The purpose of the objects generated by the chatbot generator pattern, is to digest the messages received from the user, and build the query to be sent to the AI provider. Then the response is handled through a handler and the result is shown to the user. The result can be a text message, or a GeneXus object with a graphical interface. See Chatbots architecture.
More specifically, when you select the Generate Chatbot menu option for the first time, a module is automatically created (you will have a module for each Conversational Flows instance in the KB).
This module contains the definition of all the objects automatically generated by the Chatbot generator.
In the Build process, the objects are generated if it is needed so (if the chatbot instance has changed so it's needed to generate new objects). All the objects of the instance are generated in that case.
Callers of the UI objects:
In particular, the <InstanceName>WebUI object, is a main webpanel which calls the "PanelChatWeb" object.
Similarly, the <InstanceName>SDUI object, calls the "PanelChatSD" object for the corresponding instance.
Note: The way to call the PanelChatWeb or PanelChatSD is as follows.
CommonChatbots.PanelChatWeb(Chatbot.Conversational.Watson, !"CitizenService") // You can use any provider through the Chatbot.Conversational domain. The second parameter is the instance name.
Handler object: The handler is the service that is responsible for "routing" the user's query to the procedure that was generated to comply with the intent to which it corresponds. The Handler is executed after the query is sent to the provider, so that it has the necessary data to know where to redirect. It's a generated object.
xxBot objects: These are the procedures to which the Handler "routes". They take the name of the Conversational Object of the bot, plus "bot". They are generated based on the defined flows. They know how to interpret the context to decide when they have to execute the conversational object associated with their flow (with the appropriate parameters).
xxComponent & xxComponentSD: These are the automatically generated components for flows that have a component type response (for Web and SD).
Another module, called CommonChatbots is created which contains all the pattern resources. The Web resources are imported automatically for the first time, when the first conversational flows instance is created in the KB. The SD resources are imported when you set the Enable SD UI Generation property to TRUE for any instance, and they do not already exist in the KB.
Then, the resources are updated depending on what you configured in the Keep Resources Updated property.
In the Build process (only if the Conversational Flows instance has any change necessary to generate), and in the Generate bot action, it is checked whether the resources have any change in comparison with the version of the resources that you have in the KB, and depending on the Keep Resources updated property, they are updated or not.
In sum, the pattern generates some objects, which are included in the module of the instance, and there are other objects (resources) which are in the "CommonChatbots" module. The last, can be modified as you desire, as they are updated only if you configure the pattern settings to do so (Keep Resources Updated property).
The pattern uses an external Module where the services which interact with the AI API are defined. It contains the necessary services to communicate with the different providers.
The Chatbot module is automatically installed in the KB, when you create a Conversational Flows instance. You can check if it's installed (and updated) going through the menu "Knowledge Manager -> Manage Module References". It is automatically updated in the Build process and through the Generate chatbot action, when it's neccesary to do it (when it isn't updated in the KB).
The module contents are those procedures and SDT's exposed to be used by the GeneXus user (e.g.:SendEntityValues) procedure.
On the AI provider side, the pattern generates the Intents, Entities, and the Dialog to setup the conversation. See Conversational Flows pattern settings for more information.
Saving the instance:
When you save the instance, the dialog is synchronized to the Provider to update the conversational model.
The Chatbot generator generates a JSON file located under the model's directory: <KB_Directory>\Model\bot\. This JSON file is POST to the Provider, to create or update the Workspace. This is done when you save the instance, or when you execute the Synchronize Chatbot menu option.
There are many changes of the instance that do not requiere a Build. For example, if you only add a Trigger Messages for example, it's enough to save the instance!
In the Build process, the pattern instance is refreshed (the objects are generated), if it's needed so.
Generate Chatbot action:
See Generate Chatbot menu option.
The connection to the Chatbot Provider is done using the credentials given (this depends on the Provider).
An XML file called <Conversational Flows instance name>.config is generated under the web directory, which contains the credentials to connect to the AI service at runtime. This file is generated when the instance is saved (or when you execute the Synchronize Chatbot menu option). It is also generated if it doesn't exist under the web directory, when you build the application. In this case, Genexus doesn't connect to the AI Provider to check the credentials configured at the instance.
Note: The following warning is displayed when the Chatbot provider's configuration is empty.
Warning: The user and password for the Watson conversation service are empty. The workspace is not going to be uploaded to Watson conversation.
Client Id for <InstanceName> Conversational Flows Instance is Empty.
Client Secret for <InstanceName> Conversational Flows Instance is Empty.
In the case of Web Chatbots, check the Web Notifications and Progress UC requirements because Web notifications are used. The client does not wait for the server for a response, asynchronous calls are executed for a better user experience.