BotFramework Prompts.text() 立即跳到 Waterfall 的下一步
BotFramework Prompts.text() skipping immediately to the next step in Waterfall
我正在尝试在 MS Bot Framework 中组装一个简单的天气机器人,但我 运行 遇到了一个问题,其中 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 Framework Emulator 本身中,您可以看到消息从未从客户端发送到机器人:
[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...
我确定我在这里遗漏了一些简单的东西,但我就是无法发现它。如果有人有任何想法,我很乐意听取他们的意见!
您想将 next()
调用移动到 checkWeather 瀑布第一步中的 else 块中。提示后的代码还在执行,原来是send后调用next进入新对话框,一头雾水
所以你的第一个函数看起来像
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();
}
}
我正在尝试在 MS Bot Framework 中组装一个简单的天气机器人,但我 运行 遇到了一个问题,其中 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 Framework Emulator 本身中,您可以看到消息从未从客户端发送到机器人:
[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...
我确定我在这里遗漏了一些简单的东西,但我就是无法发现它。如果有人有任何想法,我很乐意听取他们的意见!
您想将 next()
调用移动到 checkWeather 瀑布第一步中的 else 块中。提示后的代码还在执行,原来是send后调用next进入新对话框,一头雾水
所以你的第一个函数看起来像
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();
}
}