我想将使用BotFramework和LUIS的机器人隔离到它自己的库中并将其导入app.js.我按照BotFramework GitHub上的教程和示例进行了操作,但它让我无处可去。一旦我将带有LUIS对话框的机器人放入其自己的文件并导出它,它就永远不会到达LUIS:
var builder = require('botbuilder');
//Import our libraries
var profileDialogue = require('../dialogues/profileDialogue');
//=========================================================
// Bot Setup
//=========================================================
// Create chat bot
var bot = new builder.UniversalBot(null, null, 'changeName');
// Add locale tools library to bot
bot.library(profileDialogue.createLibrary());
// Export createLibrary() function
exports.createLibrary = function() {
return bot.clone();
}
var model = URL;
var recognizer = new builder.LuisRecognizer(model);
var dialog = new builder.IntentDialog({ recognizers: [recognizer] });
//=========================================================
// Bots Dialogs
//=========================================================
bot.dialog('/changeName', dialog);
bot.dialog('change name', [
function(session, args, next) {
console.log(args);
if (args.score > 0.5) {
profileDialogue.profile(session);
}
},
function(session, results) {
session.send('Ok... Changed your name to %s', session.userData.name);
}
]);
此代码仅在节点调用的app.js文件中存在时才有效,从未希望将其隔离以用于其他机器人。
这是我的app.js:
var restify = require('restify');
var builder = require('botbuilder');
//Import our libraries
var changeName = require('./bots/changeName');
//=========================================================
// Bot Setup
//=========================================================
// 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 bot
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());
//=========================================================
// Bots Dialogs
//=========================================================
bot.dialog('/', [function(session, args, next) { session.send("I don't understand") }]);
// Add locale tools library to bot
bot.library(changeName.createLibrary());
如何正确实现这一目标?我没有以正确的方式思考这个问题吗?
更新
我能够通过使用不同的语法(bot.dialog与triggerAction合作)来隔离LUIS bot:
bot.dialog('/changeName', [
function(session, args, next) {
if (args && args.intent && args.intent.score && args.intent.score > 0.5) {
console.log(args);
profileDialog.profile(session);
}
},
function(session, results) {
session.send('Ok... Changed your name to %s', session.userData.name);
}
]).triggerAction({
matches: 'change name',
intentThreshold: .50
});
我剩下的最后一个问题是父app.js需要拥有LUIS端点,如果我的孩子机器人有这个问题并不重要。还有其他想法吗?
答案 0 :(得分:0)
使用此代码将隔离僵尸程序,并允许使用LUIS将其调用到app.js文件中:
bot.dialog('/changeName', [
function(session, args, next) {
if (args && args.intent && args.intent.score && args.intent.score > 0.5) {
console.log(args);
profileDialog.profile(session);
}
},
function(session, results) {
session.send('Ok... Changed your name to %s', session.userData.name);
}
]).triggerAction({
matches: 'change name',
intentThreshold: .50
});