Reputation: 137
I'm trying to put together a simple weather bot in the MS Bot Framework, but I'm running into an issue where Prompts.text appears to be immediately skipping past actually waiting for user input (testing in the emulator).
I've cut out a bunch of code but the following still repros:
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();
}
]);
In the case where a location is not found by the findEntity
call in the third line of the code, what happens is we move in to the getLocation dialog, and then immediately go through it without waiting for the user to type something in response. From the console output I see:
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
and in the Bot Framework Emulator itself you can see that a message was never sent from the client to the 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...
I'm sure I'm missing something simple here, but I simply cannot spot it. If anyone has any ideas I'd love to hear them!
Upvotes: 0
Views: 896
Reputation: 622
You want to move the next()
call into the else block in the first step of the checkWeather waterfall. The code after the prompt is still executed, so it was calling next after sending entering the new dialog and getting all confused.
So your first function will look like
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();
}
}
Upvotes: 2