private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { if (!_luisRecognizer.IsConfigured) { // LUIS is not configured, we just run the BookingDialog path with an empty BookingDetailsInstance. await stepContext.Context.SendActivityAsync( MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the appsettings.json file.", inputHint: InputHints.IgnoringInput), cancellationToken); return(await stepContext.NextAsync(null, cancellationToken)); } // Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.) var luisResult = await _luisRecognizer.Predict(stepContext.Context.Activity.Text); switch (luisResult.Prediction.TopIntent) { case "ModifyOrder": var pizzaOrder = PizzaOrder.Convert(luisResult.Prediction); var pizzaResponseText = PizzaOrder.GetPizzaOrderString(pizzaOrder); var responseCardAttachment = new HeroCard("Your order has been placed! ", null, pizzaResponseText, new List <CardImage>() { new CardImage(PizzaOrder.GetPizzaImage()) }).ToAttachment(); var chatActivity = Activity.CreateMessageActivity(); chatActivity.Attachments.Add(responseCardAttachment); await stepContext.Context.SendActivityAsync(chatActivity); break; case "Confirmation": var confirmationMessage = MessageFactory.Text("That's great! We'll get right on it", null, InputHints.IgnoringInput); await stepContext.Context.SendActivityAsync(confirmationMessage, cancellationToken); break; case "CancelOrder": var cancelMessage = MessageFactory.Text("Your order has been cancelled!", null, InputHints.IgnoringInput); await stepContext.Context.SendActivityAsync(cancelMessage, cancellationToken); break; case "Greetings": var greetingsMessage = MessageFactory.Text("Hello!", null, InputHints.IgnoringInput); await stepContext.Context.SendActivityAsync(greetingsMessage, cancellationToken); break; default: // Catch all for unhandled intents var didntUnderstandMessageText = $"Sorry, I didn't get that. Please try asking in a different way (intent was {luisResult.Prediction.TopIntent})"; var didntUnderstandMessage = MessageFactory.Text(didntUnderstandMessageText, didntUnderstandMessageText, InputHints.IgnoringInput); await stepContext.Context.SendActivityAsync(didntUnderstandMessage, cancellationToken); break; } return(await stepContext.NextAsync(null, cancellationToken)); }
private async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { if (!_luisRecognizer.IsConfigured) { // LUIS is not configured, we just run the BookingDialog path with an empty BookingDetailsInstance. await stepContext.Context.SendActivityAsync( MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the appsettings.json file.", inputHint: InputHints.IgnoringInput), cancellationToken); return(await stepContext.NextAsync(null, cancellationToken)); } // Call LUIS and gather any potential booking details. (Note the TurnContext has the response to the prompt.) var luisResult = await _luisRecognizer.RecognizeAsync <PizzaOrder>(stepContext.Context, cancellationToken); switch (luisResult.TopIntent().intent) { case PizzaOrder.Intent.ModifyOrder: var pizzaOrder = luisResult; var pizzaResponseText = PizzaOrder.GetPizzaOrderString(pizzaOrder); /* * var responseCardAttachment = new HeroCard("Your order has been placed! ", null, pizzaResponseText, new List<CardImage>() { new CardImage(PizzaOrder.GetPizzaImage()) }).ToAttachment(); * var chatActivity = Activity.CreateMessageActivity(); * chatActivity.Attachments.Add(responseCardAttachment); * await stepContext.Context.SendActivityAsync(chatActivity); */ var responseCardAttachment = new HeroCard { Title = "Your order has been placed!", Subtitle = "", Text = pizzaResponseText, // Images = new List<CardImage> {new CardImage(PizzaOrder.GetPizzaImage() )}, Images = new List <CardImage> { new CardImage("https://images.pexels.com/photos/1049626/pexels-photo-1049626.jpeg?auto=compress&cs=tinysrgb&h=350") }, //Images = null, Buttons = null, }; var reply = MessageFactory.Attachment(responseCardAttachment.ToAttachment()); reply.Speak = SSML(PizzaOrder.GetPizzaOrderStringTextOnly(pizzaOrder)); await stepContext.Context.SendActivityAsync(reply, cancellationToken); break; case PizzaOrder.Intent.Confirmation: var confirmationMessage = MessageFactory.Text("That's great! We'll get right on it", null, InputHints.IgnoringInput); confirmationMessage.Speak = SSML(confirmationMessage.Text); await stepContext.Context.SendActivityAsync(confirmationMessage, cancellationToken); break; case PizzaOrder.Intent.CancelOrder: var cancelMessage = MessageFactory.Text("Your order has been cancelled!", null, InputHints.IgnoringInput); cancelMessage.Speak = SSML(cancelMessage.Text); await stepContext.Context.SendActivityAsync(cancelMessage, cancellationToken); break; case PizzaOrder.Intent.Greetings: var greetingsMessage = MessageFactory.Text("Hello!", null, InputHints.IgnoringInput); greetingsMessage.Speak = SSML(greetingsMessage.Text); await stepContext.Context.SendActivityAsync(greetingsMessage, cancellationToken); break; default: // Catch all for unhandled intents var didntUnderstandMessageText = $"Sorry, I didn't get that. Please try asking in a different way (intent was {luisResult.TopIntent().intent})"; var didntUnderstandMessage = MessageFactory.Text(didntUnderstandMessageText, SSML(didntUnderstandMessageText), InputHints.IgnoringInput); didntUnderstandMessage.Speak = SSML(didntUnderstandMessageText); await stepContext.Context.SendActivityAsync(didntUnderstandMessage, cancellationToken); break; } return(await stepContext.NextAsync(null, cancellationToken)); }