首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从luis.ai到bot框架获得响应,而是得到错误

无法从luis.ai到bot框架获得响应,而是得到错误
EN

Stack Overflow用户
提问于 2018-02-19 10:36:30
回答 2查看 494关注 0票数 1

我开始在node.js中开发bot框架,并在我的nlp中使用luis.ai。参考node.js僵尸框架中关于azure的文档,我在app.js中进行了代码更改。但是,在在线编辑器中运行代码时,我会得到以下错误。

信息重启服务器..。信息点击http://firstbot2-b893.azurewebsites.net打开你的网站重新注册收听http://undefined:undefined

另外,一个新的浏览器窗口打开时会出现以下错误.

代码"ResourceNotFound“消息"/不存在”

请在下面找到app.js和package.json代码..。

app.js

代码语言:javascript
复制
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);

package.json

代码语言:javascript
复制
{
  "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"
}
EN

回答 2

Stack Overflow用户

发布于 2018-02-19 15:22:27

是否有理由对此作出评论:

代码语言:javascript
复制
//bot.dialog('/', intents);

似乎您需要在某个地方定义对话框来侦听,并与"/“没有找到资源的错误进行匹配。

票数 1
EN

Stack Overflow用户

发布于 2018-02-20 18:51:27

代码语言:javascript
复制
var bot = new builder.UniversalBot(connector, function (session, args) {
    session.send('You reached the default message handler. You said \'%s\'.', 
        session.message.text);
});

第二个参数算作根对话框('/'),这就是为什么您收到了有关已经存在的对话框的错误消息。

您还将LuisRecognizer插入到bot级别,然后插入到IntentDialog

代码语言:javascript
复制
// 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] })

您应该只使用其中一种或另一种,特别是在开始时和仅使用其中一种创建的LuisRecognizer时。

我建议将var bot行更改为:

代码语言:javascript
复制
var bot = new builder.UniversalBot(connector);

然后,只在根对话框中使用您的IntentDialog,取消对以下行的注释:

代码语言:javascript
复制
//bot.dialog('/', intents);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48864229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档