Dialogflow
Bot integration with Dialogflow supports the following types of messages:
TEXT
IMAGE
DOCUMENT
MENU
QUICK_REPLY
FORM
Text message
To define a text response, simply select "Text Response" from the possible response options and type one or more messages.
Image message
To return an image as a response, first you need to add a channel that supports this type of response (eg. Facebook), then select the "Image" type response and configure it with the url that must be called to return the image.
The url can contain a link to an image on the internet or it can be a web service that returns an image.
It is also necessary to configure some parameters for correct image processing. Being able to return multiple messages, even of different types, for the same intent, the parameters must end with a number corresponding to the position of the response in the sequence of configured responses.
Property | Required | Description |
---|---|---|
messageType | yes | Indicates the type of response: in this case must be “image” |
fileName | yes | File name including extension |
caption | no | Caption of the image |
Example
Response configured with an image, a text message and another image in this exact order.
Document message
To return a document as a response, we use Dialogflow “Image” response (eg. from Facebook or Telegram channel), with the url that returns the document and configured with the following parameters:
Property | Required | Description |
---|---|---|
messageType | YES | Indicates the type of response: in this case must be “document” |
fileName | YES | File name including extension |
Being able to return multiple messages, even of different types, for the same intent, the parameters must end with a number corresponding to the position of the response in the sequence of configured responses.
Example
Response configured with a text message, a document, a text message and another document in this exact order.
Menu message
Dialogflow provides the ability to return menus where each option results in a clickable button.
To create a menu, the "Card" type message is used (eg. from Facebook or Telegram channel).
The title of the card is used as the header of the menu, also the subtitle can be configured, while for each single option the relative label and its value are configured, which can be a link to open a new page or a phrase which, if chosen as an answer, will be sent back to the bot.
Finally, if the configured option is a url, an additional parameter is required (that must end with a number corresponding to the position of the option in the sequence of configured options of the menu) called target, to specify where to open the link.
Property | Required | Description |
---|---|---|
target | YES | The target attribute specifies where to open the link. Possible values:
|
To be able to insert more than 3 menu items, since the card allows you to insert a maximum of 3 options, it is necessary to follow the procedure below:
Add another "card" type response
Fill in the "title" field with the SAME title inserted in the original card (this is to link the options of the two menus together in a single menu)
As for the options, the same general rules of the menu apply, so, for example, in the case of url, a parameter called "target _ <# num>" must be added, with the number <#num> corresponding to the menu item that represents the url (with numbering starting from 1) and whose value corresponds to the location where you want to open the url.
Example
Menu with 7 options, including 4 url in positions 2,3,4,7 and 3 queries to the bot.
Quick reply (Whatsapp interactive button)
To configure a quick reply, select a channel that supports this type of response (eg. Telegram), then select the "Quick Replies" type response and configure it with the title and the text options. A maximum of 3 options are allowed. In addition, it’s possible to add header and footer to the response using the following parameters:
Property | Required | Description |
---|---|---|
header | no | Header of the quick reply |
footer | no | Footer of the quick reply |
Example
Quick reply configured with header, footer, title and three options:
Form
To return a form as a response, we use “Custom Payload” to configure the object structure sent.
So, remove the text response and click on the button “Add Responses” and select the option “Custom Paylod” to define the object structure.
The object must have all the following parameters (all required):
Property | Type | Description |
---|---|---|
response_to_bot | string | Query sent back to the bot after the form is submitted by the customer |
title | string | title of the form to be displayed |
type | string | must be equal to “form” |
formData | array | array of objects representing the inputs of the form. See table below for details |
formData Object
Property | Type | Description |
---|---|---|
customMandatoryErrorMessage | string | label to be displayed in case a mandatory input is not submitted by the customer |
isVisibleAgent | boolean | indicates if the content is intended or not to be shown to agent for privacy reason |
mode | string | it describes how to use the value field. “manual” the value is used as default value, “auto” it's evaluated as a JS function |
name | string | key name of the input field (must be unique) |
isEditable | boolean | False if user is not allowed to change default value, true otherwise |
isMandatory | boolean | true if the field is required, false otherwise |
dc_type | string | Type of field. Supported values are:
|
value | string | if mode is manual it has to be set with an empty string (then it will contain the customer response), if auto it's evaluted as a JS function returning a value |
custom_regexp | string | Regular expression for validating input |
isVisibleCustomer | boolean | indicates if the field is intended or not to be shown to the customer. (eg: a field with mode “auto” could be hidden) |
label | string | field label to be displayed |
customValidationErrorMessage | string | label to be displayed in case an input is not valid according to the custom_regexp configured |
Example
Example of custom payload:
{
"response_to_bot": "operatore",
"title": "Titolo Form",
"type": "form",
"formData": [
{
"customMandatoryErrorMessage": "Nome obbligatorio",
"isVisibleAgent": true,
"mode": "manual",
"name": "name",
"isEditable": true,
"isMandatory": true,
"dc_type": "text",
"value": "",
"custom_regexp": "",
"isVisibleCustomer": true,
"label": "Nome",
"customValidationErrorMessage": ""
},
{
"isEditable": true,
"isVisibleAgent": true,
"custom_regexp": "",
"value": "",
"mode": "manual",
"name": "surname",
"isMandatory": true,
"customValidationErrorMessage": "",
"customMandatoryErrorMessage": "Cognome obbligatorio",
"isVisibleCustomer": true,
"dc_type": "text",
"label": "Cognome"
},
{
"isVisibleCustomer": true,
"dc_type": "email",
"value": "",
"isMandatory": true,
"customValidationErrorMessage": "Email non valida",
"mode": "manual",
"isEditable": true,
"label": "Email",
"customMandatoryErrorMessage": "Email obbligatoria",
"isVisibleAgent": true,
"name": "email2",
"custom_regexp": ".*@.*"
}
]
}