在wit-ai天气示例中更新时间和日期

时间:2017-04-24 22:59:57

标签: node.js wit-ai

我试图通过添加机智/日期时间来扩展机智天气示例。

例如,用户可能会输入" 1小时内在柏林会有多冷?"天气机器人将在柏林1小时内恢复天气数据。

到目前为止,这是有效的,但是当我尝试设置missingDate以询问日期是否遗漏时,它表现得很有趣。

对话将是: - How cold will it be in Berlin? - In what time? - In 1 hour.

相反,在1小时后,我再次被问到上下文中的位置,而是再次触发。

我的操作名为getForecast({context, entities}),我将其定义如下:

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);
}

0 个答案:

没有答案