Reputation: 170
My question is : how to append a value given by a user to an entity. The user provided value is dynamic.
The Watson response overwrites the toppings variable with the value given by the user, as you can see in the attached image.
{
"output": {
"text": "I got an order to add one or more toppings.
Adding <?context.toppings.append('toppings')?>.
Toppings to provide: <?entities['toppings']?.toString()?>"
},
"context": {
"toppings": "<? entities['toppings']?.toString()?>"
}
}
Upvotes: 0
Views: 782
Reputation: 1326
You can append to an array with the .append()
function.
In your example, the expression "toppings": "<? entities['toppings']?.toString()?>"
will overwrite the toppings variable every time this node is processed with the actual recognized entities @toppings
. First the the $toppings
variable needs to be defined as an array, e.g.:
"context" : {
"toppings" : []
}
Then in context
part of a dialog node you can write:
"context" : {
"toppings" : "<?$toppings.append(entities['toppings'].toJsonArray())?>"
}
More info in our doc: Watson Conversation Doc
EDIT: Thinking about this, it is probably not a good idea to have the same name for the entity and for the variable you store it in. :-)
Upvotes: 1