2017-05-01 3 views
0

Je travaille actuellement avec l'application de conversation watson chatbot. Je me suis retrouvé dans une situation où je dois actualiser un contexte, juste à un certain stade en fonction de l'entrée de l'utilisateur, mais je n'ai pas réussi à le faire.Contexte de conversation 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? 

Répondre

0

Vous pouvez définir context.city à une chaîne vide ou null dans votre application ou dans l'éditeur avancé enter image description here puis dans votre application logique de solution sur cette base

+0

Merci, j'ai trouvé un moyen de le faire environ 10 minutes après l'avoir posté. Je vous remercie. –

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 = ""; 
    } 
    } 
} 

Pour quelqu'un d'autre qui pourrait être en train de traverser le même problème maintenant ou dans le futur,

Ce fut ce qui a résolu pour moi. Les informations nécessaires étaient dans un tableau, donc j'ai bouclé dessus, et vérifié si le contexte.city! = Array.