private async Task <DialogTurnResult> PromptReplyToInsult(WaterfallStepContext stepContext, CancellationToken cancellationToken) { NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Options; // First time around. Ask for response bool addInsult = (bool)stepContext.Result; if (addInsult) { var reply = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_NEW_INSULT_REPLY, _brain.GetBastardDBContext()); return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions() { Prompt = MessageFactory.Text(string.Format(reply, newInsultQnA.Insults.Last())), RetryPrompt = MessageFactory.Text("Seriously, what should I say?") })); } else { // User doesn't want to add it. Abort. Next prompt will have this text var reply = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_ENDING_DISAPPOINT, _brain.GetBastardDBContext()); return(await stepContext.EndDialogAsync(reply, cancellationToken)); } }
private async Task <DialogTurnResult> ConfirmNewInsultQnA(WaterfallStepContext stepContext, CancellationToken cancellationToken) { NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Values[BotConstants.STEP_VALUES_NEW_INSULT_KEY]; // Confirm it's saved var reply = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_INSULT_ADDED, _brain.GetBastardDBContext()); await stepContext.Context.SendActivityAsync( MessageFactory.Text(string.Format(reply, newInsultQnA.InsultResponse)), cancellationToken ); // New new insult QnA to SQL await _brain.AddNewInsultQnA(newInsultQnA); // Done var text = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_ALL_DONE, _brain.GetBastardDBContext()); await stepContext.Context.SendActivityAsync( MessageFactory.Text(text), cancellationToken ); // For next main diag loop, preface with this... return(await stepContext.EndDialogAsync("Hit me again", cancellationToken)); }
public static AdaptiveCard GetNewQnACard(NewInsultQnA newInsult) { var insultFacts = new List <AdaptiveFact>(); for (int i = 0; i < newInsult.Insults.Count; i++) { var insult = newInsult.Insults[i]; bool isLastInsult = (i < newInsult.Insults.Count - 1); if (isLastInsult) { insultFacts.Add(new AdaptiveFact { Title = insult, Value = "...or..." }); } else { insultFacts.Add(new AdaptiveFact { Title = insult }); } } var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 1)) { Body = new List <AdaptiveElement>() { new AdaptiveContainer() { Style = AdaptiveContainerStyle.Emphasis, Bleed = true, Items = new List <AdaptiveElement>() { new AdaptiveTextBlock("New Insult Q&A") { Size = AdaptiveTextSize.Medium, Weight = AdaptiveTextWeight.Bolder } } }, new AdaptiveTextBlock($"So if someone says to me:") { Wrap = true }, new AdaptiveFactSet { Facts = insultFacts }, new AdaptiveTextBlock($"...I'll tell them back:") { Wrap = true }, new AdaptiveTextBlock(newInsult.InsultResponse) { Wrap = true, Weight = AdaptiveTextWeight.Bolder, Color = AdaptiveTextColor.Accent, Size = AdaptiveTextSize.Large }, } }; return(card); }
private Task <DialogTurnResult> RepeatIfNeeded(WaterfallStepContext stepContext, CancellationToken cancellationToken) { bool moar = (bool)stepContext.Result; NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Values[BotConstants.STEP_VALUES_NEW_INSULT_KEY]; if (moar) { return(stepContext.ReplaceDialogAsync(nameof(AddMoreInsultsForResponseDialog), newInsultQnA, cancellationToken)); } else { return(stepContext.EndDialogAsync(newInsultQnA, cancellationToken)); } }
private async Task <DialogTurnResult> NewInsult(WaterfallStepContext stepContext, CancellationToken cancellationToken) { NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Options; // Save new QnA to session stepContext.Values.Add(BotConstants.STEP_VALUES_NEW_INSULT_KEY, newInsultQnA); var askToHelp = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_NEW_INSULT_START, _brain.GetBastardDBContext()); return(await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = MessageFactory.Text(string.Format(askToHelp, newInsultQnA.Insults.First())), RetryPrompt = MessageFactory.Text("Need some actual text here") }, cancellationToken)); }
private async Task <DialogTurnResult> MoreResponses(WaterfallStepContext stepContext, CancellationToken cancellationToken) { NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Values[BotConstants.STEP_VALUES_NEW_INSULT_KEY]; bool moreInsults = (bool)stepContext.Result; if (moreInsults) { // User wants to add more insults for response. Go around again, but pass the current insult state return(await stepContext.BeginDialogAsync(nameof(AddMoreInsultsForResponseDialog), newInsultQnA, cancellationToken)); } else { return(await stepContext.NextAsync(null, cancellationToken)); } }
private async Task <DialogTurnResult> AskForNextInsult(WaterfallStepContext stepContext, CancellationToken cancellationToken) { NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Options; // Save new QnA to session stepContext.Values.Add(BotConstants.STEP_VALUES_NEW_INSULT_KEY, newInsultQnA); var reply = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_NEXT_INSULT_PROMPT, _context); return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions() { Prompt = MessageFactory.Text(string.Format(reply, newInsultQnA.InsultResponse)), RetryPrompt = MessageFactory.Text("Seriously, what should I say?") })); }
public async Task AddNewInsultQnA(NewInsultQnA newInsultQnA) { var dbContext = GetBastardDBContext(); InsultResponse insultResponse = new InsultResponse() { Text = newInsultQnA.InsultResponse }; foreach (var newInsult in newInsultQnA.Insults) { dbContext.NewInsults.Add(new Insult() { Text = newInsult, ParentResponse = insultResponse }); } await dbContext.SaveChangesAsync(); }
private async Task <DialogTurnResult> AddInsultResponse(WaterfallStepContext stepContext, CancellationToken cancellationToken) { NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Values[BotConstants.STEP_VALUES_NEW_INSULT_KEY]; string insultReply = (string)stepContext.Result; newInsultQnA.InsultResponse = insultReply; // Send adaptive card with new QnA await CommonDialogMessages.SendConfirmQnACard(stepContext, cancellationToken, newInsultQnA); var text = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_MORE_INSULTS_QUESTION, _brain.GetBastardDBContext()); return(await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions() { Prompt = MessageFactory.Text(text), RetryPrompt = MessageFactory.Text($"Seriously, what other insults should I reply '{newInsultQnA.InsultResponse}' to?") })); }
private async Task <DialogTurnResult> AskIfMore(WaterfallStepContext stepContext, CancellationToken cancellationToken) { string newInsult = (string)stepContext.Result; NewInsultQnA newInsultQnA = (NewInsultQnA)stepContext.Values[BotConstants.STEP_VALUES_NEW_INSULT_KEY]; newInsultQnA.Insults.Add(newInsult); // Send adaptive card with new QnA await CommonDialogMessages.SendConfirmQnACard(stepContext, cancellationToken, newInsultQnA); var reply = await PhraseGenerator.GetPhrase(BotConstants.CHAT_CATEGORY_MORE_INSULTS_QUESTION, _context); return(await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = MessageFactory.Text(reply), RetryPrompt = MessageFactory.Text("Soooo...more?") }, cancellationToken)); }
private async Task <DialogTurnResult> GetQnAResponseFromInput(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var options = new QnAMakerOptions { Top = 1 }; // The actual call to the QnA Maker service. var response = await _botServices.QnAMakerService.GetAnswersAsync(stepContext.Context, options); if (response != null && response.Length > 0) { return(await stepContext.NextAsync(response[0].Answer, cancellationToken)); } else { // New insult? string insult = stepContext.Context.Activity.Text; return(await stepContext.BeginDialogAsync(nameof(NewInsultQnADialog), NewInsultQnA.FromNewInsult(insult), cancellationToken)); } }
public static async Task SendConfirmQnACard(WaterfallStepContext stepContext, CancellationToken cancellationToken, NewInsultQnA newInsultQnA) { // Send adaptive card with new QnA var adaptiveCard = CardGenerator.GetNewQnACard(newInsultQnA); var adaptiveCardAttachment = new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = adaptiveCard, }; var promptMessageSummary = MessageFactory.Attachment(adaptiveCardAttachment, $"Want to add any other insults I should reply '{newInsultQnA.InsultResponse}' to?"); await stepContext.Context.SendActivityAsync(promptMessageSummary, cancellationToken); }