Enhance the sample application

In this section, you will enhance the sample application by writing code and working with the Watson Conversation tool. Your enhancements will enable the server to return information about a park through the Watson Conversation response. Each time a user asks for details about (#tellmeabout) a particular park, the server should look up that park by name in the ParksDatabase. The lookup will return the park’s data object, which should then be added to the Watson Conversation response payload.

You will also use conversation context in a variety of ways. First, you will use it to store the list of known (known to the system) national park names. Second, you will use context to keep track of the last park name referenced by the user. This tracking enables the server to respond with park details even if the user didn’t explicitly state a park name in the current utterance, for example, “What animals live there?”

This section might be more challenging than the sections in previous labs. In this lab, some steps do include all the details needed to implement the step. This approach is meant to be a challenge. If you get stuck, don’t fret; simply look ahead that the solution video.

    Let’s get started:

  1. Open the file server/api/services/discourse/discourse.handler.js. This is where all of your code will go. This file also provides a good set of code comments describing how to implement the new functionality. These comments are your friend!
  2. Store the known parks in context. The server must set the known list of national parks:
    1. Modify the context object in the response r to include the parks property.
    2. Set the parks property equal to the array of known park names. Set the parks property only on the first dialog turn.
      Hint: You can get the array of parks by calling ParksDatabase.all() method. You also can determine the dialog turn by inspecting the context.system object and looking for dialog_turn_counter. The ParksDatabase.all()method returns a list of park objects, not park names.
  3. Test your work by entering an input such as show me a list of parks. Be sure that all known parks used in this lab appear in the response. You can also use Chrome development tools to view the response payload.
  4. Store the park name that the user is asking about. The server should create a park context variable to track the park name. Examine the entities object in the response r. If the NationalParks entity is detected, update the context object to include the property park and set park equal to the value of the NationalParks entity.
  5. Test your work by inspecting the response payload.
  6. Return the park object with the response payload. The server should look up the park by name by using ParksDatabase.It must then return that park’s data object as part of the response payload. It must add the parkproperty (with the park object as its value) to the response’s output object.
      1. Examine the

    intents

      1.  object in the response

    r

      1. . If the top intent is the

    tellmeabout

       intent, follow these steps:

    1. Get the park name from the response’s context object.
    2. Add the property park to the response’s output object.
    3. Set the value of park to the park object.
  7. Test your work by using the input Tell me about Zion or inspect the response payload.
  8. Create new dialog nodes to enable the conversation to answer questions about the plant life for each national park. For example, try the following inputs for animals. After you complete your work, you should be able to ask and answer similar inputs for plants.Example 1
      • User: Tell me about the animals.
      • Watson: For which national park?
      • User: Jelly Beans!
      • Watson: Hmm. I don’t know that national park.

    Example 2

      • User: Tell me about the animals.
      • Watson: For which national park?
      • User: Zion.
      • Watson: <answer>

    Example 3

    • User: Tell me about the animals in Denali.
    • Watson: <answer>

Hint: Use the following nodes as a guide. These nodes implement the functionality for animals. Use these as a template and re-create something similar to handle plants.

The response’s output object for animals contains the property “cardType”“animals”. For plants, use “cardType”“plants”.