Exercise 3 - Invoke and test the Weather request service from IBM Watson Assistant - Documentation for BMC Helix Virtual Agent 21.02
Invoke Process from Chatbot
The IT Chatbot workspace shipped with the Chatbot Starter Kit already has intents and entities created for Weather Service.
Intent:
The BMC_Weather Intent uses several annotated entities for City name. (Note this can include State names as well as Country names). Instead of adding all the City names in the world to the bmc_city entity we have used annotated entities to represent them. For more information regarding annotations please refer to the following link:
The following are some sample Intent values with annotated entities:
- How is weather in Hong Kong
- weather update please
- is weather good outside for long drive
- is it hot outside
- how is temperature in London
- How is temperature in Santa Clara
- How is weather in Moscow
Annotating the City names is done from the Intent by turning on the Annotate entities feature, selecting the city name from the Intent value and then choosing the entity to store the annotations as shown below.
Entity:
The entity @bmc_city only has a few cities specified as examples, but it can understand the context of the intent as if it was a city name because of the annotated city examples.
Dialog and Process invocation:
From the IT Chatbot skill, go to the Dialog section and look for the BMC- Weather update dialog. This is our first parent dialog node for this service. We have added the intent, #BMC_Weather in the condition, so that when Watson identifies this intent the parent dialog for this service gets triggered.
The BMC- Weather update dialog is simple. If the intent matches it initializes the weather_at_city variable with the @bmc_entity or chatbot_cityName (city of the logged in user from foundation Person data).
The following is the syntax for initializing the weather_at_city variable as seen from the Dialog:
weather_at_city = "<?@bmc_city ? @bmc_city.values.join(' ') : $chatbot_cityName?>"
The syntax is like the short if statement in java. It can be read as follows:
If @bmc_city entity is not null,
join all the values using a space (' ') as a separator
else
use the $chatbot_cityName variable
Please refer to the following link for the list of available context variables: Adding context to a chat conversation by using Person or application data
In addition, you can also reference the following Watson doc link:
From the BMC – Weather update dialog node, open the JSON Editor, by clicking the three vertical dots button located across from the "Then set context" text, to see how the Get Weather process is called.
Note that special JSON of "action" is added to the "output": { } section of the JSON.
Typically, the "output": { } JSON contains a "text" response that is sent to the user. For example, you can see this in any of the example Fill Question dialogs found in the sample use cases as displayed below:
For this use case, we do not want the process output to be sent to the user. Instead we want to evaluate the $status variable and then respond with a result or a message stating that either a city could not be found, or an error occurred.
In the screenshot below, we show how the JSON variables relate back to the process variables:
- Variable Ids and not variable names are used in the "action" attribute
- Process Input variables are set to Watson context variables
- Output of process from actionResult is set back into Watson variables
Variables are initialized by the Get Weather process. In the child node there is a check, if execution $status == "Success" we respond with the following html that is then displayed to the user from the Chatbot UI.
<b>$weather_at_city</b><br>
<img src="$image_url"/> <b> $current_temp</b>
<br>Clouds : $cloud_percent%
<br>Wind speed : $wind_speed
Chatbot supports basic html formatting, see the link below for more information:
Formatting chatbot responses to be displayed in communication channels