Reputation: 11
I started working on bot framework in node.js and used luis.ai for my nlp. Referring the documentation on azure for their botframework for node.js, I did the code changes in app.js. However I am getting the following error when running the code in online editor.
[info] Restarting server... [info] Click on http://firstbot2-b893.azurewebsites.net to open your site restify listening to http://undefined:undefined
Also, a new browser window opens with following error...
code "ResourceNotFound" message "/ does not exist"
Please find the app.js and package.json code below...
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 tableName = 'botdata';
var azureTableClient = new botbuilder_azure.AzureTableClient(tableName, process.env['AzureWebJobsStorage']);
var tableStorage = new botbuilder_azure.AzureBotStorage({ gzipData: false }, azureTableClient);
// Create your bot with a function to receive messages from the user
//var bot = new builder.UniversalBot(connector);
// Create your bot with a function to receive messages from the user
// This default message handler is invoked if the user's utterance doesn't
// match any intents handled by other dialogs.
var bot = new builder.UniversalBot(connector, function (session, args) {
session.send('You reached the default message handler. You said \'%s\'.', session.message.text);
});
bot.set('storage', tableStorage);
// Make sure you add code to validate these fields
var luisAppId = process.env.LuisAppId;
var luisAPIKey = process.env.LuisAPIKey;
var luisAPIHostName = process.env.LuisAPIHostName || 'westus.api.cognitive.microsoft.com';
const LuisModelUrl = 'https://' + luisAPIHostName + '/luis/v2.0/apps/' + luisAppId + '&subscription-key=' + luisAPIKey;
// Main dialog with LUIS
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
// Add the recognizer to the bot
bot.recognizer(recognizer);
var intents = new builder.IntentDialog({ recognizers: [recognizer] })
.matches('Greeting', (session) => {
session.send('You reached Greeting intent, you said \'%s\'.', session.message.text);
})
.matches('Help', (session) => {
session.send('You reached Help intent, you said \'%s\'.', session.message.text);
})
.matches('Cancel', (session) => {
session.send('You reached Cancel intent, you said \'%s\'.', session.message.text);
})
.matches('Reports', (session) => {
session.send('You reached Reports intent, you said \'%s\'.', session.message.text);
})
.onDefault((session) => {
session.send('Sorry, I did not understand \'%s\'.', session.message.text);
});
//bot.dialog('/', intents);
{
"name": "luisbot",
"version": "1.0.0",
"description": "",
"main": "app.js",
"dependencies": {
"botbuilder": "^3.13.1",
"botbuilder-azure": "^3.0.4",
"restify": "^5.0.0"
},
"devDependencies": {
"request": "^2.81.0",
"zip-folder": "^1.0.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Upvotes: 1
Views: 531
Reputation: 1642
var bot = new builder.UniversalBot(connector, function (session, args) {
session.send('You reached the default message handler. You said \'%s\'.',
session.message.text);
});
This second parameter counts as a root dialog ('/'
), which is why you received the error message regarding the dialog already existing.
You're also plugging the LuisRecognizer
into the bot
level and then into an IntentDialog
:
// Main dialog with LUIS
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
// Add the recognizer to the bot
bot.recognizer(recognizer);
var intents = new builder.IntentDialog({ recognizers: [recognizer] })
You should only use one or the other, especially when starting off and when only using one created LuisRecognizer
.
I recommend changing your var bot
line to:
var bot = new builder.UniversalBot(connector);
And then using your IntentDialog
only with your root dialog, by uncommenting this line:
//bot.dialog('/', intents);
Upvotes: 1
Reputation: 143
Is there a reason this is commented out:
//bot.dialog('/', intents);
Seems you need to define somewhere for dialog to listen, and matches up with the "/" no resource found error.
Upvotes: 1