2017-12-28 15 views
3

채팅 봇을 초기화 할 때 메시지를 표시하고 대화 상자를 호출하고 싶습니다. 아래 코드는 메시지를 보여줍니다. 그러나 대화를 부를 수는 없습니다.Node.js의 conversationUpdate 이벤트에서 대화 상자 시작하기 BotBuilder

bot.on('conversationUpdate', function (activity) { 
// when user joins conversation, send welcome message 
if (activity.membersAdded) { 
    activity.membersAdded.forEach(function (identity) { 
     if (identity.id === activity.address.bot.id) { 
      var reply = new builder.Message() 
       .address(activity.address) 
       .text("Hi, Welcome "); 
      bot.send(reply); 
      // bot.beginDialog("initialize", '/'); 
      // session.beginDialog("initialize"); 
     } 
    }); 
}});bot.dialog('/', intents); 

다음은 대화 코드입니다. chatbot이 시작될 때 아래 대화 상자를 호출해야합니다.

bot.dialog('initialize', [ 
function (session, args, next) { 
    builder.Prompts.choice(session, "Do you have account?", "Yes|No", { listStyle: builder.ListStyle.button }); 
}, function (session, args, next) { 
    if (args.response.entity.toLowerCase() === 'yes') { 
     //session.beginDialog("lousyspeed"); 
     session.send("No pressed"); 
    } else if (args.response.entity.toLowerCase() === 'no') { 
     session.send("Yes pressed"); 
     session.endConversation(); 
    } 
}]).endConversationAction("stop", 
"", 
{ 
    matches: /^cancel$|^goodbye$|^exit|^stop|^close/i 
    // confirmPrompt: "This will cancel your order. Are you sure?" 
}); 

시도한 방법은 다음과 같습니다. 그러나 그들은 같은 방법 이름을 가지고 있지만, 메소드 서명은 session.beginDialog()<UniversalBot>bot.beginDialog() 사이에 차이가, 당신은 때문에이 오류가 타격

 1. bot.beginDialog("initialize", '/'); 
     2. session.beginDialog("initialize"); 
+0

를 사용하여 내 문제를 해결 활동 "여기? 귀하의 코드를 사용하면 활동이 정의되지 않는다고 말합니다 ... – Johan

답변

0

을 어떻게 당신이 "정의 않았 단 한 줄의 코드

bot.beginDialog(activity.address, 'initialize'); 
2

을 작동하지 않습니다. session.beginDialog() 내지 제 인수는 dialogId이지만 bot.beginDialog()을 사용할 때 먼저 인수가 address이고, 두 번째는 PARAM dialogId 때문에

이 약간 복잡 할 수있다.

이 문제를 해결하려면 SDK 참조 문서에 설명 된 올바른 입력 매개 변수 (예 : bot.beginDialog())를 호출하십시오. bot.beginDialog(activity.address, dialogId);

https://docs.botframework.com/en-us/node/builder/chat-reference/classes/_botbuilder_d_.universalbot.html#begindialog

또한 여기에 botbuilder.d TypeScript definition file의 전체 메소드 서명을 볼 수 있습니다

/** 
* Proactively starts a new dialog with the user. Any current conversation between the bot and user will be replaced with a new dialog stack. 
* @param address Address of the user to start a new conversation with. This should be saved during a previous conversation with the user. Any existing conversation or dialog will be immediately terminated. 
* @param dialogId ID of the dialog to begin. 
* @param dialogArgs (Optional) arguments to pass to dialog. 
* @param done (Optional) function to invoke once the operation is completed. 
*/ 
beginDialog(address: IAddress, dialogId: string, dialogArgs?: any, done?: (err: Error) => void): void;