Custom events

Custom events are events you create to signify some communication that can't be captured easily through text or voice. Custom events can indicate that a user has clicked a button, provided authorization, or that a certain amount of time has passed. These events can be triggered through Dialogflow fulfillment or the detect intent API. These events can be handled in your Dialogflow agent or in fulfillment.

Define event names in intents

You can define an event name in an intent in the Dialogflow Console or by using the API Intents type.

In an intent, locate the Events section and enter the event name(s) in the text field:

To add events via the API, add a string to the events field of the Intents type, as seen in the HTTP request below:

PATCH Authorization: Bearer <AccessToken>
https://dialogflow.googleapis.com/v2/projects/<ProjectID>/agent/intents/<IntentID>
{
  "events": [
    "event-name-1",
    "event-name-2"
    ...
  ]
  ...
}

Invoke an event via the detect intent API

To trigger a specific intent by event name, send a detect intent API request containing an event parameter value that corresponds to the event name. When you send a query request with an event parameter, Dialogflow creates a context with the same name as the event name and context lifespan: 0. This lifespan value means that the context is active only during the current request.

You can use this context to pass parameter values from the detect intent request to the parameters defined in the Action and parameters section of the intent, and also reference these parameter values in the Response section of the triggered intent.

  • To reference an event parameter in the parameter table or a response, use the following format: #event-name.parameter-name.
POST Authorization: Bearer <AccessToken>
https://dialogflow.googleapis.com/v2/projects/<ProjectID>/agent/sessions/<SessionID>:detectIntent
{
        "queryInput": {
                "event": {
                        "name": "event-name",
                        "parameters": {
                                "parameter-name-1": "parameter-value-1",
                                "parameter-name-2": "parameter-value-2",
                                ...
                        },
                        "languageCode": "en-US"
                }
        }
}

For more information, see the detectIntent method of the Sessions type.

Invoke event from webhook

You can invoke events via fulfillment by setting the followupEventInput field of the WebhookResponse. You can optionally set the followupEventInput.parameters field to provide parameters to the intent.

When building an agent, you can reference event parameters for the intent that will be triggered by the event.

When your application receives a fulfillment WebhookRequest, you can trigger a followup event by sending a WebhookResponse similar to the following:

{
  "followupEventInput": {
    "name": "event-name",
    "parameters": {
      "parameter-name-1": "parameter-value-1",
      "parameter-name-2": "parameter-value-2"
    },
    "languageCode": "en-US"
  }
}

When Dialogflow receives a webhook response that includes an event, it immediately triggers the corresponding intent in which it was defined.

The following flow describes the steps:

  1. The end-user types or speaks an expression.
  2. Dialogflow matches the end-user expression to Intent-1, which is configured for fulfillment.
  3. Dialogflow sends a webhook request to your server.
  4. Your server responds with a webhook response that includes a followup event.
  5. Instead of responding to the user for the Intent-1 match, Dialogflow triggers Intent-2, which is configured for the event.
  6. Dialogflow proceeds as though the end-user initiated the match for Intent-2 and handles required parameters and fulfillment as dictated by the configuration of Intent-2.

Chaining intent matches with webhook response events

It is possible to chain intent matches with webhook response events. In the flow described above, Intent-2 could also be configured for fulfillment. If your server's webhook response supplies another event, Dialogflow proceeds to match Intent-3 (configured for the event) without responding to the end-user for Intent-2.

Dialogflow does not respond to the end-user until the chain has ended. When chaining intents in such a way, each webhook response must be sent within timeout restrictions.

Was deze pagina nuttig? Laat ons weten hoe goed we u hebben geholpen:

Feedback verzenden over...

Dialogflow Documentation
Hulp nodig? Ga naar onze ondersteuningspagina.