Here we introduce the steps to use the Chatbot Generator with Dialogflow.
After the setup in Google Clouds, you need to create an Agent in DialogfLow, where GeneXus will create your chatbot for this provider (create and update the intents, entities, and the dialog itself).
The following is a summary of the steps that should be followed:
Go to this link. Select the list of projects, and create a New Project.
Then, you'll have something similar to this:
In the project's Dashboard, go through APIs & Services -> Library
Then, in the search bar, search for Dialogflow. Select it, and click the Enable button.
Now you have to get the Client ID and Client Secret for accessing the Dialogflow API - which is based on OAuth 2.0 authentication.
In the API&Services menu, select Credentials. Next, in the Credentials screen go through "OAuth consent screen" tab, where you have to enter a Product Name.
After that, still in the Credentials screen, select "Create Credentials," "OAuth client ID."
When it prompts for an Application type, select Other.
Finally, you'll get your Client ID and Client Secret. You'll need it in the steps that follow.
Important: make sure that you copy the credentials that you've just created. The Web application credentials do not work for this, because they require the configuration of a valid redirect URI. You'll get an error HTTP 400 invalid redirect URI if you try to use them.
Go to the Dialogflow web site to create a new Agent. Consider selecting the correct Project (defined in the previous step) before pressing the create Agent button. Note that you can create only one Agent per project.
Edit the Conversational Flows instance and configure the NLP Provider property, Dialogflow Agent property, Google Cloud Project property, Client Id and Client Secret properties.
To continue, save or execute "Generate Chatbot." At this moment, GeneXus will try to synchronize our instance with the agent created in Dialogflow.
First of all, in GeneXus output, you'll see the following the first time you connect to DialogFlow. A browser will be open for you to authorize the app.
========== Chatbot synchronization for CitizenAdv started ==========
error: One or more errors occurred.
So you will notice that the first time it will open a browser instance in which you will be required to log in using your Google account (since it uses OAuth 2.0).
The credentials will be stored in your develpment machine so you won't be asked again to authorize the app. They're stored in a file located under <Users>/<username>/AppData/Roaming/Folder/File and are used for the connection to Google DialogFlow from the IDE.
Folder = DialogflowToken$KBName$$InstanceName$Chatbot
File = Google.Apis.Auth.OAuth2.Responses.TokenResponse-user
When you do the first build, the browser will open again to ask yout to allow access to the application. This is for setting the GXCF_<InstanceName>Chatbot.config file connection credentials.
After starting a new session, the generation or synchronization continues as in other providers.
GeneXus is responsible for refreshing the authentication token so that it is not necessary to log in again (until the refresh token expires). It knows how to refresh the Access Token automatically.