1

I am trying to extend the wit-ai weather example by adding wit/datetime to the mix.

For example a user might type "How cold will it be in Berlin in 1 hour?" and the weather bot will bring back the data for the weather in 1 hour in Berlin.

So far this works, but when I try to setup missingDate in order to ask the date if it's missing it behaves kind of funny.

A dialogue would be: - How cold will it be in Berlin? - In what time? - In 1 hour.

Instead, after the 1 hour step, I get asked again for the location which is in the context, but instead is triggered again.

My action is named getForecast({context, entities}) and I have defined it as below:

actions:
[...],
    getForecast({ context, entities }) {

        console.log(`The current context is: ${JSON.stringify(context)}`);
        console.log(`Wit extracted ${JSON.stringify(entities)}`);

        // extract entity
        var location = firstEntityValue(entities, "location");
        var date     = firstEntityValue(entities, "datetime");
        // if the entity exists, do a remote weather call.
        if (date) {
            context.date = date;
            delete context.missingDate;
        } else {
            context.missingDate = true;
            delete context.date;
            delete context.forecast;
        }

        if (location) {
            context.forecast = '38 degrees';
            context.location = location;
            delete context.missingLocation;
        } else {
            context.missingLocation = true;
            delete context.forecast;
         }
           // return the context object
            return Promise.resolve(context);
}
Panagiotis
  • 1,539
  • 1
  • 14
  • 28

0 Answers0