NLP components

Quick example

states:
    welcome:
        component: meya.text
        properties:
            text: "Let's test Dialogflow."
    dialogflow_question:
        component: meya.dialogflow
        properties:
            text: "Try saying 'Do you provide financing?' or 'Do you accept insurance?'"
            project_id: XXXX
            language: en
            error_message: "I don't understand 🤔. Try again."
            min_confidence: 0.8
            require_match: true
        transitions:
            financing: financing_state
            insurance: insurance_state
    financing_state:
        component: meya.text
        properties:
            text: "Yes, we do provide financing."
        return: true
    insurance_state:
        component: meya.text
        properties:
            text: "Yes, we do accept insurance."
        return: true
354

Working example of Dialogflow transition.

❗️

Intents are used to transition

In the transitions section of the code snippet above, both financing and insurance must be intents you've created in your NLU agent. If they don't exist, this code snippet will not work.

Similarly, any NLU intent you want to handle in this component must have an entry in the transitions section, otherwise nothing will happen when the user expresses that intent.

Flow scope variables returned by the NLU agent

All of the NLU agents (Dialogflow, api.ai, luis.ai, and wit.ai) set several variables on the flow scope related to the NLU intent matching process. These variables can be accessed from within a flow using Mustache syntax: {{ flow._intent }}, or from a Python component using self.db.flow.get("_intent").

VariableDescription
_confidenceThe agent's confidence in the match.
_intentThe intent the Dialogflow agent matched.
valueThe user's original text.
fulfillment.speechThe agent's response, if you've provided the app with responses.
parameters.simplifiedThe query submitted to the agent.
sourceThe source agent.

meya.input_cms

Accepts input from the user and matches it against a Bot CMS-trained NLU agent. It also extracts entity data and makes that available on the flow scope.

PropertyDescription
textThe text to output to the user.
speechText to speak to the user. This field also accepts SSML markup to customize pronunciation.Optional
spaceThe space, or folder, in which the key is stored in Bot CMS.Required
keyThe key, or intent, which will be returned as an action.Required
languageThe two character language identifier. Example: enOptional
min_confidenceThe minimum confidence to match the entity.Optional. Default: 0.67
detect_languageIf true, {{ flow.language }} will be set to the language the NLU agent detected from the user's input.Optional. Default: false
require_matchIf false the flow will return an action no_match that you can use to transition to another state.Optional. Default: true
scopeWhere to store the intent and entity data. One of flow, user, or bot.Optional. Default: flow
buttonsAn array of ButtonsOptional
error_messageOnly displayed if require_match is true and the user's input does not match an intent.Optional
states:
    input_cms_state:
        component: meya.input_cms
        properties:
            text: "What would you like to update?"
            space: "change"
            key: "phone"
            language: "en"
            error_message: "I don't understand"
            require_match: false
            min_confidence: 0.8
            detect_language: true
            buttons:
                - text: "My phone number"
                  action: phone
                - text: "Something else"
                  action: no_match
        transitions:
            phone: update_phone_number
            no_match: everything_else

    update_phone_number:
        component: meya.text
        properties:
            text: "Okay, let's update your phone number"
        return: true
    
    everything_else:
        component: meya.text
        properties:
            text: "You said something else"
        return: true

Transitions

next: the default transition for an answer (if not present, flow will transition to the next state in sequence)
no_match: the state to transition to if require_match is false and the user inputs something that doesn't match an intent, or matches an intent other than the one specified in this component.

📘

The captured user intent will be available as flow.intent later in the next step(s) of your flow.

meya.dialogflow

Accepts input from the user and matches it against a pre-trained Dialogflow model. It also extracts entity data and makes that available on flow scope. Read the Dialogflow docs

🚧

This component requires a Dialogflow v2 agent and the Dialogflow integration. If you are using a v1 agent, upgrade your agent or use the meya.api_ai component.

PropertyDescription
textThe text to output to the userRequired
speechText to speak to the user. This field also accepts SSML markup to customize pronunciation.Optional
project_idFound in your Dialogflow agent's settings.Required
require_matchIf false the flow will return an action no_match that you can use to transition to another stateOptional. Default: true
min_confidenceThe minimum confidence required to match the entity.Optional. Default: 0.67
languageTwo letter language code. ex "en" matching the api.ai agent's language. If omitted, the bot will set flow.language to the language the input was written in.Optional. Default: blank (i.e. auto-detect)
scopeWhere to store the intent + entity data. One of flow, user, bot.Optional. Default: flow
latch_upIf true, any confidence value greater than min_confidence will be round up to 1.0, thus winning any intent collisions. Confidence values less than min_confidence will be rounded down to 0.0.Optional. Default: false
buttonsan array of ButtonsOptional
cache_durationThe number of seconds a request is cached. Set to 0 to force a new request. Note that shorter cache durations may increase latency in bot response since more API calls must be made.Optional. Default: 60

Transitions

next: the default transition for an answer (if not present, flow will transition to the next state in sequence)
no_match: the state to transition to if require_match is false and the user inputs something ambiguous

📘

The captured user intent will be available as flow.intent later in the next step(s) of your flow.

dialogflow_state:
    component: meya.dialogflow
    properties:
        text: "How are you doing today?"
        project_id: XXXX
        language: en
        error_message: "I don't understand"
        min_confidence: 0.8
        require_match: false
    transitions:
        bad: bad_state
        good: good_state
        no_match: ambiguous_state
bad_state:
    component: meya.text
    properties:
        text: "That's too bad."
    return: true
good_state:
    component: meya.text
    properties:
        text: "Great!"
    return: true

meya.wit

Accepts input from the user and matches it against a pre-trained wit.ai model. It also extracts entity data and makes that available on flow scope. Read the wit docs

🚧

Categorizing the user intent

If you are going to use the transitions property of this component you should train your model to classify utterances using the intent entity that categorizes the user intent. See example

PropertyDescription
textThe text to output to the userRequired
speechText to speak to the user. This field also accepts SSML markup to customize pronunciation.Optional
tokenThe wit.ai secret server token for your wit.ai app settingsRequired
require_matchIf false the flow will return an action no_match that you can use to transition to another stateOptional. Default: true
min_confidenceThe minimum confidence required to match the entity.Optional. Default: 0.67
latch_upIf true, any confidence value greater than min_confidence will be round up to 1.0, thus winning any intent collisions. Confidence values less than min_confidence will be rounded down to 0.0.Optional. Default: false
scopeWhere to store the intent + entity data. One of flow, user, bot.Optional. Default: flow
buttonsAn array of ButtonsOptional
cache_durationThe number of seconds a request is cached. Set to 0 to force a new request. Note that shorter cache durations may increase latency in bot response since more API calls must be made.Optional. Default: 60

Transitions

next: the default transition for an answer (if not present, flow will transition to the next state in sequence)
no_match: the state to transition to if require_match is false and the user inputs something ambiguous

📘

The captured user intent will be available as flow.intent later in the next step(s) of your flow.

component: meya.wit
properties:
	text: "How do you feel?"
	token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
	error_message: "I don't understand"
	min_confidence: 0.8
	require_match: false
transitions:
	bad: bad_state
	good: good_state
	no_match: ambiguous_state

meya.api_ai

Accepts input from the user and matches it against a pre-trained api.ai model. It also extracts entity data and makes that available on flow scope. Read the api.ai docs

🚧

This component does not support Dialogflow v2 features, such as multi-language agents. If you wish to make use of those features, use the meya.dialogflow component with your v2 agent.

PropertyDescription
textthe text to output to the user
speechText to speak to the user. This field also accepts SSML markup to customize pronunciation.Optional
client_access_tokenThe api.ai client access token from your api.ai agent settingsRequired
languageTwo letter language code. ex "en" matching the api.ai agent's language. If omitted, the bot will set flow.language to the language the input was written in.Optional. Default: blank (i.e. auto-detect)
require_matchIf false the flow will return an action no_match that you can use to transition to another stateOptional. Default: true
min_confidencethe minimum confidence to match the entityOptional. Default: 0.67
latch_upIf true, any confidence value greater than min_confidence will be round up to 1.0, thus winning any intent collisions. Confidence values less than min_confidence will be rounded down to 0.0.Optional. Default: false
scopewhere to store the intent + entity data. One of flow, user, bot.Optional. Default: flow
buttonsan array of ButtonsOptional
cache_durationThe number of seconds a request is cached. Set to 0 to force a new request. Note that shorter cache durations may increase latency in bot response since more API calls must be made.Optional. Default: 60

Transitions

next: the default transition for an answer (if not present, flow will transition to the next state in sequence)
no_match: the state to transition to if require_match is false and the user inputs something ambiguous

📘

The captured user intent will be available as flow.intent later in the next step(s) of your flow.

component: meya.api_ai
properties:
  text: "How do you feel?"
  client_access_token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  language: en
  error_message: "I don't understand"
  min_confidence: 0.8
  require_match: false
transitions:
  bad: bad_state
  good: good_state
  no_match: ambiguous_state

❗️

Intents are used to transition

In the transitions section of the code snippet above, both bad and good must be intents you've created in your Dialogflow agent. If they don't exist, this code snippet will not work.

Similarly, any Dialogflow intent you want to handle in this component must have an entry in the transitions section, otherwise nothing will happen when the user expresses that intent.

Example - Language Detection

You can use the meya.api_ai component to detect a user's language. Start by creating a Dialogflow agent with both English and French language enabled. Then create a greetings intent in the agent with English and French training phrases, such as hello and bonjour. Finally, create a new flow called language and paste the following code.

states:
    first:
        component: meya.text
        properties:
        		text: "Your language is {{ flow.language }}"

    api_ai_state:
        component: meya.api_ai
        properties:
            text: "Enter some text"
            client_access_token: <YOUR_CLIENT_ACCESS_TOKEN>
        transitions:
            greeting: greeting

    greeting:
        component: meya.text
        properties:
            text: "Your language is {{ flow.language }}"

Test it out in the test chat window. Enter hello and the bot will respond Your language is en. Enter bonjour and the bot will say Your language is fr.

360

meya.luis

Accepts input from the user and matches it against a pre-trained luis.ai model. It also extracts entity data and makes that available on flow scope. Read the luis docs

PropertyDescription
textthe text to output to the user
speechText to speak to the user. This field also accepts SSML markup to customize pronunciation.Optional
app_idluis.ai app idRequired
api_keyluis.ai api keyRequired
subdomainWithin your Luis app, you can specify which geographic regions your app will be available in. Within Meya, you can specify which one you're using by setting subdomain.Optional. Default: westus
require_matchIf false the flow will return an action no_match that you can use to transition to another stateOptional. Default: true
min_confidencethe minimum confidence to match the entityOptional. Default: 0.67
latch_upIf true, any confidence value greater than min_confidence will be round up to 1.0, thus winning any intent collisions. Confidence values less than min_confidence will be rounded down to 0.0.Optional. Default: false
scopewhere to store the intent + entity data. One of flow, user, bot.Optional. Default: flow
buttonsan array of ButtonsOptional
cache_durationThe number of seconds a request is cached. Set to 0 to force a new request. Note that shorter cache durations may increase latency in bot response since more API calls must be made.Optional. Default: 60

Transitions

next: the default transition for an answer (if not present, flow will transition to the next state in sequence)
no_match: the state to transition to if require_match is false and the user inputs something ambiguous

📘

The captured user intent will be available as flow.intent later in the next step(s) of your flow.

component: meya.luis
		properties:
  			text: "How do you feel?"
  			app_id: xxxxxxxxxxxxxxxxxxxxxxxxxx
  			api_key: xxxxxxxxxxxxxxxxxxxxxxxxxx
  			error_message: "I don't understand"
  			min_confidence: 0.8
		transitions:
  			bad: bad_state
  			good: good_state

❗️

Intents are used to transition

In the transitions section of the code snippet above, both financing and insurance must be intents you've created in your Luis agent. If they don't exist, this code snippet will not work.

Similarly, any Luis intent you want to handle in this component must have an entry in the transitions section, otherwise nothing will happen when the user expresses that intent.

meya.nlp_yes_no

Accepts input from the user and matches it against a pre-trained yes/no model (English).

PropertyDescription
textthe text to output to the user
speechText to speak to the user. This field also accepts SSML markup to customize pronunciation.Optional
require_matchIf false the flow will return an action no_match that you can use to transition to another stateOptional. Default: true

Transitions

next: the default transition for an answer (if not present, flow will transition to the next state in sequence)
no_match: the state to transition to if require_match is false and the user inputs something ambiguous

❗️

yes and no are reserved in YAML so must be escaped with single or double quotes.

component: meya.nlp_yes_no
properties:
	text: Do you like Meya?
transitions:
	"yes": yes_state
 	"no": no_state