Reputation: 33
My webhook returns an array of elements. I need to make IBM Watson Assistant respond with those elements as options to the users.
How can I achieve that?
Upvotes: 0
Views: 819
Reputation: 33
@data_henrik response was very helpful but it was little vague. So, I thought to post my own answer. I made some changes in my function so that the result it returns matches the options format just like in the image below.
And just as @data_henrik suggested, I stored that result in a context variable named myOptions and used it like :
<? output.generic.addAll($myOptions) ?>
Upvotes: 1
Reputation: 17118
The JSON structure for an IBM Watson Assistant answer with options is documented. You already mentioned that your webhook returned an array of elements. It would need to match that structure.
Now, in your dialog you would need to add that options array myOptionsArray to your output. Assuming the array data is stored in the variable myvar, use something like this:
<? output.generic.addAll($myvar.myOptionsArray) ?>
The generic refers to the generic JSON output format - in contrast to the integrations JSON format. The above expression could be placed in a response or in some intermediate assignment. It might need some experimenting but works...
Upvotes: 1