1
我正在使用微軟的Bot Framework創建一個簡單的高低聊天機器人,它使您猜測隨機數。我決定使用遞歸對話框;但是,無論何時我使用session.send發送消息,它都會結束對話框。我如何發送不會結束對話的消息?Microsoft Bot框架 - 在對話框中發送消息
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 }
])