I am currently trying to write a Chatbot with Microsofts Bot Framework. I want to use a choice-prompt but it does not wait for me/the user to choose an option. Not even the example-code from here worked for me. See this working example:
var restify = require('restify');
var builder = require('botbuilder');
var botbuilder_azure = require("botbuilder-azure");
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
openIdMetadata: process.env.BotOpenIdMetadata
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
var bot = new builder.UniversalBot(connector);
bot.set('storage', new builder.MemoryBotStorage());
var luisAppId = process.env.LuisAppId;
var luisAPIKey = process.env.LuisAPIKey;
var luisAPIHostName = process.env.LuisAPIHostName || 'westus.api.cognitive.microsoft.com';
var LuisModelUrl = 'https://' + luisAPIHostName + '/luis/v2.0/apps/' + `enter code here`luisAppId + '?subscription-key=' + luisAPIKey;
/**
* RECOGNIZERS
*/
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
bot.recognizer(recognizer);
/**
* DIALOG SECTION
*/
var intents = new builder.IntentDialog({ recognizers: [recognizer] });
bot.dialog('/', intents);
intents.onDefault([
function(session){
session.send('I am sorry but I don`t know that.');
}
]);
intents.matches('City' ,[
function(session, args) {
session.beginDialog('getLocationDialog');
session.endDialog();
}
]);
var locationLabels = {
City1: 'City 1',
City2: 'City 2',
City3: 'City 3'
};
bot.dialog('getLocationDialog', [
function (session) {
builder.Prompts.choice(session, "Choose a city", locationLabels
, { listStyle: builder.ListStyle.button },{
maxRetries: 3,
retryPrompt: 'This is not a valid option. Choose one of the options listed above.' });
},
function (session, results) {
console.log(results.response.entity);
if (results.response){
var location = locationLabels[results.response.entity];
session.send('You are interested in %s', location);
session.endDialog();
}
else {
session.send('Okay.');
session.endDialog();
}
}
]);
The dialog with the prompt is this part (the intent is matched using LUIS):
intents.matches('City' ,[
function(session, args) {
session.beginDialog('getLocationDialog');
session.endDialog();
}
]);
var locationLabels = {
City1: 'City 1',
City2: 'City 2',
City3: 'City 3'
};
bot.dialog('getLocationDialog', [
function (session) {
builder.Prompts.choice(session, "Choose a city", locationLabels
, { listStyle: builder.ListStyle.button },{
maxRetries: 3,
retryPrompt: 'This is not a valid option. Choose one of the options listed above.' });
},
function (session, results) {
console.log(results.response.entity);
if (results.response){
var location = locationLabels[results.response.entity];
session.send('You are interested in %s', location);
session.endDialog();
}
else {
session.send('Okay.');
session.endDialog();
}
}
]);
See this code in action
The bot does not wait for me to choose an option. Can somebody tell where the problem is?