Intents determine which user requests are understood and what action to take. In most cases, you use the Dialogflow ES console to manage intents. In advanced scenarios, you can use the API to manage intents. This document describes how to create, list, and delete intents using the API.
Before you begin
Before you begin, complete the following steps:
- Read Dialogflow basics.
- Perform setup steps.
Create an agent
- Go to the Dialogflow ES console.
- Sign in to the console if prompted. For more information, see the Dialogflow console overview.
- In the sidebar menu, expand Loading agents.
- Click Create new agent.
- Enter the agent name, default language, and default time zone.
- Enter an existing project. To let the Dialogflow console create a project, select Create a new Google project.
- Click Create.
Use IntentView to return all intent data
By default, the API returns abbreviated intent data when you create, list, or get an intent. The following samples use this default.
To retrieve all intent data, you must set the IntentView parameter to
INTENT_VIEW_FULL. For more information about intent data, see the methods
for the Intents type.
Create intent
The following samples show you how to create an intent. For more information about intents, see the Intents reference.
REST
To create an intent for your agent, call the create method on the intent
resource.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
HTTP method and URL:
POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/agent/intents
Request JSON body:
{
"displayName": "ListRooms",
"priority": 500000,
"webhookState": "WEBHOOK_STATE_UNSPECIFIED",
"trainingPhrases": [
{
"type": "EXAMPLE",
"parts": [
{
"text": "What rooms are available at 10am today?"
}
]
}
],
"action": "listRooms",
"messages": [
{
"text": {
"text": [
"Here are the available rooms:"
]
}
}
]
}
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
The path segment after intents contains your new intent ID.
Go
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the Dialogflow CX reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Dialogflow CX reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Dialogflow CX reference documentation for Ruby.
List intents
The following samples show how to list intents. For more information, see the Intents reference.
REST
To list the intents for your agent, call the list method on the intents
resource.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
HTTP method and URL:
GET https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/agent/intents
To send your request, expand one of these options:
You should receive a JSON response similar to the following:
{
"intents": [
{
"name": "projects/PROJECT_ID/agent/intents/5b290a94-55d6-4074-96f4-9c4c4879c2bb",
"displayName": "ListRooms",
"priority": 500000,
"action": "listRooms",
"messages": [
{
"text": {
"text": [
"Here are the available rooms:"
]
}
}
]
},
...
]
}
The path segments after intents contain your intent IDs.
Go
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the Dialogflow CX reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Dialogflow CX reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Dialogflow CX reference documentation for Ruby.
Delete intents
The following samples show you how to delete an intent. For more information, see the Intents reference.
REST
To delete an intent for your agent, call the delete method on the intents
resource.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
- INTENT_ID: your intent ID
HTTP method and URL:
DELETE https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/agent/intents/INTENT_ID
To send your request, expand one of these options:
You should receive a successful status code (2xx) and an empty response.
Go
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To authenticate to Dialogflow CX, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Additional languages
C#: Please follow the C# setup instructions on the client libraries page and then visit the Dialogflow CX reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Dialogflow CX reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Dialogflow CX reference documentation for Ruby.