Dialogflow
Dialogflow
The dialogflow
verb connects a call to a Google Dialogflow bot.
{
"verb": "dialogflow",
"project": "ai-in-rtc-drachtio-tsjjpn",
"lang": "en-US",
"credentials": "{\"type\": \"service_account\",\"project_id\": \"prj..",
"welcomeEvent": "welcome",
"eventHook": "/dialogflow-event",
"actionHook": "/dialogflow-action"
}
You can use the following attributes with the dialogflow
verb:
Option | Description | Required |
---|---|---|
project |
The Google Dialogflow project ID. | Yes |
lang |
Language to use for speech recognition. | Yes |
credentials |
The service account key in JSON string form that authenticates to Dialogflow. | Yes |
welcomeEvent |
An event to send to Dialogflow when first connecting; e.g., to trigger a welcome prompt. | No |
welcomeEventParams |
An object containing parameters to send with the welcome event. | No |
noInputTimeout |
Number of seconds of no speech detected after which to reprompt. | No |
noInputEvent |
Name of the Dialogflow event to send in the query when no input timeout expires. | No |
passDtmfAsTextInput |
If true , pass user DTMF entries as text inputs to the Dialogflow bot. |
No |
thinkingMusic |
A URL to a .wav or .mp3 file to play as filler music while the Dialogflow backend is executing. |
No |
actionHook |
A webhook to invoke when the operation completes. See below for specified request parameters. | No |
eventHook |
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 Zerpia application to execute. | No |
tts |
If provided, audio prompts will be played using text-to-speech rather than the Dialogflow-provided audio clips. | No |
tts.vendor |
Speech vendor to use: Google , aws (alias: polly ), or default (for application default). |
No |
bargein |
If true , kill playback immediately when the user begins speaking. |
No |
tts.language |
Language code to use. | Yes |
tts.gender |
(Google only) MALE , FEMALE , or NEUTRAL . |
No |
tts.voice |
Voice to use. Note that the voice list differs whether you are using AWS or Google. Defaults to application setting, if provided. | No |
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 withend iteration
set totrue
was received from Dialogflow.
The eventHook
webhook will contain two parameters: event
and data
. The event
parameter identifies the specific event, and the data
parameter is an object containing event data associated with the event. The following events are supported:
intent
: Dialogflow detected an intent.transcription
: A speech transcription was returned from Dialogflow.dtmf
: 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 completed playing.no-input
: The no-input timer elapsed with no input detected from the caller.
—
Call Transfer in Dialogflow
Call transfer from a Dialogflow bot is achieved by responding to an eventHook
with event intent
by returning a new Zerpia 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 ways in the Dialogflow editor:
- By adding a Dialogflow Phone Gateway Response to the intent, with a **Transfer Call** action.
- 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) to check if call transfer is being requested. If so, it should respond with a new Zerpia 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
.
const evt = req.body;
if (evt.event === 'intent') {
const qo = evt.data.query_result;
const transfer = qo.fulfillment_messages.find((fm) => {
return fm.platform === 'TELEPHONY' && fm.telephony_transfer_call;
});
if (transfer) {
// a transfer has been requested
// transfer.telephony_transfer_call.phone_number has the phone number to transfer to
}
}