简体   繁体   English

如何使用 IBM Watson Assistant 中的动态选项做出响应?

[英]How to respond with dynamic options in IBM Watson Assistant?

My webhook returns an array of elements.我的 webhook 返回一个元素数组。 I need to make IBM Watson Assistant respond with those elements as options to the users.我需要让 IBM Watson Assistant 响应这些元素作为用户的选项。

How can I achieve that?我怎样才能做到这一点?

@data_henrik response was very helpful but it was little vague. @data_henrik 的回复非常有帮助,但有点含糊。 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 :正如@data_henrik 所建议的那样,我将该结果存储在名为myOptions的上下文变量中,并像这样使用它:

<? output.generic.addAll($myOptions) ?>

The JSON structure for an IBM Watson Assistant answer with options is documented . 包含选项的 IBM Watson Assistant 答案的 JSON 结构已记录在案 You already mentioned that your webhook returned an array of elements.您已经提到您的 webhook 返回了一个元素数组。 It would need to match that structure.它需要匹配该结构。

Now, in your dialog you would need to add that options array myOptionsArray to your output.现在,在您的对话框中,您需要将该选项数组myOptionsArray添加到您的输出中。 Assuming the array data is stored in the variable myvar , use something like this:假设数组数据存储在变量myvar 中,请使用以下内容:

<? output.generic.addAll($myvar.myOptionsArray) ?>

The generic refers to the generic JSON output format - in contrast to the integrations JSON format.通用是指通用 JSON 输出格式- 与集成 JSON 格式相反。 The above expression could be placed in a response or in some intermediate assignment.上面的表达式可以放在响应中或一些中间赋值中。 It might need some experimenting but works...它可能需要一些实验,但有效......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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