Intents determine which user requests are understood and what action to take. In most cases, you will use the Dialogflow ES console to manage intents. In advanced scenarios, you may wish to use the API to manage intents. This page describes how to create, list, and delete intents using the API.
Before you begin
You should do the following before reading this guide:
- Read Dialogflow basics.
- Perform setup steps.
Create an agent
If you have not already created an agent, create one now:
- Go to the Dialogflow ES console.
- If requested, sign in to the Dialogflow Console. See Dialogflow console overview for more information.
- Click Create Agent in the left sidebar menu. (If you already have other agents, click the agent name, scroll to the bottom and click Create new agent.)
- Enter your agent's name, default language, and default time zone.
- If you have already created a project, enter that project. If you want to allow the Dialogflow Console to create the project, select Create a new Google project.
- Click the Create button.
Import the example file to your agent
The steps in this guide make assumptions about your agent, so you need to import an agent prepared for this guide. When importing, these steps use the restore option, which overwrites all agent settings, intents, and entities.
To import the file, follow these steps:
-
Download the
room-booking-agent.zip
file. - Go to the Dialogflow ES console.
- Select your agent.
- Click the settings settings button next to the agent name.
- Select the Export and Import tab.
- Select Restore From Zip and follow instructions to restore the zip file that you downloaded.
Use IntentView to return all intent data
When creating, listing, or getting an intent, intent data is returned to the caller. By default, this returned data is abbreviated. The samples below use this default.
To retrieve all intent data,
you must set the IntentView
parameter to INTENT_VIEW_FULL
.
For more information, see the methods for the
Intents
type.
Create intent
The following samples show how to create an intent. For more information, 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, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To authenticate to Dialogflow, 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 reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Dialogflow reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Dialogflow reference documentation for Ruby.
List intents
The following samples show how to lists 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, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To authenticate to Dialogflow, 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 reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Dialogflow reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Dialogflow reference documentation for Ruby.
Delete intents
The following samples show 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, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
To authenticate to Dialogflow, 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 reference documentation for .NET.
PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Dialogflow reference documentation for PHP.
Ruby: Please follow the Ruby setup instructions on the client libraries page and then visit the Dialogflow reference documentation for Ruby.