我正在创建一个简单的高低聊天机器人,使用微软的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");
}
}
])
答案 0 :(得分:1)
你可以提示用户输入并等待用户输入builder.Prompts.text(),或者你可以启动一个子对话框,它可以使用session.send(&#34;&#34;)结束自身和返回父母。