Dialogflow Intents and Entities
Dialogflow is Google's Natural Language Processing offering. It supports a wide variety of European and Asian languages. Full documentation is available on the Dialogflow site.
Before attempting to work with Dialogflow's entities, make sure you have a solid understanding of how Slots and Intent and Entity Mapping work.
Before linking up your intents and entities, be sure to first connect your Dialogflow agent's Cloud Configuration to your bot.
The first step is to fetch your agent's intent name. To do this, launch Dialogflow, select the agent whose intents you are using and click Intents in the side navigation.
Here you can see all the intents associated with this agent. These are the intent names you will need to use in the Stackchat Bot Builder.
To trigger navigation to a Stackchat flow when this intent is detected, open the Configure AI dialogue for the Flow you want to navigate to.
In Dialogflow, find the name of the intent you want to connect. Be sure to copy it exactly, as it is case-sensitive.
Click the Add Intent button and paste the intent name into the new text box in the overlay.
Now, you can enter the entities associated with that intent. You can see all the entities associated with an intent by clicking on it in Dialogflow.
Whereas intents represent the user's overall intention in their utterance, entities represent key words in the utterance that we want to extract. There are two types of entities in Dialogflow, custom entities (those created by you) and system entities (pre-built entities provided by Dialogflow in order to facilitate handling the most popular common concepts).
Custom entities are no more difficult than dealing with the intent, in that it is a one-to-one mapping between Dialogflow and Stackchat. For example, in the Weather intent used above, there is one custom entity, @Forecast_type
.
Copy the text found in the VALUE column of Dialogflow for the entity you are mapping, omitting the $
.
Click the + button Aad paste that value into Stackchat and select the Stackchat slot you wish to map it to. In this example, the Stackchat slot has the same name as the Dialogflow entity to prevent confusion.
System entities can be identified by the sys.
prefix on the entity name and there are two main types of system entities, distinguished by their structure. A system mapping entity is populated with a primitive data type and a system composite entity is populated with an object.
There are a few extra steps involved to link a system composite entity to a Stackchat slot. It is recommended that you review the full list of Dialogflow System Entities to become familiar with how they work.
System mapping entities are added to Stackchat in an identical manner to custom entities. An example from the intent above is @sys.geo-city
. This entity identifies cities in utterances (as the name suggests) and is populated by a string representing the city name that was detected.
To map this sytem entity to a Stackchat text
slot, the VALUE can be placed in the entity field in Stackchat, again omitting the $
.
System composite entities (i.e those populated with an object) have more than one piece of information that can be mapped to Stackchat slots. These require a different slot configuration.
From the intent we have been looking at so far, an example of a system composite entity is @sys.date-period
.
Let's take a look at its response in the Dialogflow System Entity Documentation.
Name | Descriptions | Examples | Returned Data Type | Returned Object Example |
---|---|---|---|---|
@sys.date-period | Matches a date interval | April | Object: Strings in ISO-8601 format | {"startDate":"2018-04-01T12:00:00-06:00","endDate":"2018-04-30T12:00:00-06:00"} |
In the Returned Object Example column, we can see that this system entity returns two distinct values, "startDate" and "endDate".
We cannot populate a Stackchat slot with the date-period object, but we can populate Stackchat slots with the properties of the object, which in this case are date-period.startDate
and date-period.endDate
.
This format is consistent across all system composite entities in Dialogflow: entityname.specificdatapoint
.
And since there are two data points sent from Dialogflow to Stackchat, we will need to map these to two Stackchat date
slots. The image below shows how to best store this information.
Aside from checking the Dialogflow System Entity Documentation, another great way to look at the output of a system composite entity is by viewing the Diagnostic Info in the Dialogflow preview pane.
Here, the utterance is "Weather in Dayton next week."
Now click Diagnostic Info.
Here in the Raw API Response we can see both a system mapping entity ("geo-city": "Dayton"
) and the system composite entity date-period
with its two components startDate
and endDate
.