SIGN UP

How to use Dialogflow Connector

How to use Dialogflow Connector

Intro

We have recently introduced connector for Dialogflow that lets connect a call running via Voximplant with a Dialogflow agent, which will do speech recognition and natural language processing (NLP) according to its logic. Audio streaming from Voximplant to Dialogflow happens in real-time, query results arrive to VoxEngine as soon as they are returned by an agent. The only requirement is that Dialogflow agent should be switched to API V2 support since API V1 doesn't support streaming (it has a rather significant impact, so please read the migration guide to avoid problems).

Setting up Dialogflow

After your Dialogflow agent has been switched to API V2 you can download the service account JSON file associated with the agent from GCP console (please read the Setting up authentication article for details). The JSON file is required for Voximplant to be authorized before sending audio data to the agent.

Dialogflow agent setup


Setting up Voximplant

Each Voximplant application can have only one Dialogflow agent associated with it. In Voximplant control panel click on the Settings drop-down menu and choose Dialogflow Connector.

Control Panel - Dialogflow Connector

Click on the Add Service Account link in the left menu, then click the Choose file button and select the JSON file downloaded from GCP console. Bind the service account to an application by clicking the Bind app button. Choose the application in the drop-down list and click the Save button. The Dialogflow agent is now bound to the Voximplant application.

Control Panel - Dialogflow Connector

Now we can use AI module in VoxEngine to send media from calls or conferences to the Dialogflow agent. Please see the example below:

require(Modules.AI)

var dialogflow, call

function sendMediaToDialogflow() {
  call.removeEventListener(CallEvents.PlaybackFinished)
  call.sendMediaTo(dialogflow)
}

function onDialogflowResponse(e) {
  let response = e.response
  if (response.queryResult !== undefined && response.queryResult.fulfillmentText !== undefined) {
  	call.say(response.queryResult.fulfillmentText, Language.Premium.US_ENGLISH_FEMALE)
    call.addEventListener(CallEvents.PlaybackFinished, sendMediaToDialogflow)
  }
}

function onCallConnected(e) {
  dialogflow = AI.createDialogflow({ lang: DialogflowLanguage.ENGLISH_US })
  dialogflow.addEventListener(AI.Events.DialogflowResponse, onDialogflowResponse) 
  call.say("Hi! I'm virtual assistant and I'm ready to help!", Language.Premium.US_ENGLISH_FEMALE) 
  call.addEventListener(CallEvents.PlaybackFinished, sendMediaToDialogflow)
}

VoxEngine.addEventListener(AppEvents.CallAlerting, (e) => {
  call = e.call
  call.addEventListener(CallEvents.Connected, onCallConnected)
  call.addEventListener(CallEvents.Disconnected, VoxEngine.terminate)
  call.answer()
})

This scenario sends media from inbound call to the Dialogflow agent, query results are returned in DialogflowQueryResult events. In the example we just playback the fulfullmentText returned by the agent and then waiting for the next phrase from a caller. DialogflowQueryResult represents Dialogflow's QueryResult object


Demo

You can see the connector in action at https://demos05.voximplant.com/dialogflow-connector. This demo is an example of automated pizza order via a phone call. You can also download the Dialogflow agent from this demo using the following link PizzaOrderDelivery.zip

Tags:ivrdialogflowmachine learningnluainlp
B6A24216-9891-45D1-9D1D-E7359CEB8282 Created with sketchtool.

Comments(0)

Add your comment

To leave a comment, first confirm that you are not a robot. It's free

Recommend

Get your free developer account or talk with our sales team to learn more about Voximplant solutions
SIGN UP
Contact sales

Please complete this field.

Please complete this field.

Please complete this field.

Choose the solution

Please complete this field.

Please complete this field.