2017-03-01 5 views
0

BotFrameworkとLUISを使用するボットを自分のライブラリに分離してapp.jsにインポートしたい私はBotFramework GitHubのチュートリアルとサンプルに従っていましたが、私はどこにもいません。私はそれ自身のファイルにLUIS対話とボットを入れて、それをエクスポートしたら、それはLUISに手を差し伸べたことがない: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); 
    } 
]); 

、決して私は他のボットで使用するためにそれを分離したい。ここで

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

どのように私はこれを適切に達成することができますか?私はこれについて正しい考え方をしていませんか?

UPDATE

私は(bot.dialogがtriggerActionと提携)異なる構文を使用してLUISボットを分離することができました:

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」の内容コードの先頭のブロックですか、あなたの元の未分離のボットの内容ですか?あなたはbotインスタンスを2回作成しているようですか?私。 builder.UniversalBotへの2回の呼び出し? RequireJSのmodule.exportを使用して、あなたが含むライブラリから関数をエクスポートし、サーバで作成されたbotインスタンスをその関数に渡す必要があります。 – Gareth

+0

私はフレームワークに少し新しくなっているので、私はそれを2回作成するのかどうか分かりません。しかし、私がボット自体をエクスポートすると、同じエラーが発生します:module.exports = {bot}; 自分のLUISエンドポイントアプリケーションを持つ複数のLUIS対応ボットを1つの場所にインポートして、独自のフレームワークを構築してコードを簡単に保守できるようにすることを目的としています。私の最大の問題は構文にありますが、NodeJSでbotframeworkがこのような考え方をサポートしているかどうかは確信しています。 –

答えて

0

ボットを分離し、それがapp.jsファイルに呼び出すことができるように、LUISを使用しますが:

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 
}); 
関連する問題