Currently, I am delving into the world of Watson AI/Assistant in order to incorporate it into our services as a web development firm. To enhance my understanding of the assistant, I have embarked on a self-taught journey by creating a text-based adventure game. This game involves Watson guiding players through different scenarios where they can interact with objects like picking items up and putting them down. One challenge I am facing is figuring out how to manipulate a JSON array called an inventory within Watson.
While I successfully created the array using the context variable option, I encountered a roadblock when attempting to modify its contents easily due to the lack of capability for executing code within my Assistant environment.
My main query revolves around whether it is possible to trigger JavaScript code upon recognizing a specific intent. For instance, if a user inputs "pick up sand" with the intent identified as "pick up" and "sand" as the recognized entity, could I then execute JavaScript to update the "inventory" array with the retrieved entity (in this case, "sand")?
Is such functionality feasible within Watson Assistant?
I experimented with setting up the context variable as an array (which was successful). However, I struggled to perform updates without displaying the entire array, rendering it impractical as a functioning inventory system. The JSON array snippet below illustrates the initial setup containing the context variable addition:
{
"output": {
"generic": [
{
"values": [
{
"text": "Welcome to Kojoto."
}
],
"response_type": "text",
"selection_policy": "sequential"
},
{
"time": 5000,
"typing": false,
"response_type": "pause"
}
]
},
"context": {
"Inventory": [
{
"name": "belt",
"description": "A leather belt."
},
{
"name": "pouch",
"description": "A leather pouch."
}
]
}
}
I aim to be able to augment the inventory upon recognizing an intent without having to overwrite the entire array each time. This streamlined approach would significantly enhance efficiency and usability compared to toggling item presence in the array from "yes" to null.