如果您使用的是 nodejs,基于 IBM Developers 的简单对话示例,您可以执行以下操作:
还有节点:
访问此值的代码:
function updateMessage(input, data, req, res) {
console.log("Entties: "+JSON.stringify(data.entities));
//200 and 500 do something
if (data.entities[0].value == '200' && data.entities[1].value == '500') {
console.log("User choice value:" + data.entities)
// showProducts(data, req, res); do something inside this function
// or paste your code for do something here
}
调试:
Obs.:如果用户只输入一个值 (@sys-currency),您需要在一个条件下创建一个值,并获取此值以便在您的应用程序中使用我的示例:
data.entities //if have one value
data.entities[i] //Watson return some array if have more than 1 value
一个好主意是使用上下文变量并加入来获取所有值,例如:
{ "context": {
"result": "<? @sys-currency ?>"
}
},
如果您在上下文中传递所有库存商品并且您希望输出像我们有 X、Y、Z 库存,那么您可以在 Watson 中创建输出
<? context.results.join(', ') ?> //all values return
重要提示:您需要访问 Watson Conversation 调用 (conversation.message) 的 data 返回值,以访问实体、意图和上下文变量等所有值,其中。喜欢:
conversation.message(payload, function (err, data) {
console.log(data)
if (err) {
return res.status(err.code || 500).json(err);
}
}