1

我正在使用 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");
		}
	}
])

4

1 回答 1

1

您可以提示用户输入并等待用户输入 builder.Prompts.text(),或者您可以启动子对话框,该子对话框可以使用 session.send("") 结束自身并返回父级。

于 2016-04-03T08:33:34.180 回答