BotFramework Prompts.text()立即跳到瀑布的下一步

时间:2017-03-21 04:43:09

标签: node.js botframework

我正在尝试在MS Bot框架中组合一个简单的天气机器人,但我遇到了一个问题,Prompts.text似乎立即跳过实际等待用户输入(在模拟器中测试)。

我已经删除了一堆代码但是仍然存在以下代码:

bot.dialog('checkWeather', [
    function (session, args, next) {
        var location = builder.EntityRecognizer.findEntity(args.intent.entities, "builtin.weather.absolute_location");

        if (!location) {
            session.beginDialog("getLocation");
        } else {
            session.privateConversationData.location = location.entity;
        }

        next();
    },
    function (session, results, next) {
        var location = session.privateConversationData.location;

        session.send('Okay! I am going to check the weather in %s!', location);
    }
])
    .triggerAction({ matches: 'builtin.intent.weather.check_weather' });

bot.dialog('getLocation', [
    function (session) {
        builder.Prompts.text(session, 'For which area would you like me to check the weather?');
    },
    function (session, results) {
        session.privateConversationData.location = results.response;
        console.log('Location entered was: %s', results.response);
        session.endDialog();
    }
]);

如果代码的第三行中的findEntity调用找不到位置,那么我们将进入getLocation对话框,然后立即通过它而无需等待用户在响应中键入内容。从控制台输出我看到:

ChatConnector: message received.
session.beginDialog(*:checkWeather)
checkWeather - waterfall() step 1 of 2
checkWeather - session.beginDialog(getLocation)
.getLocation - waterfall() step 1 of 2
.getLocation - session.beginDialog(BotBuilder:Prompts)
..Prompts.text - session.send()
..Prompts.text - session.sendBatch() sending 1 messages
..Prompts.text - session.endDialogWithResult()
.getLocation - waterfall() step 2 of 2
Location entered was: undefined
.getLocation - session.endDialog()
checkWeather - waterfall() step 2 of 2
checkWeather - session.send()
checkWeather - session.sendBatch() sending 1 messages

在Bot框架模拟器本身中,您可以看到消息从未从客户端发送到机器人:

[21:32:14] -> POST 202 [message] Hows the Weather 
[21:02:14] <- GET 200 getUserData 
[21:02:14] <- GET 200 getPrivateConversationData 
[21:02:15] <- POST 200 setPrivateConversationData 
[21:02:15] <- POST 200 Reply[message] For which area would you like me to check the weat... 
[21:02:15] <- POST 200 setPrivateConversationData 
[21:02:15] <- POST 200 Reply[message] Okay! I am going to check the weather in undefined... 

我确定我在这里遗漏了一些简单的东西,但我根本无法发现它。如果有人有任何想法,我很乐意听到他们!

1 个答案:

答案 0 :(得分:2)

您想在checkWeather瀑布的第一步中将next()调用移动到else块中。提示后的代码仍然执行,因此在发送进入新对话框并让所有人感到困惑之后,它正在调用下一个。

所以你的第一个功能看起来像

function (session, args, next) {
    var location = builder.EntityRecognizer.findEntity(args.intent.entities, "builtin.weather.absolute_location");

    if (!location) {
        session.beginDialog("getLocation");
    } else {
        session.privateConversationData.location = location.entity;
        next();
    }
}