2017-12-28 16 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); 

ダイアログためのコードです。チャットボットが始まると以下のダイアログを呼び出す必要があります

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