> For the complete documentation index, see [llms.txt](https://atlas.anywhere.now/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://atlas.anywhere.now/product-reference/dialogue-studio/dialogue-studio-example-flows/connect-google-dialogflow.md).

# Connect to Google Dialogflow

Build a voicebot flow in Dialogue Studio that connects to Google Dialogflow for intent detection and intelligent routing.

This example connects Dialogue Studio to a Google Dialogflow agent for natural language understanding in a voicebot. There is no importable flow for this example: build it node by node as described below, using the Dialogflow-specific nodes in Dialogue Studio.

## What it does

The flow greets the caller, transcribes what they say, sends it to a Dialogflow agent for intent detection, and routes the conversation based on the detected intent. This adds a self-service layer to an IVR that can answer questions or route callers based on spoken input rather than DTMF menus.

## Prerequisites

* A UCC configured with Dialogue Studio.
* A Dialogflow agent configured in [Google Dialogflow](https://dialogflow.cloud.google.com/). See [Quickstart: Create, train, and publish your Dialogflow](https://cloud.google.com/dialogflow/docs/quick).
* Transcription configured for the UCC.

When designing your Dialogflow agent:

* **Intents** represent what the caller wants to achieve, for example "I need help with insuring my new car" or "I have a question about my current ticket." Start with two or three intents that are not too similar, each with around 15-20 training phrases and a roughly even number of phrases per intent.
* **Entities** represent specific topics, such as an insurance type, and can include synonyms. The entity's content does not determine the intent, but its presence does. Make sure entities are highlighted in the training phrases if Dialogflow does not do this automatically.

## Configuration

### Bot greeting

![Incoming Call node used to start the Dialogflow flow](https://2627137428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FscZpnEdBjDgQmlVn1iLr%2Fuploads%2Fgit-blob-4e736b379d931a54f23cd00d469921e7079155bb%2Fdialogflow-incoming-call.png?alt=media)

Start with an **Incoming Call** node. It listens for audio/video sessions only. Open it, select or configure your server, and filter on `Audio/Video`.

Next, add a **Say** node to greet the caller and ask their question. Connect the end of the Incoming Call node to the Say node.

### Start the transcriptor

Add a **Transcriptor** node and connect the end of the Say node (or the `otherwise` output of a switch node, if you loop back here) to it. Optionally change the transcription language.

By default, the Transcriptor node keeps listening and restarts after every result. For a Dialogflow integration you want to stop after the first result, since Dialogflow can hold a multi-turn conversation on its own. Add a **Change** node that sets `msg.payload.stop` to `true` (boolean), wired from the transcriptor's events output back into the transcriptor's own input, so it stops itself after producing a transcript.

Add a second **Change** node to store the transcript for later use: set `msg.payload` to `msg.payload.transcriptor.transcript`, wired from the transcriptor's events output.

### Configure the Dialogflow node

Add a **DialogFlow** node and connect the previous Change node to it. This node connects your IVR to the Dialogflow agent.

* **Agent**: select your Dialogflow configuration. If you do not have one yet:
  1. Log in to [Service accounts - IAM & Admin - Google Cloud console](https://console.cloud.google.com/iam-admin/serviceaccounts).
  2. In the project dropdown, select the project of the Dialogflow agent.
  3. Create a service account, or select an existing one.
  4. Switch to the **Keys** tab.
  5. Select **Add Key > JSON**, then **Create**.
  6. Copy the contents of the downloaded JSON file into the JSON field of the DialogFlow configuration node.
* **Session**: set to `msg.session.id`, so the caller stays in the same Dialogflow session instead of restarting the conversation on every turn.
* **Language**: select the language of the bot.

{% hint style="warning" %}
The downloaded service account JSON file is a credential. Store it using your organization's approved secret handling and never paste it into a flow you plan to export, share, or debug.
{% endhint %}

### Handle the response

Add a **Change** node connected to the end of the DialogFlow node with two rules:

* Set `msg.completed` to `msg.payload.diagnosticInfo.fields.end_conversation.boolValue`.
* Set `msg.intent` to `msg.payload.intent.displayName`.

If your intent uses parameters, they are available at `msg.payload.parameters.fields.[parametername].stringValue`.

Add a **Switch** node connected to the end of that Change node, with the property set to `msg.intent`. Add one rule per intent (for example `== ticket_status`), and always add an `otherwise` rule for when Dialogflow did not detect an intent.

You can now continue the flow based on the detected intent. The following optional patterns cover situations you may encounter.

### Optional: play the Dialogflow response

Dialogflow lets you configure a response text per intent, or a prompt for a missing parameter. To play it, add a **Say** node, change it to use an expression, and set the expression to:

```
payload.fulfillmentMessages[0].text.text[0]
```

Connect the end of the previous node to this Say node.

### Optional: handle end of conversation

Dialogflow can mark a conversation as completed, stored earlier in `msg.completed`. Add a **Switch** node with the property set to `msg.complete`, one rule for `true`, and an `otherwise` rule for not yet complete. If not completed, continue with the pattern in [Send another response](#send-another-response) below.

### Optional: handle a missing parameter

If an intent has required parameters that are missing, it is marked incomplete (`msg.complete` is `false`). Add a **Switch** node with the property set to `msg.payload.parameters.fields.[parametername].stringValue`, with one rule for empty and one for not empty. If missing, continue with [Send another response](#send-another-response) below.

### Optional: handle an unknown intent

When Dialogflow cannot detect an intent, it returns the "Default Fallback Intent" along with its own response text, which you can play to prompt the caller to try again. This is also marked as an incomplete conversation. Continue with [Send another response](#send-another-response) below.

### Send another response

For a voicebot, you do not need to do anything extra: the Transcriptor node added earlier keeps listening and sends the next reply to Dialogflow automatically, unless you stopped it, in which case start it again.

## Safe fallback behavior

Always include an `otherwise` rule on the intent Switch node so an undetected intent has somewhere to go, and use the "Default Fallback Intent" response from Dialogflow to prompt the caller rather than leaving them without a reply. The transcriptor's continuous-listening default means a caller who does not trigger a recognized intent gets another chance to respond rather than being disconnected.

## Verification

1. Call the UCC and confirm the greeting plays and the transcriptor starts listening.
2. Ask a question matching one of your configured intents and confirm the Switch node routes to the matching branch.
3. Ask something outside your configured intents and confirm the fallback intent response plays and the caller gets another chance to respond.
4. If using multi-turn intents, confirm the session stays consistent by checking that `msg.session.id` is passed on every DialogFlow node call.

## Related topics

Go to [Dialogue Studio example flows](/product-reference/dialogue-studio/dialogue-studio-example-flows.md) for the full gallery of example flows.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://atlas.anywhere.now/product-reference/dialogue-studio/dialogue-studio-example-flows/connect-google-dialogflow.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
