Responses

Intents have a built-in response handler that can return responses after the intent is matched. This feature only supports static responses, though you can use parameter references in these responses to make them somewhat dynamic. This is helpful for recapping information provided by the end-user. For example, your intent response could look like: "Okay, I booked a room for you on $date".

In some cases, this is all you need. In cases where your code needs to take some action or build a more dynamic response, you should use one of the dynamic response options below. Agents typically use a combination of static and dynamic responses.

Multiple types of responses can be provided. The basic response type is a text response. Other types of responses are available (image, audio, synthesized speech, and so on), some of which are platform-specific.

If you define more than one response variation for an intent, your agent will select a response at random. You should add several response variations to make your agent more conversational.

When building an agent, you should provide response data for each intent. When you use the API or fulfillment to interact with Dialogflow, you technically may not need to provide response data, because both of these methods can dynamically generate any response. However, if you want to use the simulator for testing or define intents that have a simple response, you should provide response data.

As a general rule, your intent responses should prompt the end-user to provide an expression that will match another intent. Your responses should also guide the end-user to provide specific data. For example, a question like "What city were you born in?" is better than a more open-ended question like "Where were you born?".

Where to find this data

When building an agent, it is most common to use the Dialogflow Console (visit documentation, open console). The instructions below focus on using the console. To access intent response data:

  1. Go to the Dialogflow Console.
  2. Select an agent.
  3. Select Intents in the left sidebar menu.
  4. Select an intent.
  5. Scroll down to the Responses section.

If you are building an agent using the API instead of the console, see the Intents reference. The API field names are similar to the console field names. The instructions below highlight any important differences between the console and the API.

Response platforms

Each response is defined for either the Default platform (referred to as PLATFORM_UNSPECIFIED in the API) or a specific integration platform. If you are not using an integration, all of your responses can use the default platform. If you are using integrations, each integration can have a unique response, or it can be configured to use the default response.

For more information on platform-specific responses, see Rich messages.

Create built-in responses

To create built-in responses:

  1. Select Default or a specific platform.
  2. If the desired type of response (for example, Text response) is not already listed, click Add Responses and select the response type.
  3. Enter required information for the response.
  4. Click Save.

Dynamic responses with fulfillment

Here is the processing flow for dynamic responses with fulfillment:

  1. Dialogflow interacts with the end-user, typically through your integration app.
  2. When an intent with fulfillment enabled is matched, Dialogflow sends a webhook request to your service that includes information about the matched intent, action, parameters, and a response message based on the built-in intent response.
  3. Your services takes any necessary actions, like database reads/writes or other service calls.
  4. Your service creates a response message by using the provided response message or by creating a modified response message.
  5. Your service sends a webhook response to Dialogflow that includes the response message.
  6. Dialogflow passes the response message on to the end-user.

Dynamic responses with the API

Here is the processing flow for dynamic responses with the API:

  1. Your service interacts with the end-user and gets an expression, typically through your custom app.
  2. Your service sends a detect intent request (see the Sessions detectIntent method) to Dialogflow.
  3. Dialogflow sends a detect intent response to your service that includes information about the matched intent, action, parameters, and a response message based on the built-in intent response.
  4. Your services takes any necessary actions, like database reads/writes or other service calls.
  5. Your service creates a response message by using the provided response message or by creating a modified response message.
  6. Your service responds to the end-user with the response message.

Special characters

Some special characters require escaping in your response.

To use the dollar sign $ or the number sign # in a response, add braces {} around the content that immediately follows the sign. For example:

  • ${100} resolves to $100
  • ${$number} resolves to $100, where $number is a parameter reference with a value of 100
  • #{hello} resolves to #hello

To use braces {} in a response, use double braces. For example:

  • {{hello}} resolves to {hello}

Handling empty parameter values

If your intent has a parameter that can resolve to an empty value, you must provide at least one response variant that does not use that parameter.

For example, if your intent has 2 parameters (p1 and p2), and either or both could be empty, you should provide at least four response variants:

  • Got it. You said $p1 and $p2.
  • Got it. You said $p1.
  • Got it. You said $p2.
  • Got it.
Hai trovato utile questa pagina? Facci sapere cosa ne pensi:

Invia feedback per...

Dialogflow Documentation
Hai bisogno di assistenza? Visita la nostra pagina di assistenza.