This article will show you how to connect a Dialogflow ES agent to inbound and outbound calls and transfer a call from a Dialogflow bot to an operator.
Dialogflow is a virtual agent that handles conversations with your end-users. It is a natural language understanding module that understands the nuances of human language.
Dialogflow ES is the standard agent type suitable for small to medium businesses and simple to moderately complex agents.
Use the Dialogflow connector to connect a call running via Voximplant with a Dialogflow agent, which does speech recognition, natural language processing (NLP), and speech synthesis according to its logic. Audio streaming from Voximplant to and from Dialogflow happens in real-time and query results arrive at VoxEngine as soon as they are returned by an agent.
Inbound and outbound calls
Set up Dialogflow
Recheck that your Dialogflow agent uses API V2. Now create and download the service account JSON file associated with the agent from the GCP console (please read the Set up authentication article for details). Choose the "Dialogflow API Client" role while creating the service account. Voximplant requires the JSON file for authorization before sending audio data to the agent.
Click on the Speech tab in the agent settings to set up Speech synthesis options.
Enable Automatic Text to Speech by clicking on the toggle button and choose MP3 or OGG in the Output Audio Encoding dropdown (IMPORTANT: only MP3 and OGG are currently supported) and one of the available voices. We highly recommend that you use WaveNet-powered voices, since they sound much better than standard options. Save settings by clicking the Save button in the top right corner.
Set up Voximplant
In the Voximplant control panel, go to your application and switch to the Dialogflow connector tab. Here, click Add in the center of the screen or Add Dialogflow agent in the upper right corner.
The Add Dialogflow agent dialog then appears; next click the Choose a file button or drag-drop the JSON file downloaded from the GCP console and click the Add button. After the file is uploaded, you can see a newly added agent in the list:
You can also visit Marketplace in the main menu to deploy an application and a test phone number connected to your Dialogflow agent – to do so, click Install in the appropriate tile. Then follow the instructions to do a test call and be connected to the Dialogflow agent.
If something went wrong, you might have to delete the test application in the Applications section and the test scenario in the Scenarios section of the control panel before you try to create the test application again. Their names start with DF_ (for scenarios) or df- (for applications).
- Please note that the default test application can work with an agent that supports English. If your Dialogflow agent uses another language, please change the test Voxengine scenario accordingly.
Using a real phone number is required as a caller ID to make calls to the phone network from Voximplant. Create an app in the Voximplant control panel and a scenario inside the app, then buy a phone number and attach it to this app. After that, create a rule that forwards all the calls from the number you bought to the scenario.
If you choose a number in a country where no special verification is required (for example, in the United States), then you can make calls straight away. Otherwise you will get a notification to upload verification documents required by the authorities in the country. It takes time before the number becomes active if all the submitted verification documents are correct.
We start with inbound calls.
The scenario should look like this:
This scenario sends media from an inbound call to the Dialogflow agent, query results are returned to the DialogflowResponse event.
Since we have enabled Speech Synthesis in the Dialogflow agent settings there is the DialogflowPlaybackStarted event after each DialogflowResponse event containing queryResult with fullfilmentText. It indicates that the audio stream with generated speech is being played. DialogflowResponse represents Dialogflow's QueryResult object.
To launch the scenario, you just have to call the number you purchased a few steps ago.
You can see the connector in action on https://demos05.voximplant.com/dialogflow-connector. This demo is an example of an automated pizza order via a phone call. You can also download the Dialogflow agent from this demo via the following link PizzaOrderDelivery.zip.
Modify scenario for outbound calls
Change the scenario to make it work with outbound calls:
Run the rule
You can initiate an outbound call programmatically via the StartScenarios method of the Management API or you can run the rule from the control panel. While in your application, switch to Routing on the left menu and click Run rule:
The "Run rule" dialog is displayed. In the dialog specify a callee's phone number in Script Custom Data and click the Run rule button to initiate a call.
If everything is correct, the call arrives at the specified phone number and you hear a greeting from your agent.
You can also use CallLists if you need to initiate many calls.
Transfer a call from a Dialogflow bot to an operator
Use the Dialogflow connector to connect a call running via Voximplant with a Dialogflow bot and control the bot’s behavior. Audio streaming from Voximplant to Dialogflow and back is in real-time, query results arrive at VoxEngine as soon as the agent returns them.
Set up Dialogflow
Go to https://dialogflow.com/ and create a new agent. Let’s name it "ToOperator", for example, and click Create.
After that, you need to set up your entities. Our bot reacts to the word "operator" and its synonyms: agent, live person, real person. In the Intents tab, enter the parameter name that is used in our code, and choose the entity created earlier. Then add some training phrases so Dialogflow can just find and highlight the needed words and assign correspondences in the returned JSON. The more phrases you add, the better.
Voximplant uses the JSON file to perform authorization before sending audio data to the agent. Create and download the service account JSON file associated with the agent from the GCP console (please read the Set up authentication article for details). Choose the "Dialogflow API Client" role when creating a service account.
Set up Voximplant
In the Voximplant control panel, go to your application and switch to the Dialogflow connector tab. Here, upload the JSON file downloaded from the GCP console and click the Add button.
Now you have to create a user (an operator) to whom you make calls. The user should be online when you call. If you are calling from the web, create a second user (a callee). The users can log in here at https://phone.voximplant.com/.
Now you need to create a rule, a scenario, buy a number, and bind them all together. The JavaScipt code sample of how to transfer a call to an operator is as follows: