Warning: count(): Parameter must be an array or an object that implements Countable in /home/iteanz/public_html/wp-includes/post-template.php on line 317

Add context variables

Context variables help you speed up the process of providing responses by allowing you to reuse the names of things, such as the names of the national parks.

For example, you’ve created responses that include the names of the parks. However, if you add or remove park names, you don’t want to be forced to update every response that you’ve created. With context variables, you can make this update one time.

  1. Click the Edit (pencil) icon to open the conversation_start node.
  2. Open the Advanced editor (click the icon with curly brackets surrounding an ellipsis).In this editor, you see a JSON representation of the response that you created in the graphical user interface.

  3. Enter the following code to create the context variable: 
    "parks":["Yellowstone", "Yosemite", "Arches"]
  4. To test your change, open the Chrome Developer tools.
  5. Click the Network tab and clear the conversation.Note that this action invokes the conversation API’s message endpoint with a payload that resets the conversation. This means that the conversation_start node, which contains your context variable, was invoked. By previewing the response, you should see your context variable is now included in Watson’s response.
  6. Close the Advanced editor and open the #listparks node for editing.
  7. In the Chat pane, enter list the parks.
    You see the response of I can tell you about Yosemite, Yellowstone, and Arches. These are not the parks you added to context.
  8. To update the response to use the values from your context variable, remove the text Yosemite, Yellowstone, and Arches from the #listparks node, and replace the text with $parks.
    Note: The dollar sign specifies a context variable.
  9. Go to the Chat pane to test the conversation.
  10. Clear the conversation to reset it.
  11. Enter the text list parks.
    You now see the output.The formatting is poor, but you’ll fix this in the next section.