Dialogflow

connect a call to a Google Dialogflow bot.

1{
2 "verb": "dialogflow",
3 "project": "ai-in-rtc-drachtio-tsjjpn",
4 "lang": "en-US",
5 "credentials": "{\"type\": \"service_account\",\"project_id\": \"prj..",
6 "welcomeEvent": "welcome",
7 "eventHook": "/dialogflow-event",
8 "actionHook": "/dialogflow-action"
9}

Parameters

credentials
stringRequired

The service account key in JSON string form that is used to authenticate to Dialogflow.

lang
stringRequired

Language to use for speech recognition.

project
stringRequired

The Google Dialogflow project ID.

actionHook
string

A webhook invoked when the operation completes.
See below for specified request parameters.

bargein
boolean

If true, kill playback immediately when the user begins speaking.

eventHook
string

A webhook to invoke when a Dialogflow event occurs, such as an intent being detected or a speech transcription being returned.
The response to the event hook may contain a new Jambonz application to execute.

noInputEvent
string

Name of the Dialogflow event to send in query when no input timeout expires.

noInputTimeout
number

Number of seconds of no speech detected after which to reprompt.

passDtmfAsTextInput
boolean

If true, pass user DTMF entries as text inputs to the Dialogflow bot.

thinkingMusic
string

A URL to a .wav or .mp3 file to play as filler music while the Dialogflow back-end is executing.

tts
object

If provided, audio prompts will be played using text-to-speech rather than the Dialogflow-provided audio clips.

tts.gender
string

(Google only) MALE, FEMALE, or NEUTRAL.

tts.language
stringRequired

Language code to use.

tts.vendor
string

Speech vendor to use: Google, AWS (alias: Polly), or default (for application default).

tts.voice
string

Voice to use. Note that the voice list differs depending on whether you are using AWS or Google. Defaults to application setting, if provided.

welcomeEvent
string

An event to send to Dialogflow when first connecting; e.g., to trigger a welcome prompt.

welcomeEventParams
object

An object containing parameters to send with the welcome event.

actionHook properties

The actionHook webhook will contain the following additional parameters:

  • dialogflowResult: the completion reason:
    • redirect - a new application was returned from an event webhook
    • completed - an intent with end iteraction set to true was received from dialogflow

eventHook properties

The eventHook webhook will contain two parameters: event and data. The event parameter identifies the specific event and the data parameter is an object containng event data associated with the event. The following events are supported:

  • intent: dialogflow detected an intent
  • transcription: a speech transcription was returned from dialogflow
  • dmtf: a dtmf key was pressed by the caller
  • start-play: an audio segment returned from dialogflow started to play
  • stop-play: an audio segment returned from dialogflow completing playing
  • no-input: the no input timer elapsed with no input detected from the caller

Please refer to this tutorial for a detailed example.

call transfer in Dialogflow

Call transfer from a dialogflow bot is achieved by responding to an eventHook with event intent by returning a new jambonz application containing a dial verb. Of course, this should only be done if the intent is signaling a request for a call transfer.

Indicating a desire to transfer the call to a live agent can be done in a couple of different ways in the dialogflow editor:

  1. By adding a Dialogflow Phone Gateway Response to the intent, with a Transfer Call action.
  2. By adding a custom payload in a response to the intent, with arbitrary JSON content that you define and which should include the telephone number (or registered user, or sip endpoint) to transfer to.

Note: option 1 only works when transferring to a US number, because the dialogflow editor only accepts US destinations. To transfer to non-US destinations, use option 2.

In either case, your application is responsible for having an eventHook that parses the intent (found in the data property of the webhook content) in order to check if call transfer is being requested, and if so responding with a new jambonz application.

For instance, when the Dialogflow Phone Gateway Response is used (option 1 above), the code snippet below shows where to find the transfer number in the intent data provided in the eventHook.

1const evt = req.body;
2if (evt.event === 'intent') {
3 const qo = evt.data.query_result;
4 const transfer = qo.fulfillment_messages.find((fm) => {
5 return fm.platform === 'TELEPHONY' && fm.telephony_transfer_call;
6 });
7 if (transfer) {
8 // a transfer has been requested
9 // transfer.telephony_transfer_call.phone_number has the phone number to transfer to
10 }
11}