简体   繁体   中英

How to respond with dynamic options in IBM Watson Assistant?

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?

@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) ?>

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM