public async Task BotFlow_BuildSimpleDataStructure_Verify() { var myBotFlow = BotFlow.DisplayMessage("Hello! Do you want milk?", "http://www.mysite.com/milk.png") .WithOption("Yes", BotFlow.DisplayMessage("Here's your milk.")) .WithOption("No", BotFlow.DisplayMessage("Well, then what do you want?") .WithOption("Cookies", BotFlow.DisplayMessage("Here are your cookies")) .WithOption("Waffles", BotFlow.DisplayMessage("Here are your waffles")) .WithOption("Nothing", BotFlow.DisplayMessage("Sorry, I don't have anything else for breakfast!"))) .FinishWith("You have been served breakfast!"); (await myBotFlow.GetMessage()).Should().Be("Hello! Do you want milk?"); myBotFlow.ImageUrl.Should().Be("http://www.mysite.com/milk.png"); myBotFlow.CompletionMessage.Should().Be("You have been served breakfast!"); myBotFlow.Options.Count.Should().Be(2); myBotFlow.Options[0].OptionString.Should().Be("Yes"); myBotFlow.Options[1].OptionString.Should().Be("No"); myBotFlow.Options[0].NextFlow.Options.Should().BeEmpty(); (await myBotFlow.Options[0].NextFlow.GetMessage()).Should().Be("Here's your milk."); myBotFlow.Options[1].NextFlow.Options.Should().HaveCount(3); }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <Message> Post([FromBody] Message message) { if (message.Type == "Message") { var wrongAnswerBotFlow = BotFlow.DisplayMessage("Wrong answer!") .Do(() => { /* Report score to the server */ }); var finishedBotFlow = BotFlow.DisplayMessage("Very nice! You got all questions right!") .Do(() => { /* Report score to the server */ }); var thirdQuestionBotFlow = BotFlow.DisplayMessage("Nice answer! Now a tough one: How much is 7 * 7?") .WithOption("49", finishedBotFlow) .WithOption("54", wrongAnswerBotFlow) .WithOption("11", wrongAnswerBotFlow); var secondQuestion = BotFlow.DisplayMessage("Now a tough one: How much is 10 / 5?") .WithOption("2", thirdQuestionBotFlow) .Do(() => { /* Report score to the server */ }) .WithOption("5", wrongAnswerBotFlow) .WithOption("1", wrongAnswerBotFlow); var firstQuestion = BotFlow.DisplayMessage("Let's do this! How much is 2 + 1?") .WithOption("1", wrongAnswerBotFlow) .WithOption("3", secondQuestion) .WithOption("4", wrongAnswerBotFlow); var botflow = BotFlow.DisplayMessage("This is a small math quiz - are you ready?") .WithOption("Yes", firstQuestion) .WithOption("No", BotFlow.DisplayMessage("Call me when you're ready!")) .FinishWith("Thanks for playing!"); return(await Conversation.SendAsync(message, () => botflow.BuildDialogChain())); } else { return(HandleSystemMessage(message)); } }
public async Task <Message> Post([FromBody] Message message) { if (message.Type == "Message") { BotFlow myBotFlow = BotFlow.DisplayMessage("Hello I am breakfastbot and will do my best to serve you breakfast! Do you want milk?") .WithThumbnail("http://www.mysite.com/milk.png") .WithOption("Yes", BotFlow.DisplayMessage("Here's your milk.") .Do(() => Ordering.OrderMilk())) .WithOption("No", BotFlow.DisplayMessage("Well, then what do you want? ;)") .WithOption("Cookies", BotFlow.DisplayMessage("Here are your cookies") .Do(() => Ordering.OrderCookies())) .WithOption("Waffles", BotFlow.DisplayMessage("Here are your waffles") .Do(() => Ordering.OrderWaffles())) .WithOption("Nothing", BotFlow.CalculateMessage(async() => { // Retrieve breakfast from database string top10Breakfasts = await DatabaseLookup.GetTop10Breakfasts(); return("Maybe you want some ideas - here are the top 10 breakfasts according to our database: " + top10Breakfasts + ". Do any of these sound good?"); }) .WithOption("Yes", BotFlow.DisplayMessage("Great! Click here to browse to our breakfast webpage to find them.") .WithOptionLink("Breakfast website", "http://www.microsoft.com") ) .WithOption("No", BotFlow.DisplayMessage("You must be kidding - everybody likes breakfast!") ) ) ) .FinishWith("Have a great day!"); return(await Conversation.SendAsync(message, () => myBotFlow.BuildDialogChain())); } return(HandleSystemMessage(message)); }