i'm here to ask of any of you guys know why my bot won't start the dialog? I'm a new guy in the world of bots and read a lot of it, but can't seem to fix this.
var restify = require('restify');
var builder = require('botbuilder');
// 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.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var luisAppUrl = process.env.LUIS_APP_URL || 'https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/.......';
var bot = new builder.UniversalBot(connector);
var bot = new builder.UniversalBot(connector, function(session, args, next) {
session.send('How can i help you ?')
session.endDialog();
next();
});
bot.recognizer(new builder.LuisRecognizer(luisAppUrl));
bot.dialog('Location', [
function (session, args, next) {
var intent = args.intent;
var locations = builder.EntityRecognizer.findEntity(intent.entities, 'Location');
var location = session.dialogData.location = {
title: title
};
// session.send()
if (!locations){
builder.Prompts.text(session, 'From which settlement do you want to know the location? ')
} else {
next();
}
},
function(session, results) {
var location = session.dialogData.location;
if(results.response){
note.text = results.response;
// session.send('Our company is located in Antwerp')
}
}
]).cancelAction({
matches: /^(cancel|nevermind)/i,
confirmPrompt: "Are you sure?"
});
So my bot just keeps crashing and doesn't start the bot.dialog ? Can you guys see what is wrong ?
The bot is crashing because you're instantiating the UniversalBot
class twice:
var luisAppUrl = process.env.LUIS_APP_URL // etc
var bot = new builder.UniversalBot(connector);
var bot = new builder.UniversalBot(connector, function(session, args, next) {
session.send('How can i help you ?')
session.endDialog();
next();
});
Try removing the first bot
so your code is just:
var luisAppUrl = process.env.LUIS_APP_URL // etc
var bot = new builder.UniversalBot(connector, function(session, args, next) {
session.send('How can i help you ?')
session.endDialog();
next();
});
EDIT:
To reach the 'Location'
dialog, you'll need to add a triggerAction()
to your dialog
.
bot.dialog('Location', [
function (session, args, next) {
// ...
},
function(session, results) {
// ...
}
]).triggerAction({
matches: 'Location' // What your intent from LUIS is called.
}).cancelAction({
matches: /^(cancel|nevermind)/i,
confirmPrompt: "Are you sure?"
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.