rkhadder
rkhadder

Reputation: 13

Microsoft Bot Framework - Sending a message during a dialog

I am creating a simple high low chat bot, using Microsoft's Bot Framework, that makes you guess a random number. I've decided to use recursive dialogs; however, whenever I send a message using session.send it ends the dialog. How can I send a message that doesn't end the dialog?

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");
		}
	}
])

Upvotes: 1

Views: 1042

Answers (1)

konquestor
konquestor

Reputation: 1308

you can prompt user for an input and wait for users input builder.Prompts.text(), or you can start a child dialog, which can use session.send("") end itself and return back to the parent.

Upvotes: 1

Related Questions