# Dialogflow

With Dialogflow, you can pre-set some frequently asked questions, and your bot can deal with the simple queries on behalf of you and transfer the difficult. Besides, you can train your bot to understand more human language including greeting, gratitude, basic interaction, etc.

### Setup Dialogflow <a href="#setup-dialogflow" id="setup-dialogflow"></a>

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2F4uQA8kRqYGeIc8vq3jJG%2Fimage.png?alt=media&#x26;token=b6abce9a-ec03-4502-a547-1e5c3c23fd64" alt=""><figcaption></figcaption></figure>

On your dialogflow dashboard, click on the gear icon and then click on your project URL,

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FbpL912se6ityEql1n8wn%2FUntitled.png?alt=media&#x26;token=06fd8ed7-307a-450f-8963-18ae4f34b07e" alt=""><figcaption></figcaption></figure>

Click on the top-left corner and open the options. Scroll down and click on “IAM & Admin” settings and then to “Service Accounts”

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FSTFOB2guIVwW7QyInDtW%2Fimage.png?alt=media&#x26;token=f3862296-912e-4d70-adcb-5d89a4bd73e2" alt=""><figcaption></figcaption></figure>

Click on “Create Service Account”. Follow the process below.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2F7m2ONlOkKOfyGcMuT8kO%2Fimage.png?alt=media&#x26;token=efb9e5e5-af1a-4b39-8d78-713a70803bce" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2F0olDAkVRI7JiejNDnoLK%2FUntitled.png?alt=media&#x26;token=28cf370a-e1d3-4193-ada6-307b94e4834d" alt=""><figcaption></figcaption></figure>

Afterwards, click on Manage Keys to create a key.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FYNb2RCkrlAnGrZ2TA2B5%2Fimage.png?alt=media&#x26;token=62dfa8fe-2128-4ac4-b0c3-8cfc77e76b5f" alt=""><figcaption></figcaption></figure>

Click on “Add Key”

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FSdhh5ndrh39Dja9zj33M%2Fimage.png?alt=media&#x26;token=22cdc35d-5d9d-497a-a8ea-58b014eb231a" alt=""><figcaption></figcaption></figure>

This will download a JSON file for you. You can then upload this directly on Rapidbott.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FP1fkyjorTm9iisffqjP0%2Fimage.png?alt=media&#x26;token=681b7ac6-62e1-4b47-aeed-fd406218c4b5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FzG91riUjpYBb7TvuPVAD%2Fimage.png?alt=media&#x26;token=62f15d7b-d252-43fe-9a64-9a2dc5a062ba" alt=""><figcaption></figcaption></figure>

Click on Sync Agents once after the integration is completed.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FiYqpjXwVi3yDDID4Ke6R%2Fimage.png?alt=media&#x26;token=099464f4-95aa-46a9-b7ef-eb174c7d89f1" alt=""><figcaption></figcaption></figure>

### Use Dialogflow <a href="#use-dialogflow" id="use-dialogflow"></a>

Choose one of your flows that you would like your Dialogflow agent to manage.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FuyB8ju0H7JN56TI9C7GC%2Fimage.png?alt=media&#x26;token=0084b6f9-498f-4287-b4f4-aeb7a881999d" alt=""><figcaption></figcaption></figure>

In the workspace of the flow,

1. click "Automation" on the left sidebar
2. activate the "default Reply"
3. select frequency, usually "Every Time".
4. click "Choose Sub Flow"

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2F2tDMD0pQA4CteP5DSZ7I%2Fimage.png?alt=media&#x26;token=b78b2d7b-aa70-48c6-90c2-44764d559747" alt=""><figcaption></figcaption></figure>

Select your agent and you are then able to manage your FAQs. Enter FAQ interface by clicking the "Manage Faqs" button as below:

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FaQMoCtENSVYPTonHe3Dy%2Fimage.png?alt=media&#x26;token=b64a7471-93a9-47fe-bb76-4ccbc8aedaae" alt=""><figcaption></figcaption></figure>

This is how the FAQ interface looks like:

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FSXls1P3bZmfVH3WySep4%2Fimage.png?alt=media&#x26;token=03655364-2e21-4285-99a5-e80572dbb8c5" alt=""><figcaption></figcaption></figure>

The "Sync Product Entity" button is for Ecommerce usage. By synchronizing product information in your Ecommerce system with Dialogflow, you can then recognize and reply to related products when users ask about them. To quote a product name, type "{{"to see the picture below

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FUlrMwAFsMhkKlPZD0ukP%2FUntitled.png?alt=media&#x26;token=05f2d89b-16a6-42e4-b4ca-e0f5cbb00152" alt=""><figcaption></figcaption></figure>

Click "+ New Faq" to start building your smart dialog:

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FgMmaX7bYi9wD4ol0NSD5%2FUntitled.png?alt=media&#x26;token=bbe345f8-ee0a-4fbe-a77c-a49f0e933013" alt=""><figcaption></figcaption></figure>

For each frequently asked question, put as many synonymous sentences as you can in the question area and Dialogflow will help with the rest.

You don't need to worry about too many details because Dialogflow is using fuzzy matching. For example, you have already put "When is your office hour?" and "When do you open?". The bot can recognize it is asking about opening hours whatever user send "office hour?", "when u open?", etc even there is any abbreviation or grammar mistake.

The answer area is telling the bot what to reply when a question matched. The bot will randomly pick one answer from the answer list to send.

In "Send sub flow" area, choose a sub flow if needed. The sub flow will be sent just after the answer.

Finally, click "Save" and here you go, 🎉 your first FAQ has done. The bot is now understanding more human language! Keep testing and improving it.

### Improve Dialogflow <a href="#improve-dialogflow" id="improve-dialogflow"></a>

Back to [Dialogflow Website](https://dialogflow.cloud.google.com/), you will see Rapidbott created many FAQ intents on behalf of you:

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2Fzh5iKc25W7r2CBmP2NvR%2Fimage.png?alt=media&#x26;token=94b52e63-2b24-45f3-8ddc-7b86ee1a2e6c" alt=""><figcaption></figcaption></figure>

1. choose your agent
2. click "Intents"
3. these are the intents synchronized from Rapidbott
4. Test your bot here, see whether it understand which FAQ you are asking about.

Check and adjust "Default Fallback Intent" or "Default Welcome Intent" if needed. "Default Fallback Intent" is matched when none of the FAQ is matched.

Select any intent, give it some more editing to help the bot understand more:

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2F4EjjoOYBsEoY5fyjFXEy%2FUntitled.png?alt=media&#x26;token=6a20fe9f-769f-4414-9a63-1492cf588067" alt=""><figcaption></figcaption></figure>

For example, in this case, double click to select "Melbourne", then enter the keyword "city", click on "@sys-geo-city". This is telling the bot that the word "Melbourne" is a city. So next time when users asking "Can you deliver to Sydney?" or other cities, the bot can file the question to this FAQ.

There are various practical built-in lexicon includes color, time, post-code, country, street name, language, etc. You can even create your own!

### Dynamic Content Response <a href="#dynamic-content-response" id="dynamic-content-response"></a>

Response answer is not limited to just text. Try custom payload!

To begin with, create a FAQ in Rapidbott with only questions, no answer or sub flow.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FHuKHYSahsFK5JitOlrkb%2FUntitled.png?alt=media&#x26;token=98870374-b618-478d-82a2-aac667da953f" alt=""><figcaption></figcaption></figure>

Wait a moment and refresh your Dialogflow intents until the new intent shows.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FHYMqpjgRp1wAy46eL9nE%2FUntitled.png?alt=media&#x26;token=9ad5261e-cb57-42ec-902a-834f0748e39b" alt=""><figcaption></figcaption></figure>

In the new intent, click area 4, "ADD RESPONSES", then "Custom Payload". Copy and paste any needed [response format](https://docs.rapidbott.com/help-center/developers/dynamic-content) here, such as text/media/files, buttons, actions, quick replies and so on so forth.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2Fu6qqTKcoAz4F2p3Jps3C%2Fimage.png?alt=media&#x26;token=321f8512-fe32-4257-99bd-5e3a308f7ece" alt=""><figcaption></figcaption></figure>

In this case, a call button will be sent. So copy the following code to Dialogflow:

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FB9hLbte7WCFVZfdIP1vZ%2FUntitled.png?alt=media&#x26;token=fb0960f6-e383-4b0a-a628-a48bfc8708f9" alt=""><figcaption></figcaption></figure>

Adjust text, button title, number, etc as needed and click "Save":

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FkTzwIqyViVF1PTbnRjJZ%2FUntitled.png?alt=media&#x26;token=31af8d83-688c-4dfd-af53-edddd5ed8a1f" alt=""><figcaption></figcaption></figure>

Let's test it from the testing area on the right:

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FEl5u7feCTMBjbOqPjfr2%2FUntitled.png?alt=media&#x26;token=5bbeaf3b-a83e-4c9f-a477-e8f05bcb094c" alt=""><figcaption></figcaption></figure>

Well done! the bot recognizes that "can I call" is asking faq3.20.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FWmitjCHjeX47yoWFmz4C%2FRB%20Support.png?alt=media&#x26;token=ae2c4c84-4ffd-401e-8993-6cfd7233ebb8" alt=""><figcaption></figcaption></figure>

The user side looks perfect as well. Feel free to explore other response types!
