我正在使用 Microsoft 的Bot Framework创建一个简单的高低聊天机器人,它可以让您猜测一个随机数。我决定使用递归对话框;但是,每当我使用session.send发送消息时,它都会结束对话。如何发送不结束对话的消息?
bot.add('/max-num', [
function (session) {
builder.Prompts.number(session, "What's the max number?")
},
function (session, results) {
var max = results.response;
session.userData.max = max;
session.userData.num = Math.ceil(Math.random() * max)
session.userData.round = 1;
session.send("I choose a number between 1 and " + max + " inclusively!");
session.replaceDialog('/round');
}
]);
bot.add('/round', [
function (session) {
builder.Prompts.number(session,"Guess a number")
},
function (session, results) {
// function vars
var round = session.userData.round;
var target = session.userData.num;
var guess = results.response;
// high/low logic
if (guess === target) { // Winning Case
session.send("Wow you got it in " + round + (round === 1 ? "round" : "rounds"));
session.endDialog();
} else { // Losing case
if (guess > target)
session.send("Your guess was too high!");
else if (guess < target)
session.send("Your guess was too low!");
session.replaceDialog("/round");
}
}
])