2017-02-10 11 views
1

LUISを使用してSlackボットを作成しようとしています。ボットが追加されたチャンネルの挨拶を見ると、挨拶を送信したユーザーに直接メッセージが送信されます。Node.js:MS Bot FrameworkでSlackで直接メッセージを送信するには?

私は問題#431を見て、ボットを書きました。

ERROR: ChatConnector: startConversation - address is invalid. 
Error: Invalid address. 
    at ChatConnector.startConversation (C:\..\node_modules\botbuilder\lib\bots\ChatConnector.js:173:18) 
    at C:\..\node_modules\botbuilder\lib\bots\UniversalBot.js:308:27 
    at UniversalBot.tryCatch (C:\..\node_modules\botbuilder\lib\bots\UniversalBot.js:381:13) 
    at UniversalBot.ensureConversation (C:\..\node_modules\botbuilder\lib\bots\UniversalBot.js:302:14) 
    at C:\..\node_modules\botbuilder\lib\bots\UniversalBot.js:163:19 
    at C:\..\node_modules\botbuilder\lib\bots\UniversalBot.js:337:53 
    at UniversalBot.tryCatch (C:\..\node_modules\botbuilder\lib\bots\UniversalBot.js:381:13) 
    at C:\..\node_modules\botbuilder\lib\bots\UniversalBot.js:337:23 
    at UniversalBot.tryCatch (C:\..\node_modules\botbuilder\lib\bots\UniversalBot.js:381:13) 
    at UniversalBot.lookupUser (C:\..\node_modules\botbuilder\lib\bots\UniversalBot.js:324:14) 

(私はディレクトリの一部を省略しました)

I:ボットが挨拶を受信したときに、現在、それは、次のエラーメッセージが与えられる。しかし、

var builder = require('botbuilder'); 
var restify = require('restify'); 
// 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); 
}); 
server.get(/.*/, restify.serveStatic({ 
    'directory': '.', 
    'default': 'index.html' 
})); 

// 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, { 
    persistConversationData: true // need persistent data for dictionary 
}); 
server.post('/api/messages', connector.listen()); 

// Create LUIS recognizer that points at our model and add it as the root '/' dialog 
var model = (omitted); 
var recognizer = new builder.LuisRecognizer(model); 
var dialog = new builder.IntentDialog({ recognizers: [recognizer] }); 
bot.dialog('/', dialog); 

// Add intent handlers 
dialog.matches('Greeting', [ 
    function(session, args, next) { 
     var language = builder.EntityRecognizer.findEntity(args.entities, 'Language'); 
     next({ response: language }); 
    }, 
    function(session, results) { 

     bot.beginDialog({ 
      text: 'Hello', 
      to: {channelId: "emulator", address:"User1", id:"(omitted)", isBot:false}, 
      from: { channelId:"emulator", address:"Bot1", id:"(omitted)", isBot:true} 
     }, '/'); 
    } 
]); 

:ここに私のコードです問題#687を見ましたが、それでも問題を把握できませんでした。どのようにしてボットを動作させることができますか?

私はBotbuilder v3.4.4とNode v4.6.0を使用しています。

答えて

1

私が思うここに行く方法は次のとおりです。

  1. 保存どこかにあなたがやっているbot.beginDialogで、後でそれを使用する必要がありますようsession.message.address
  2. 新しいダイアログを開始する前に、会話オブジェクトを削除して、新しい会話を作成する必要があります。
  3. アドレスを使用してダイアログを開始します。

// consider making this an array insted 
var address 

// probably in the function that matches the greeting 
address = session.message.address; 

// in the step where you want to send the direct messsage 
var newConversationAddress = Object.assign({}, address); 
delete newConversationAddress.conversation; 

// begin dialog with address without conversation 
bot.beginDialog(newConversationAddress,... 

のようなものCreateNewConversationサンプルを見てくださいだろう。かなり類似したことが行われていることがわかります。

関連する問題