2017-02-10 1 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 디렉토리의 일부를 생략 한)

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. 저장 session.message.address 어딘가에 당신이 bot.beginDialog 당신이 일을 나중에 그것을 사용해야 할 것 같은.
  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 샘플을 살펴보십시오. 꽤 비슷한 것이 이루어지고 있음을 알 수 있습니다.