【发布时间】:2016-04-02 23:33:22
【问题描述】:
我正在创建一个简单的高低聊天机器人,使用微软的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");
}
}
])
【问题讨论】:
标签: node.js botframework