2016-04-02 9 views
1

MicrosoftのBot Frameworkを使用して、単純な高低チャットボットを作成しています。これにより、乱数を推測できます。私は再帰的なダイアログを使うことに決めました。しかし、私がsession.sendを使用してメッセージを送信すると、ダイアログが終了します。ダイアログを終了しないメッセージを送信するにはどうすればよいですか?Microsoft Bot Framework - ダイアログ中にメッセージを送信する

bot.add('/max-num', [ 
 
\t function (session) { 
 
\t \t builder.Prompts.number(session, "What's the max number?") 
 
\t }, 
 
\t function (session, results) { 
 
\t \t var max = results.response; 
 
\t \t session.userData.max = max; 
 
\t \t session.userData.num = Math.ceil(Math.random() * max) 
 
\t \t session.userData.round = 1; 
 
\t \t session.send("I choose a number between 1 and " + max + " inclusively!"); 
 
\t \t session.replaceDialog('/round'); 
 
\t } 
 
]); 
 
bot.add('/round', [ 
 
\t function (session) { 
 
\t \t builder.Prompts.number(session,"Guess a number") 
 
\t }, 
 
\t function (session, results) { 
 
\t \t // function vars 
 
\t \t var round = session.userData.round; 
 
\t \t var target = session.userData.num; 
 
\t \t var guess = results.response; 
 
\t \t 
 
\t \t // high/low logic 
 
\t \t if (guess === target) { // Winning Case 
 
\t \t \t session.send("Wow you got it in " + round + (round === 1 ? "round" : "rounds")); 
 
\t \t \t session.endDialog(); 
 
\t \t } else { // Losing case 
 
\t \t \t if (guess > target) 
 
\t \t \t \t session.send("Your guess was too high!"); 
 
\t \t \t else if (guess < target) 
 
\t \t \t \t session.send("Your guess was too low!"); 
 

 
\t \t \t session.replaceDialog("/round"); 
 
\t \t } 
 
\t } 
 
])

答えて

1

あなたは、ユーザに入力を促し、ユーザー入力builder.Prompts.text(待つ)、またはあなたがsession.sendを使用することができ、子ダイアログを起動することができ(「」 )自身を終了し、親に戻ります。

関連する問題