This guide provides all required setup steps to start using Dialogflow CX.
Before you begin
You should do the following before reading this guide:
About the Google Cloud Console
The Google Cloud Console (visit documentation, open console) is a web UI used to provision, configure, manage, and monitor systems that use Google Cloud products. You use the Google Cloud Console to set up and manage Dialogflow resources.
Create a project
To use services provided by Google Cloud, you must create a project. A project organizes all your Google Cloud resources. A project consists of a set of collaborators, enabled APIs (and other resources), monitoring tools, billing information, and authentication and access controls. You can create one project, or you can create multiple projects and use them to organize your Google Cloud resources in a resource hierarchy. When creating a project, take note of the project ID. You will need this ID to make API calls. For more information on projects, see the Resource Manager documentation.
In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.
A billing account is used to define who pays for a given set of resources, and it can be linked to one or more projects. Project usage is charged to the linked billing account. In most cases, you configure billing when you create a project. For more information, see the Billing documentation.
Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.
Enable the API
You must enable the Dialogflow API for your project. For more information on enabling APIs, see the Service Usage documentation.Enable the Dialogflow API.
Set up authentication
If you plan to use the Dialogflow API, you need to set up authentication. Any client application that uses the API must be authenticated and granted access to the requested resources. This section describes important authentication concepts and provides steps for setting it up. For more information, see the Google Cloud authentication overview.
About service accounts
There are multiple options for authentication, but it is recommended that you use service accounts for authentication and access control. A service account provides credentials for applications, as opposed to end-users. Service accounts are owned by projects, and you can create many service accounts for a project. For more information, see Understanding service accounts.
When an identity calls an API, Google Cloud requires that the identity has the appropriate permissions. You can grant permissions by granting roles to a service account. For more information, see the Identity and Access Management (IAM) documentation.
For the purpose of trying the Dialogflow API, you can use the Project > Owner role in steps below, which grants the service account full access to the project. For more information on roles specific to Dialogflow, see the Dialogflow access control document.
About service account keys
Service accounts are associated with one or more public/private key pairs. When you create a new key pair, you download the private key. Your private key is used to generate credentials when calling the API. You are responsible for security of the private key and other management operations, such as key rotation.
Create a service account and download the private key file
Set up authentication:
In the Cloud Console, go to the Create service account key page.Go to the Create Service Account Key page
- From the Service account list, select New service account.
- In the Service account name field, enter a name.
From the Role list, select Project > Owner.
- Click Create. A JSON file that contains your key downloads to your computer.
Use the service account key file in your environment
Provide authentication credentials to your application code by
setting the environment variable
Replace [PATH] with the file path of the JSON file that contains your
service account key. This variable only applies to your current shell session,
so if you open a new session, set the variable again.
Linux or macOS
With command prompt:
Install and initialize the Cloud SDK
If you plan to use the Dialogflow API,
you need to install and initialize the Cloud SDK.
Cloud SDK is a set of tools that you can use
to manage resources and applications hosted on Google Cloud.
This includes the
command line tool.
The following link provides instructions:Install and initialize the Cloud SDK.
Test the SDK and authentication
If you have set up authentication in previous steps, you can use the `gcloud` tool to test your authentication environment. Execute the following command and verify that no error occurs and that credentials are returned:
gcloud auth application-default print-access-token
That command is used by all Dialogflow command line REST samples to authenticate API calls.
Install the Dialogflow client library
Client libraries are available for several popular languages. To install a client library:
<dependency> <groupId>com.google.cloud</groupId> <artifactId>google-cloud-dialogflow-cx</artifactId> <version>0.6.1</version> </dependency>
If you are using Gradle, add the following to your dependencies:
If you are using sbt, add the following to your dependencies:
libraryDependencies += "com.google.cloud" % "google-cloud-dialogflow-cx" % "0.6.1"
If you're using IntelliJ or Eclipse, you can add client libraries to your project using the following IDE plugins:
The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.
npm install @google-cloud/dialogflow-cx
pip install google-cloud-dialogflow-cx