Control Components

These YAML-mode control components route the flow based on whether the user input matches a predetermined value.

System.ConditionEquals

This component alters the navigation based on a variable value.

Note

This component isn't available in the Visual Flow Designer. You can use the Switch for this purpose instead.
Use this component to branch the dialog flow when a value gets matched. This component executes value-based routing by comparing the values set for its source or variable properties against the value stored by the value property. The component triggers the equal and notequal actions accordingly based on a match (or lack thereof). In the following snippet, the customer gets routed to the orderPizza state when the input extracted for the orders context variable matches pizza, or to the execution path that begins with the orderPasta state when it doesn't.
  Check for Pizza:
    component: "System.ConditionEquals"
    properties:
      variable: "orders"
      value: "pizza"
    transitions:
      actions:
        equal:  "orderPizza"
        notequal: "orderPasta"
Properties Description Required?
variable The name of the variable whose current value determines the routing. The Dialog Engine ignores the variable property if you have also defined the source property. No
source The source property is an alternate to the variable property. No
value The value that's compared against either the source or variable properties. Yes

How Do I Use Apache FreeMarker Expressions with the System.ConditionEquals Component?

You you can narrow the matching criteria to specific values and formats by defining the value and source properties with Apache FreeMarker expressions. For example:
  • verifyCode:
        component: "System.ConditionEquals"
        properties:
          variable: "code"
          value: "${userEnteredCode.value}"
        transitions:
          actions:
            equal: "wrongCode"
            notequal: "${flow.value}"
    
  • conditionEquals:
        component:"System.ConditionEquals"
        properties:
          source: "${addressVariable.value.state} - ${addressVariable.value.country}"
          value: "CA - USA"
        transitions:
          actions:
            equal: goCalfifornia
            notequal: goSomewhereElse
  • main: true
    name: "Shoppingbot"
    context:
      variables:
        yesnoVar: "YES_NO"
        
    ...
    
     confirmBuy:
        component: "System.ConditionEquals"
        properties:
          source: "${yesnoVar.value.yesno}"
          value: "YES"
        transitions:
          actions:
            equal: "deviceDone"
            notequal: "cancelOrder"
      deviceDone:
        component: "System.Output"
        properties:
          text: "Your ${devices.value} is on its way."
        transitions:
          return: "done"
      cancelOrder:
        component: "System.Output"
        properties:
          text: "Thanks for your interest."
        transitions:
          return: "done"
  • context:
      variables:
        wordLength: "int"
        words: "string"
    states:
      askName:
        component: "System.Text"
        properties:
         prompt: "What is your name?"
         variable: "words"
      setVariable:
        component: "System.SetVariable"
        properties: 
          variable: "wordLength"
          value: "${words.value?length}"
      conditionEquals:
        component: "System.ConditionEquals"
        properties:
          source: "${(wordLength.value?number > 2)?then('valid', 'invalid')}"
          value: "valid"
        transitions:
          actions:
            equal: "checkFirstNameinDatabase"
            notequal: "inValidName"
      done:
        component: "System.Output"
        properties:
          text: "Done"
        transitions:
          return: "done"
      checkFirstNameinDatabase:
        component: "System.Output"
        properties:
          text: "Check the first name in the database."
        transitions:
          return: "done"
      inValidName:
        component: "System.Output"
        properties:
          text: "This name is not valid. It needs to be at least three letters."
        transitions:
          return: "done"

System.ConditionExists

Use this component to check for the existence of a specified variable. To route the dialog according to the value, define the transitions key using exists and notexist actions.

Note

This component isn't available in the Visual Flow Designer. You can use the Switch for this purpose instead.
Properties Description Required?
variable The name of the variable Yes
main: true
name: "HelloKids"
context:
  variables:
    foo: "string"
    lastQuestion: "string"
    lastResponse: "string"
states:
  intent:
    component: "System.Intent"
    properties:
      variable: "iResult"
    transitions:
      actions:
        Talk: "checkUserSetup"
        unresolvedIntent: "checkUserSetup"
  checkUserSetup:
    component: "System.ConditionExists"
    properties:
      variable: "user.lastQuestion"
    transitions:
      actions:
        exists: "hellokids"
        notexists: "setupUserContext"
  setupUserContext:
    component: "System.CopyVariable"
    properties:
      from: "lastQuestion,lastResponse"
      to: "user.lastQuestion,user.lastResponse"
    transitions:
      ...
...

System.Switch

Use this component to switch states based on a variable value.

Note

This topic covers use of this component in YAML mode. For information on using it in the Visual Flow Designer, see Switch.
Enables value-based routing similar to the System.ConditionEquals component. The System.Switch component selects an execution path by comparing a list of values against a variable or source property. When the values match, the component triggers an action transition that names the state that starts the execution path. You can add a NONE transition when the current value set for the variable doesn’t match any of the items defined for the values property. Configure the Dialog Flow for Unexpected Actions describes how the System.Switch component enables your skill bot to gracefully handle incorrect user input.
switchOnCategory:
    component: "System.Switch"
    properties:
      variable: "category"
      values:
      - "Vehicle"
      - "Property"
      - "Other"
    transitions:
      actions:
        NONE: "ActionNoLongerAvailable"
        Vehicle: "getVehicleQuote"
        Property: "getPropertyQuote"
        Other: "getOtherQuote"
Property Description Required?
variable A variable whose current value is used as the basis for the switch transition. Define the values property as a list of comparison values. The Dialog Engine ignores the variable property when you have also defined the source property. No
source The source property is an alternate to the variable property. No
values The list of values used as comparisons against the source or variable properties.
Note

This property is not available in the Visual Flow Designer of the component. See Switch.
Yes

How Do I Use Apache FreeMarker Expressions with the System.Switch Component?

You you can narrow the matching criteria to specific values and formats by defining the value and source properties with Apache FreeMarker expressions. For example, you can define the expression using built-in FreeMarker operations, like date and string:
  switch2:
    component: "System.Switch"
    properties:
      source: "${startDate.value.date?string('dd-MM-yyyy')}"
      values:
      - "17-12-2017"
      - "18-12-2017"
    transitions:
      actions:
        "17-12-2017": goToday
        "18-12-2017": goTomorrow