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.

Dialogflow Intents list

*A Dialogflow agent with 9 intents.*

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.

Dialogflow AI Configuration Location

*The Configure AI button in the Graph View.*

In Dialogflow, find the name of the intent you want to connect. Be sure to copy it exactly, as it is case-sensitive.

Dialogflow Copy Intent from Dialogflow

*An exact match including case is required.*

Click the Add Intent button and paste the intent name into the new text box in the overlay.

Dialogflow Paste Intent to Stackchat

*An exact match achieved.*

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.

A Dialogflow Custom Entity

*You can assign whatever name you wish to custom entities.*

Copy the text found in the VALUE column of Dialogflow for the entity you are mapping, omitting the $.

Dialogflow Entity Value

*Do not forget to omit 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.

Dialogflow Entity Connection to Slot

*Dialogflow VALUE pasted into Stackchat.*

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.

Dialogflow System Entity

*System entities all begin with `"sys."`.*

To map this sytem entity to a Stackchat text slot, the VALUE can be placed in the entity field in Stackchat, again omitting the $.

Dialogflow System Entity in Stackchat

*Remember that this is case sensitive.*

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.

Complex Dialogflow System Entity @sys.date-period

*`@sys.date-period` has two parts.*

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.

Complex Dialogflow System Entity Mapped to Slots

*Everything is still case sensitive.*

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."

Complex Dialogflow Preview

*Utterance is at the top.*

Now click Diagnostic Info.

Complex Dialogflow System Entity in Raw API Response

*The original query and extracted entities.*

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.