macaroni

when

Description:
The when executor is used to conditionally execute a list of executors, depending if condition is true or false, as part of a multi-turn dialog.

Parent: dialog

Value:

# key/value compact form
- when:
  - (condition1, required)
  - (condition2, optional)
  - ...
  execute:
  - (executor1, required)
  - (executor2, optional)
  - ...
  expected:
  - (trigger1, optional)
  - (trigger2, optional)
  - ...
  unexpected:
  - (executor1, required)
  - (executor2, optional)
  - ...

# key/value compact example
- when:
  - missing: '{temperature}'
  execute:
  - speak: What temperature?

EXAMPLE

commands:

- triggers:
  - '{device} {#temperature} [degrees]'
  - '[{temp-verb}] [the] {device} [of the car]'
  - '[{temp-verb}] [the] {device} [of the car] (up | down)'
  - '{temp-verb} [the] {device} [of the car] [to] {#temperature} [degrees]'
  - '{temp-verb} [the] {device} [of the car] (up | down) [to] {#temperature} [degrees]'
  - "I'm [{anything}] {temp-statement}"
  - "it's [{anything}] {temp-statement} [in here]"
  - "Make it {temp-statement} [in here]"
  # it's cold in here

  execute:

  - dialog:

    - when:
      - required: '{temp-statement}'
      - missing: '{#temperature}'
      execute:
      - speak: What temperature would you like it to be?
      expect:
      - '[{anything}] {#temperature} [degrees]'
      unexpected:
        phrase:
        - speak: Didn't understand; What temperature, as a number between 60 and 90.
        command:
        - speak: OK. Now, What temperature would you like the cabin to be?

    - when: [ missing: '{#temperature}' ]
      execute:
      - speak: to what temperature?
      expect:
      - '{#temperature} [degrees]'
      - '{temp-verb} [it] [to] {#temperature} [degrees]'
      unexpected:
        phrase: retry
        command:
        - speak: What temperature would you like it to be?

    - when: [ condition: '{#temperature} < 60' ]
      execute:
      - speak: minimum is 60
      expect:
      - '[ok] {#temperature} [degrees]'
      - '{temp-verb} [it] [to] {#temperature} [degrees]'
      unexpected:
      - speak: What temperature would you like it to be?

    - when: [ condition: '{#temperature} > 90' ]
      execute:
      - speak: maximum is 90
      expect:
      - '[ok] {#temperature} [degrees]'
      - '{temp-verb} [it] [to] {#temperature} [degrees]'
      unexpected:
      - speak: What temperature would you like it to be?

  - speak: 'OK, setting the temperature to {#temperature} degrees'
  - broadcast:
      name: CarControl.SetTemperature
      value: '{#temperature}'

Additional information:

Status: ✅ IMPLEMENTED