2017-03-01 2 views
0

BotFramework 및 LUIS를 사용하는 내 봇을 자체 라이브러리에 격리하고 app.js로 가져 오려고합니다. 나는 BotFramework GitHub에 대한 튜토리얼과 예제를 따라 갔지만 아무데도 사용하지 않았다. 나는 그것을 자신의 파일에 루이스의 대화와 봇을 넣어 내보낼 후에는 루이스에게 도달하지 :BotFramework NodeJS Bot을 LUIS로 자체 라이브러리에 통합

은 해당 노드가 호출 파일 app.js에있는 경우이 코드는 작동
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); 
    } 
]); 

, 결코 나는 다른 로봇에서 사용하기 위해 그것을 분리하고 싶다.

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()); 

가 어떻게이 제대로 달성 할 수있다 : 여기

내 app.js입니까? 나는 이것을 올바르게 생각하지 않습니까?

UPDATE

내가 (bot.dialog가 triggerAction와 협력) 다른 구문을 사용하여 루이스 봇을 분리 할 수 ​​있었다 :

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

것은 코드의 상단 블록을 './bots/changeName'또는 내용인가 원래의 분리되지 않은 봇의 내용입니까? 봇 인스턴스를 두 번 만드는 것 같습니까? 나는. 빌더에게 전화가 두 번. 유니버설 봇? RequireJS의 module.export를 사용하여 포함하고있는 라이브러리에서 함수를 내보내고 서버에서 만든 bot 인스턴스를 해당 함수로 전달해야합니다. – Gareth

+0

프레임 워크에 조금 익숙해 져서 두 번 만들지 모르겠다. 그러나 내가 bot 자체를 export 할 때 다음과 같은 에러를 보게된다 : module.exports = {bot}; 내 의도는 내 자신의 프레임 워크를 구축하고 코드를 쉽게 유지할 수 있도록 LUIS 끝점 앱이있는 여러 개의 LUIS 지원 봇을 단일 위치로 가져올 수있게하는 것입니다. 가장 큰 문제는 구문과 관련이 있습니다 만, botJramework이 NodeJS에서 이러한 유형의 사고를 지원하는지 확실합니다. –

답변

0

루이스 사용하여 로봇을 분리하고 그것이 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 
});