Watson Conversation:检查上下文变量的存在并采取行动?

Watson Conversation: Check and act on existence of context variable?

我在对话节点中使用 IBM Watson Conversation service 和插槽。在响应中,我想 return 使用插槽收集的上下文变量的值。但是,我不能确定该变量是否存在,因为用户可能已经取消了输入过程并且该变量是可选的。我如何检查是否存在并根据该检查采取行动?

使用这个

<? $myVariable ?>

当变量不存在时给出错误。

Conversation service uses Spring Expression Language (SpEL) to process variables and conditions in its responses. There is a special check that can be applied. I have taken the example from this useful collection of use cases:

"<? context.myVariable? 'Great. I have the following: '+context.myVariable+'.' : 
'No information present' ?>"

您可以通过 context 后跟变量名来访问上下文变量。问号 (?) 检查是否存在。如果存在变量,则采用第一个响应,否则采用第二个响应。冒号 (:) 分隔两个答案选项。

在上面的例子中,答案是“Great. I have the following: VALUE”或“No information present”。