Omnidip
Omnidip

Reputation: 1

Wit.ai seems to be jumping randomly between stories

I have two separate simple stories on my Wit.ai bot,

the first one takes in the word "Debug", sends "test" then runs a function that outputs context stuff to the console called test_context()

the second one takes in an address, runs a function that changes the context called new_session(), then sends a confirmation of the change to the user structured like "your location has been changed to {address}"

when I type directly into the wit.ai test console it seems to correctly detect the stories and run the corresponding functions, but when I try to use it through the Node.js API it seems to act completely randomly.

Sometimes when typing in an address it will run test_context() followed by new_session(), then output no text, sometimes it will just output the test text followed by the address text and run no functions, sometimes it will act correctly.

The same behavior happens when inputting "Debug" as well.

The back end is set up correctly, as 2 other stories seem to be working perfectly fine.

Both of these stories were working fine earlier today, I have made no changes to the wit stories themselves and no change to the back-end has even touched the debug function.

Is this a known issue?

Upvotes: 0

Views: 153

Answers (1)

Alex
Alex

Reputation: 75

I encountered this problem as well.

It appears to me as when you do not handle setting context variables in the story from wit.ai correctly (by setting them to null for example), it messes up the story. As a developer it is your own responsability to handle the story correctly "client side", so I can understand wit.ai lets weird stuff happen when you do not do this. Maybe wit.ai decided to jump stories to keep their bot from crashing, still remains a bit mysterious to me. Maybe your problem is of a different kind, just sharing a similair observation and my solution.

Exactly for reasons of testing I created three stories;

  1. handle greetings
  2. tell what the weather in city x is
  3. identify when you want to plan a meeting

The bot is connected to facebook and I handle actions (like planning a meeting) on my nodejs express server.

I said to the bot "I want to plan a meeting tomorrow", resulting in a wit date/time. One timeslot by the way. This is going ok. Then I sent the message "I want to plan a meeting this morning". This resulted in TWO date/time variables in the wit.ai context. In turn, my code could not handle this; two timestamps resulted in null (probably json message getting more complicated and I try to get the wrong field). This in turn resulted in null for the context variable that had to be returned.

So what I did is to catch the error for when the context variable is not filled and just fill in [wit.js could not find date]. This fixed the problem, even though I now of course need to handle this error better.

Old code:

'createAppointment': ({sessionId, context, text, entities}) => {
return new Promise(function(resolve, reject) {
    const myDateTime = firstEntityValue(entities, 'datetime');
    console.log('the time trying to send ',myDateTime);
    createAppointment(context, myDateTime)
    context.appointmentText = myDateTime
    return resolve(context);
 },}

New, working code:

'createAppointment': ({sessionId, context, text, entities}) => {
return new Promise(function(resolve, reject) {
    const myDateTime = firstEntityValue(entities, 'datetime');
    console.log('the time trying to send ',myDateTime);
    if(myDateTime){
      createAppointment(context, myDateTime)
      context.appointmentText = myDateTime
      return resolve(context);
    } else {
      context.appointmentText = '[wit.js could not find date]'
      return resolve(context);
    }
  });
},

Hope this helps

Upvotes: 0

Related Questions