# Dialogflow: Connecting to Dialogflow

Connecting Dialogflow to IS-Messenger is simple as you will only need to retrieve a JSON file from Dialogflow and upload it to IS-Messenger platform.

### Setting Up Dialogflow <a href="#setting_up_dialogflow" id="setting_up_dialogflow"></a>

Prior to generating the Google Service Account Key, you will need to have a Google account to sign into Dialogflow.

In order to set up Dialogflow, we will need to do the following:

* ​[Getting a Dialogflow account​](https://docs.is-messenger.com/ismessenger/workspace-setting/integrations/dialogflow/dialogflow-connecting-to-dialogflow)
* ​[Creating a Dialogflow agent​](https://docs.is-messenger.com/ismessenger/workspace-setting/integrations/dialogflow/dialogflow-connecting-to-dialogflow)
* ​[Connecting to Dialogflow​](https://docs.is-messenger.com/ismessenger/workspace-setting/integrations/dialogflow/dialogflow-connecting-to-dialogflow)

You may skip the step and proceed to the next if you have already performed it.

### **Getting a Dialogflow Account**

**Step 1:** [Navigate to this page](https://dialogflow.cloud.google.com/) and proceed to login with your Google account.

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1664173756431/dialogflow-connecting-1.png" alt="screenshot of dialogflow login page"><figcaption></figcaption></figure>

**Step 2:** Review the terms and check the box. Click Accept to proceed.

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1675309826282/dialogflow-connecting-1.jpeg" alt="screenshot of Dialogflow review account settings popup"><figcaption></figcaption></figure>

{% hint style="success" %}
You have now created your Dialogflow account and you can proceed to the next step, Creating a Dialog Agent
{% endhint %}

### **Creating a Dialogflow Agent**

In Dialogflow, there is a module named **Agent** that acts as the brain of your bot. This component will help your bot understand and classify human languages.

**Step 1:** Once you have logged in, click the dropdown arrow and click **Create new agent** at the side navigation menu.

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1675310009827/dialogflow-connecting-2.png" alt="screenshot showing how to create an agent in Dialogflow"><figcaption></figcaption></figure>

**Step 2:** Give the agent a name for internal reference. Make any necessary changes to the default settings.

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1675310108005/dialogflow-connecting-3.png" alt="how to connect and name your Dialogflow agent"><figcaption></figcaption></figure>

| **Fields** | **Description**                                                                                                   |
| ---------- | ----------------------------------------------------------------------------------------------------------------- |
| Name       | For identification purposes. This name will be used for internal reference only.                                  |
| Language   | The language to be used for Dialogflow's natural language processes. Choose the language of your target audience. |
| Timezone   | The timezone to be adopted for analytics purposes on Dialogflow.                                                  |

{% hint style="info" %}
Note that a new Google Cloud Project will be automatically created to the Dialogflow Agent when created. The Google Cloud Project will be used to connect Dialogflow to IS Messenger
{% endhint %}

**Step 3:** When you are ready, click **CREATE** to create the agent.

{% hint style="success" %}
Now, the Dialogflow Agent is created and you can proceed to connect Dialogflow to IS Messenger
{% endhint %}

### **Connecting to Dialogflow**

Connecting Dialogflow to the IS-Messenger platform is simple as you will only need to retrieve a JSON file from Dialogflow and upload it to the IS-Messenger platform.

**Step 1:** Login using your Google account that is associated with [Dialogflow](https://dialogflow.cloud.google.com/).

**Step 2:** Navigate to the Settings module by clicking the ⚙ icon beside the Agents dropdown menu.

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1664174344597/dialogflow-connecting-5.png" alt="screenshot showing the Dialogflow agent settings"><figcaption></figcaption></figure>

**Step 3:** In the General tab, click the link in the Service Account to view the associated Google Project.

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1664174426332/dialogflow-connecting-6.png" alt="screenshot showing how to navigate to the associated Google Project in Dialogflow"><figcaption></figcaption></figure>

**Step 4:** With the Google Project open, click **Go to project setting**.

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1674197557692/dialog-flow-4.png" alt="screenshot showing Google Project screen and Go to project setting option"><figcaption></figcaption></figure>

**Step 5:** In the **IAM & Admin** menu > Select **Service Accounts**

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1664174697108/dialogflow-connecting-7.gif" alt="gif showing how to select Service Account"><figcaption></figcaption></figure>

**Step 6:** In the Service Account Details screen, name the Service Account and click **CREATE AND CONTINUE**

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1674197816967/image-1-19-23-at-3-48-pm.jpeg" alt="screenshot showing the Service Account Details screen"><figcaption></figcaption></figure>

**Step 7:** Assign the **Dialogflow API Client** role to the service account > click **CONTINUE**

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1674198294996/image-1-19-23-at-3-51-pm.jpeg" alt="screenshot showing how to assign the Dialogflow API Client role to the service account"><figcaption></figcaption></figure>

**Step 8:** The Grant users access to this service account step is **optional**.

**Step 9:** Click **DONE**

**Step 10:** Locate the previously created Service Account and select **Manage Key** from the actions menu.

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1674198529807/image-1-19-23-at-4-00-pm.jpeg" alt="screenshot showing the select Manage Key option from the actions menu."><figcaption></figcaption></figure>

**Step 11:** In the Keys screen, click **ADD KEY** > **Create new key** and select **JSON** when prompted which format of key is preferred > click **CREATE**

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1674198673509/image-1-19-23-at-4-02-pm.jpeg" alt="screenshot showing the Create new key screen"><figcaption></figcaption></figure>

{% hint style="success" %}
The JSON file will be automatically downloaded to your computer's **Downloads** folder.
{% endhint %}

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1674198848887/image-1-19-23-at-4-07-pm.jpeg" alt="screenshot showing where the JSON file will be automatically downloaded"><figcaption></figcaption></figure>

**Step 12:** Log in to IS-Messenger with your user account and navigate to **Settings** > **Integrations**

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1674198955939/image-1-19-23-at-4-10-pm.jpeg" alt="screenshot showing Dialogflow on the platform"><figcaption></figcaption></figure>

**Step 13:** From the list, search for Dialogflow and click **Connect**.

**Step 14:** Select the language of your target audience and upload the JSON file downloaded from **Step 11**.

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1674199097720/image-1-19-23-at-4-13-pm.jpeg" alt="screenshot showing the Dialogflow integration screen on the platform"><figcaption></figcaption></figure>

**Step 15:** Click **Connect** to connect the Dialogflow Agent to the platform.

{% hint style="success" %}
Your Dialogflow Agent is now connected to the IS-Messenger platform. The Agent will start to respond to any incoming messages.
{% endhint %}

{% hint style="warning" %}
Having trouble with connecting to Dialogflow? Contact us [here](https://docs.is-messenger.com/ismessenger/modules/contacts).
{% endhint %}

### Dialogflow Multilingual Agent <a href="#dialogflow_multilingual_agent" id="dialogflow_multilingual_agent"></a>

When creating an agent in Dialogflow, the language you choose is set as the default language. With the Multilingual Agent feature your agent can now support additional languages.

### **How Dialogflow Multilingual Agent works in** IS-Messenger

The Language Field in the contact’s details on the IS-Messenger platform is used in the request sent to Dialogflow. When a request is sent to Dialogflow, the contact's language will be included and Dialogflow will resolve and respond according to the language value.

Example: If the Contact's Language Field is English, the platform will request an *en* response and if the Language Field is Spanish the platform will request the *es* response.

{% hint style="info" %}
Learn more about [Multilingual Agents here](https://cloud.google.com/dialogflow/es/docs/agents-multilingual#add).
{% endhint %}

{% hint style="success" %}
For this to work, you will first need to create a Multilingual Agent in your Dialogflow account.
{% endhint %}

### **How to Create a Multilingual Agent**

To create a Multilingual Agent, follow the steps below.

**Step 1:** In the left sidebar menu, click the **+** button to add another language.

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1674199691607/dialog-flow-1.png" alt="screenshot showing the Dialogflow add language option"><figcaption></figcaption></figure>

**Step 2:** In the **Languages** tab click **Select Additional Language** and select an additional language from the dropdown menu.

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1674199805658/dialog-flow-2.png" alt="screenshot showing the Select Additional Language option"><figcaption></figcaption></figure>

**Step 3:** To add language localization for a specific region, hover over the language and click **+ Add locale**.

<figure><img src="https://files.helpdocs.io/9e3syfbzn8/articles/627bs4x6o5/1674199964667/dialog-flow-3.png" alt="screenshot showing the add localization language option"><figcaption></figcaption></figure>

{% hint style="success" %}
Locale-specific languages are languages that are specific to a region or a country.
{% endhint %}

**Step 4:** Click **SAVE**

{% hint style="success" %}
The Language Field on the platform must be filled for the Dialogflow Multilingual Agent to work. Learn more about [Contact Fields here](https://docs.is-messenger.com/ismessenger/workspace-setting/contact-fields).
{% endhint %}

#### What's next? <a href="#what_s_next" id="what_s_next"></a>

The interaction between Dialogflow Agent and Contact is managed by intents. In summary, intents are used to describe the expected behavior for one conversation turn based on the prescribed incoming behavior.

Read more on how to manage intents:

{% content-ref url="dialogflow-managing-intents" %}
[dialogflow-managing-intents](https://docs.is-messenger.com/ismessenger/workspace-setting/integrations/dialogflow/dialogflow-managing-intents)
{% endcontent-ref %}
