Conditional action example: zoom with error handling

The zoom example on the previous page is over-simplified. Many commands return values that the dialogue uses in its responses. Let’s extend the zoom example to let the calling application return an error message if the user zooms in or out too far.

Command

First, we extend the zoom command to return a error message. After each command, the calling application calls ProcessCommandResult and can pass arbitrary string parameters back. The command file defines those parameters so the dialogue can use them.


inputs:
  - zoom_direction
  - zoom_amount

outputs: 
  - demo_error

Story

Next we extend the story to add a conditional action. A conditional action gives different responses depending on the value of any parameter in memory– either input from the user or output parameters returned from the calling application in response to a command.

In this example, the calling application returns a code for different kinds of errors, and Diatheke gives different replies depending on the value of the error code. If none of the conditions, are met (i.e. the calling app does not return an error), it returns the default reply.

Diatheke will choose the most appropriate utterance from the specified reply file based on which entity values are defined, so it is not necessary to have a separate condition for every combination. For example, for the zoomInMax condition, if the user says “Zoom in 900 percent”, the zoom_amount entity is defined, so Diatheke will choose the response that includes zoom_amount and will say “Sorry, 900 percent zooms in too far.” But if the user just said “Zoom in” without specifying an amount, Diatheke will respond “Sorry, can’t zoom in any further.”


start_actions:
  - type: command
    id: zoom_command
  - type: conditional
    id: parameters_specified

conditional_actions:
  - name: parameters_specified
    conditions:
      - condition: ${demo_error}.is(appError)
        actions:
          - type: reply
            id: zoom_app_error_reply
      - condition: ${demo_error}.is(zoomInMax)
        actions:
          - type: reply
            id: zoom_in_error_reply
      - condition: ${demo_error}.is(zoomOutMax)
        actions:
          - type: reply
            id: zoom_out_error_reply
    default_actions:
      - type: reply
        id: zoom_reply

Replies

Each tab below shows the definition of a different reply. The file name matches the id specified in the conditional action of the story.


language_data:
  en_US:
    - Sorry, there was an error attempting to zoom.

language_data:
  en_US:
    - Sorry, can't zoom in any further.
    - Sorry, ${zoom_amount} zooms in too far.

language_data:
  en_US:
    - Showing full picture.

language_data:
  en_US:
    - Zooming in.
    - Zooming in ${zoom_amount}.
    - Zooming ${zoom_direction}.
    - Zooming ${zoom_direction} ${zoom_amount}.

Note

Since parameters are strings, the calling application could explicitly pass in an error message for Diatheke to read back. However, this is not recommended because it is a better separation of concerns to have all the wording for the dialogue contained in the model, not hard-coded into the client application. Using an error code rather than a hard-coded message also allows a model to respond in different languages without code changes. (see Multi-lingual models).

So far, we have only shown a single-turn interaction, but Diatheke can model much more complex stories. We’ll illustrate how the user may express different intents during the course of one story in the apply_filters story.