Dialogflow CX Intents
Explore this tutorial to learn how to easily create intents and evolve your NLU in Dialogflow CX, using either the console or the CX CLI.
Join the DZone community and get the full member experience.
Join For FreePrevious Requisites
Here are the technologies used in this project:
- Google Cloud Account
- Dialogflow API enabled
- Dialogflow CX CLI
What Are Dialogflow CX Intents?
Before we start talking about intents, it is important to understand what NLU is. Natural Language Understanding (NLU) is a subset of Natural Language Processing (NLP). It helps a “machine” to be able to understand human language. In Dialogflow CX, this is an important part, since it will help to predict the user’s intention, allow us to act in a “smarter” way, and avoid the already typical question: “I did not understand you, could you repeat it?” We call these intentions, proposals, or user requests, which the machine must classify. These are the “intents."
Each intent has training phrases. For example, the welcome_intent
intent can have these 3 training phrases:
- "Hi"
- "Hello"
- "What’s up?"
As you can see in the example above, our intention with the welcome_intent
intent is to start a conversation when a user says any of these training phrases. An intent can have multiple entities. The entities are going to be explained in a future article.
To showcase another example, if we take a look at the image above, we will see the get_info
intent. This intent has multiple training phrases as well:
- "Tell me info about Pikachu"
- "Tell me information about Pikachu"
- "Info Pikachu"
- "Pikachu"
So we can request information about a certain Pokemon in multiple ways. In this example, pikachu
is an entity.
It is a good practice to test your training phrases with your end users. This will allow you to detect missing training phrases in your NLU.
Dialogflow Console
Dialogflow Console is a web interface where you can design your conversations by creating agents, and within an agent, create flows, intents, entity types, etc. On the Dialogflow Console, you can create and interact easily with your intent. To do that you just need to go to the Dialogflow CX Console. This is what it looks like:
You will find your intents in the Manage tab and the clicking in the intents section:
With the Dialogflow CX Console, you can do the following:
- Create an intent: When you create an intent, you can add training phrases and add a description or labels to that intent. You can add entity types as well to an intent.
- Delete an intent.
- Train and validate your NLU.
Whenever you create, modify, or delete an intent, it is important to re-train your Dialogflow CX flows. This will re-train your NLU. By doing this your bot will “understand you,” including your latest changes.
Dialogflow CX CLI
The Dialogflow CX CLI or cxcli
is a command line interface tool that you can use to interact with your Dialogflow CX projects in a terminal. It is an open-source project I created. With the cxcli
, you can interact easily with your Dialogflow CX intents.
All of the commands that you have available in the cxcli
to interact with your intent are located down the cxcli intent
command.
Create
You can create an intent using this tool. This command has this usage:
cxcli intent create [intent-name] [parameters]
You can find the full usage here. It is important to explain the --training-phrases
parameter. Why? Because it is the most important parameter. It is a list of the training phrases for this intent, comma separated. For the entities used in this intent, add @entity-type
to the word in the training phrase. This is the format:
word@entity-type
Here you have an example: hello, hi how are you today@sys.date, morning!
This a simple example of the cxcli intent create
command:
cxcli intent create test_intent --training-phrases "hello, hi how are you today@sys.date, morning" --agent-name test-agent --project-id test-cx-346408 --location-id us-central1
The command above will give you an output like this one:
$ cxcli intent create test_intent --training-phrases "hello, hi how are you today@sys.date, morning" --agent-name test-agent --project-id test-cx-346408 --location-id us-central1
INFO Intent created with id: projects/test-cx-346408/locations/us-central1/agents/40278ea0-c0fc-4d9a-a4d4-caa68d86295f/intents/a7870357-e942-43dd-99d2-4de8c81a3c09
You can see the test_intent
on the Dialogflow CX Console:
Delete
Also, an intent can be deleted. The usage of this command is pretty much similar to the one used for creating an intent:
cxcli intent delete [intent-name] [parameters]
You can find the full usage here. This a simple example of the cxcli intent delete
command:
cxcli intent delete test_intent --agent-name test-agent --project-id test-cx-346408 --location-id us-central1
The command above will give you an output like this one:
$ cxcli intent delete test_intent --agent-name test-agent --project-id test-cx-346408 --location-id us-central1
INFO Intent deleted
Resources
If you want to check the full usage of the cxcli intent
command, please refer to this page.
If you want to learn more about Dialogflow CX intents, check the official documentation.
Conclusion
This was a basic tutorial to learn what a Dialogflow CX Intent is. As you have seen in this example, creating intents and evolving your NLU in Dialogflow CX either with the console or the cxcli
is very easy!
I hope this tutorial will be useful to you.
That’s all folks! Happy coding!
Published at DZone with permission of Xavier Portilla Edo, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments