0

我目前正在使用 watson 聊天机器人对话应用程序。我遇到了我必须刷新上下文的情况,只是在某个阶段取决于用户输入,但我无法实现这一点。

I tried setting the context = {}, if the user input isn't in the Array, but it seems to check the context at every stage of the Application. 

if(context.city !== array[i]['city']){
        context = {};
 }

what i am asking the user is to input a list of cities, which is in an Array. If the user inputs a location that isn't in the Array first, it let's the user know that it isn't in the Array. If the user inputs a city that is not in the Array after inputing a city that is already in the array, it is returning the last context. 

for example,

City = Boston.
You just input Boston, price is 20.
Then if i do City = Atlanta(Bearing in mind Atlanta is not in the Array)
it does city is Atlanta, price is 20. 

Any idea how to fix this, on any steps i can follow to stop this from happening?
4

2 回答 2

1
  for(var i = 0; i < array.length; i++){
  if (context.city !== array[i]['city']){
    if(inputBox.value ===  context.city)
    {
    context = latestResponse.context;
    context.rate = rate;
    context.currency = currency;
    }
    else
    {
      context.city = "";
      context.rate = "";
      context.currency = "";
    }
  }
}

对于现在或将来可能遇到同样问题的其他人,

这就是为我解决的问题。所需的信息在一个数组中,所以我循环了它,并检查了 context.city != 数组。

于 2017-05-01T19:24:39.210 回答
0

您可以在您的应用程序或高级编辑器中将 context.city 设置为空字符串或 null, 在此处输入图像描述 然后在您的应用程序中基于此修复逻辑

于 2017-05-01T18:56:10.713 回答