Triggers

Dialogflow specific triggers

The google.dialogflow trigger will call your Dialogflow agent's "detect intent" API with the user's input text, and will match if the intent confidence threshold is reached.

- expect: dialogflow
  integration: integration.dialogflow
  intent: faq_dialogflow
  intent_regex:
  input_context:
    - input_yes
    - input_no
  min_confidence: 0.8
  max_confidence: 1.0
  • expect: The name of the NLU provider, in this case dialogflow

  • integration: The Dialogflow integration reference path. Because the trigger needs to make an API call to Dialogflow, it will need the Dialogflow integration configuration settings.

  • intent: The specific intent (or list of intents) to match if the confidence exceeds the specified min_confidence.

  • intent_regex: The regex pattern to match the returned intent against if the confidence exceeds the specified min_confidence.

  • input_context: The optional input contexts that need to be applied to the detect intent API call. Providing an input context will inform Dialogflow to only evaluate intents that match the specified input contexts.

  • min_confidence: The minimum confidence threshold that the intent needs to achieve for the trigger to match. The default is 0.75.

  • max_confidence: The maximum confidence threshold that the intent should not exceed for the trigger to match. The default is 1.0.

Simple example

In this example the trigger will match if the returned confidence is above 0.75 and below 1.0, and the intent is equal to faq_dialogflow.

triggers:
  - expect: dialogflow
    integration: integration.dialogflow
    intent: faq_dialogflow

steps:
  - say: Dialogflow is a powerful Natural Language Understanding tool.

Intent routing example

A common use case for NLU is to handle user questions and bot answers. The user input will sent to Dialogflow to match the intent and then the flow will route the matched intent to a corresponding answer flow.

In this example the faq_component intent is routed to the flow.faq.answers.component flow, and the smalltalk intent is sent to the flow.faq.smalltalk file. If the intent does not have a corresponding flow, then the flow.catchall flow is called.

triggers:
  - expect: dialogflow
    integration: integration.dialogflow
    input_context:
      - context_id: faq
        parameters:
          foo: bar
    min_confidence: 0.8
    max_confidence: 1.0

steps:
  - value: (@ flow.result )
    match:
      ^faq_component$:
        flow: flow.faq.answers.component
        data: (@ flow )
        transfer: true
      ^smalltalk\.:
        flow: flow.faq.smalltalk
        data: (@ flow )
        transfer: true
    default:
      flow: flow.catchall
      data: (@ flow )
      transfer: true
steps:
  - say: >-
      (% trans %)
      A component in Meya is the action that a bot takes at each step of a flow.
      Meya comes with a number of built-in components (see https://docs.meya.ai/reference/meya-component-element),
      but also allows you to create your own custom components (https://docs.meya.ai/docs/getting-started-with-custom-components)
      in **Python**.
      (% endtrans %)

Dialogflow allows you to specify fulfillment text for your intents that you configure in the Diagflow console. In Meya you can also display the fulfillment text set in Dialogflow, this is often useful if you use Dialogflows built-in models such as their *smalltalk model.

steps:
  - continue_screen
  - say: (@ flow.dialogflow_response.queryResult.fulfillmentText )

See the Dialogflow Fulfullment messages page for more details and examples.

Input context

Dialogflow allows your to specify input contexts and output contexts for each intent. The enables the Dialogflow agent to be context aware and thereby limit the intent detection scope to the intents associated with a particular context. Check the Dialogflow input and output contexts documentation for more information on how contexts work.

The google.dialogflow trigger allows you to set the input contexts explicitly:

As a single input context:

- expect: dialogflow
  integration: integration.dialogflow
  input_context: faq

or, as a list:

- expect: dialogflow
  integration: integration.dialogflow
  input_context:
    - input_yes
    - input_no

or, as a list of Dialogflow context dictionaries:

- expect: dialogflow
  integration: integration.dialogflow
  input_context:
    - context_id: input_yes
      parameters:
        type: yes
    - context_id: input_no
      parameters:
        type: no

Flow scope variables

The Dialogflow intent and API response get's stored in the following flow scope variables:

  • (@ flow.result ): contains matched intent.
  • (@ flow.dialogflow_response ): Contains the full "detect intent" API response.

Example Dialogflow API response:

{
  "responseId": "916a6394-d9bf-4606-80a2-2c61566e938c-5c04e5ec",
  "queryResult": {
    "intent": {
      "name": "projects/meya-v2/agent/intents/868e7b52-edc1-41fb-aa11-d9247a0493aa",
      "displayName": "faq_component"
    },
    "queryText": "create custom component",
    "parameters": {},
    "languageCode": "en",
    "allRequiredParamsPresent": true,
    "intentDetectionConfidence": 0.8202429
  }
}