Quickstart: Setup

This guide provides all required setup steps to start using Dialogflow.

Before you begin

You should do the following before reading this guide:

  1. Read Dialogflow basics.
  2. Read Editions.

About the GCP Console

The Google Cloud Platform (GCP) Console (visit documentation, open console) is a web UI used to provision, configure, manage, and monitor systems that use GCP products. You use the GCP Console to set up and manage Dialogflow resources.

Create a project

To use services provided by GCP, you must create a project. A project organizes all your GCP 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 GCP resources in a resource hierarchy. For more information on projects, see the Resource Manager documentation.

The Dialogflow Console (visit documentation, open console) can optionally create a basic project for you when you create an agent. If you plan on using your project for more than just basic access to the Dialogflow Standard Edition, or you plan on using the API, you should create a project with the GCP Console as described below.

We recommend that you create separate projects for experiments, testing, and production. Each project can only create one Dialogflow Agent. If you need multiple agents, you will need to create multiple projects. When creating a project, take note of the project ID. You will need this ID to make API calls.

Selecciona o crea un proyecto de GCP.

Ir a la página Administrar recursos

Enable billing

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.

Asegúrate de tener habilitada la facturación para tu proyecto.

Aprende a habilitar la facturación

Enable the API

You must enable the Dialogflow API for your project. For more information on enabling APIs, see the Service Usage documentation.

Habilita las Dialogflow V2 API necesarias.

Habilita las 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 GCP 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 Service accounts.

About roles

When an identity calls an API, GCP requires that the identity has the appropriate permissions. You can grant permissions by granting roles to a service account. For more information, see the Cloud Identity and Access Management 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

Configura la autenticación:
  1. En GCP Console, ve a la página Crear clave de la cuenta de servicio.

    Ir a la página Crear clave de la cuenta de servicio
  2. Desde la lista desplegable de la Cuenta de servicio, selecciona Nueva cuenta de servicio.
  3. En el campo Nombre de cuenta de servicio, ingresa un nombre.
  4. En la lista desplegable Función, selecciona Proyecto > Propietario.

    Nota: El campo Función autoriza tu cuenta de servicio para acceder a los recursos. Puedes ver y cambiar este campo luego con GCP Console. Si desarrollas una aplicación de producción, especifica permisos más detallados que Proyecto > Propietario. Para obtener más información, consulta Cómo otorgar funciones a las cuentas de servicio.
  5. Haz clic en Crear. Se descargará un archivo JSON a tu computadora que contiene tus descargas de claves.

Use the service account key file in your environment

Proporciónale las credenciales de autenticación a tu código de la aplicación mediante la configuración de la variable de entorno GOOGLE_APPLICATION_CREDENTIALS. Reemplaza [PATH] con la ruta de acceso al archivo JSON que contiene la clave de tu cuenta de servicio y [FILE_NAME] con el nombre del archivo. Esta variable solo se aplica a la sesión actual de shell. Por lo tanto, si abres una sesión nueva, deberás volver a configurar la variable.

Linux o macOS

export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

Por ejemplo:

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/[FILE_NAME].json"

Windows

Con PowerShell:

$env:GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

Por ejemplo:

$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\[FILE_NAME].json"

Con el símbolo del sistema:

set GOOGLE_APPLICATION_CREDENTIALS=[PATH]

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 GCP. This includes the gcloud command line tool. The following link provides instructions:

Realiza la instalación y la inicialización del SDK de Cloud.

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

You have three options for calling the API:

The client libraries are available for several popular languages, and these are the recommended option. To install a client library:

C#

Install the Google.Cloud.Dialogflow.V2 package from NuGet. Add it to your project in the normal way (for example by right-clicking on the project in Visual Studio and choosing "Manage NuGet Packages..."). Ensure you enable pre-release packages (for example, in the Visual Studio NuGet user interface, check the "Include prerelease" box).

Alternatively, you can use the NuGet command line interface:

nuget install Google.Cloud.Dialogflow.V2 -PreRelease

Go

go get cloud.google.com/go/dialogflow/apiv2

Java

Node.js

npm install dialogflow

PHP

composer install google/cloud-dialogflow

Python

pip install dialogflow

Ruby

gem install google-cloud-dialogflow

¿Te sirvió esta página? Envíanos tu opinión:

Enviar comentarios sobre…

Dialogflow Documentation
¿Necesitas ayuda? Visita nuestra página de asistencia.