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.
- Click the Edit (pencil) icon to open the
- 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.
- Enter the following code to create the context variable:
"parks":["Yellowstone", "Yosemite", "Arches"]
- To test your change, open the Chrome Developer tools.
- 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_startnode, which contains your context variable, was invoked. By previewing the response, you should see your context variable is now included in Watson’s response.
- Close the Advanced editor and open the
#listparksnode for editing.
- 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.
- To update the response to use the values from your context variable, remove the text
Yosemite, Yellowstone, and Archesfrom the
#listparksnode, and replace the text with
Note: The dollar sign specifies a context variable.
- Go to the Chat pane to test the conversation.
- Clear the conversation to reset it.
- Enter the text
You now see the output.The formatting is poor, but you’ll fix this in the next section.