You can use the Dialogflow reference connection code to connect a Vonage Voice API call to a Google Dialogflow agent and then have an audio conversation with the agent. Speech transcripts and sentiment analysis are posted back to the Vonage Voice API application.
Dialogflow reference connection makes use of the WebSockets feature of Vonage Voice API. When a voice call is established, a Voice API application triggers a WebSocket connection to this Dialogflow reference connection and streams the audio to and from the voice call in real time.
See the sample Voice API application for a using this Dialogflow reference connection code to connect voice calls to a Google Dialogflow agent.
This reference connection code will send caller's speech transcript and sentiment score, and Dialogflow agent's transcript to the Voice API application via webhook calls.
You may already have a Google Dialogflow agent ready, if not, please create one that will be used for the purpose here.
For the next sections, we will need the corresponding Google Cloud Project ID value as well as Google Application Credentials JSON file (actual credentials file name has ".json" extension).
To retrieve them:
- Go to the dialogflow console, go to the relevant Dialogflow agent, click on the gear icon, you will see the Project ID, we will use that value to set the parameter GCLOUD_PROJECT_ID in the next sections,
- To retrieve the application credentials:
click on the Project ID link (as mentioned above),
click on '-> Go to project settings',
'Service Accounts',
'+ CREATE SERVICE ACCOUNT',
enter a name for 'Service account name' , e.g. VonageDF
click CREATE
select 'Dialogflow API' client as role (note: role permissions are beyond the scope of this demo)
click CONTINUE
click DONE
click on the 3 vertical dots (under Actions), Create key, JSON, CREATE, save the created file in your application folder
that key file name (ending with .json) is the value, e.g. mydfagent-vonage-05768e59b7c5.json
we will use that value to set the parameter GOOGLE_APPLICATION_CREDENTIALS in the next sections.
Using your Google Cloud Console, on your corresponding Google project, make sure that both the Dialogflow API and the Cloud Natural Language API are enabled.
You deploy the Dialogflow reference connection code in one of the following couple of ways.
To run your own instance of this sample application locally, you'll need an up-to-date version of Node.js (we tested with version 14.3.0).
Download this sample application code to a local folder, then go to that folder.
Copy the .env.example
file over to a new file called .env
:
cp .env.example .env
Edit .env
file, and set both parameter values:
GCLOUD_PROJECT_ID=
GOOGLE_APPLICATION_CREDENTIALS=xxxxxxxxxxxxxxx.json
Install dependencies once:
npm install
Launch the applicatiom:
node df-connecting-server
You must first have deployed your application locally, as explained in previous section, and verified it is working.
Install git.
Install Heroku command line and login to your Heroku account.
If you do not yet have a local git repository, create one:
git init
git add .
git commit -am "initial"
Start by creating this application on Heroku from the command line using the Heroku CLI:
heroku create thisappname
Note: In above command, replace "thisappname" with a unique name on the whole Heroku platform.
On your Heroku dashboard where your application page is shown, click on Settings
button,
add the following Config Vars
and set them with their respective values:
GCLOUD_PROJECT_ID
GOOGLE_APPLICATION_CREDENTIALS
Deploy the application:
git push heroku master