/// <summary> /// This will disaplay a suggested action button menu with 2 options /// </summary> /// <param name="context"></param> /// <param name="result"></param> /// <returns></returns> private async Task Noneoftheabovedialog(IDialogContext context, IAwaitable <IMessageActivity> result) { var msg = await result; if (msg.Text.Contains(QNABotSettings.noneoftheabove) /*&& defaultmessageflag == false*/) { //defaultmessageflag = true; var defaultMessage = ((Activity)context.Activity).CreateReply(QNABotSettings.sorrynextrelease);//Created a new Activity object which will prompt the user with a question – “Did you find what you need?” when the dialog starts defaultMessage.SuggestedActions = new SuggestedActions { Actions = CardActionDialogue.GetContactInfoCard() }; await context.PostAsync(defaultMessage); context.Wait(ChoiceMenuLogic);//with the choice selected, move to ChoiceMenuLogic to determine the type of answer } else { var userFeedback = await result; var feedbacktext = userFeedback.Text; var message = context.MakeMessage(); message.Text = feedbacktext; await context.Forward(new QnADialog(f), ResumeAfterFeedback, message, CancellationToken.None); //context.Done(1);//OJO } }
protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context, IMessageActivity message, QnAMakerResults result) { var telemetry = new TelemetryClient(); try { var qnaAnswer = result?.Answers?.First()?.Answer;//store qnamaker result text and store it in qnaAnswer variable var qnaQuestions = result?.Answers?.First()?.Questions; var questions = new QnaEntity(); var userinput = new QnaHelper(); var myquestion = result; Activity reply = ((Activity)context.Activity).CreateReply(); if (qnaAnswer != null & qnaQuestions != null && qnaQuestions.Any()) { if (message.Text.ToString().ToLower().Contains("help") || message.Text.ToString().ToLower().Contains("ayuda")) { await context.PostAsync(QNABotSettings.prompt1); Task.Delay(2000); await context.PostAsync(QNABotSettings.prompt2); return; } if (qnaQuestions.Any()) { questions = QnaHelper.QNAConnection(qnaQuestions?.FirstOrDefault()); context.UserData.SetValue("questions", questions); } else { context.UserData.RemoveValue("questions"); } var score = result.Answers.OrderByDescending(i => i.Score).FirstOrDefault()?.Score; if (score != null) { score = score * 100; //Threshold 1 Path! 100% - 80% if (score <= (Convert.ToInt32(QNABotSettings.threshold1[0]) + 0.99) && score >= Convert.ToInt32(QNABotSettings.threshold1[1])) { f.Flags1++; if (qnaAnswer.Contains("||")) { var msg = context.MakeMessage(); var answers = qnaAnswer.Split("||".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList(); msg.Attachments.Add(await GetCardsAttachments(answers)); await context.PostAsync(msg); if (qnaAnswer.Contains(ConfigurationManager.AppSettings["HRHeroTitle"])) { showHRHeroCardFlag = false; } else { showHRHeroCardFlag = true; } } else { await context.PostAsync(qnaAnswer); } } //Threshold 2 Path!79 % -40 % else if (score <= (Convert.ToInt32(QNABotSettings.threshold2[0]) + 0.99) && score >= Convert.ToInt32(QNABotSettings.threshold2[1]))//79-40 { f.Flags2++; context.UserData.SetValue("firstCheck", "true"); showHRHeroCardFlag = true; var msg = ((Activity)context.Activity).CreateReply(QNABotSettings.accurateanswer); //for carousel var herocardlst = new List <HeroCard>(); if (questions != null && questions.answers != null && questions.answers.Any()) { foreach (var item in questions.answers.Where(i => i.metadata != null)) { //string TitleCase = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(); //System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase() //this is causing issues with Spanish language herocardlst.Add(new HeroCard { Title = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase((from b in item.metadata where b.name == CarouselSettings.carouseltitle select b.value).FirstOrDefault()), Subtitle = (from b in item.metadata where b.name == CarouselSettings.carouselsummary select b.value).FirstOrDefault(), Buttons = new List <CardAction>() { new CardAction(ActionTypes.PostBack, QNABotSettings.seedetails, value: item.questions?.FirstOrDefault()) }, }); } } msg.SuggestedActions = new SuggestedActions { Actions = CardActionDialogue.GetNoneoftheAbove() }; msg.AttachmentLayout = AttachmentLayoutTypes.Carousel; herocardlst.ForEach(i => msg.Attachments.Add(i.ToAttachment())); msg.AttachmentLayout = AttachmentLayoutTypes.Carousel; await context.PostAsync(msg); context.Wait(Noneoftheabovedialog); } //Threshold 3 Path!39 % -0 % else if (score < (Convert.ToInt32(QNABotSettings.threshold3[0]) + 0.99) && score >= Convert.ToInt32(QNABotSettings.threshold3[1])) //39-0 { var defaultMessage = ((Activity)context.Activity).CreateReply(QNABotSettings.sorrynextrelease); //Created a new Activity object which will prompt the user with a question – “Did you find what you need?” when the dialog starts defaultMessage.SuggestedActions = new SuggestedActions { Actions = CardActionDialogue.GetContactInfoCard() }; await context.PostAsync(defaultMessage); context.Wait(ChoiceMenuLogic); } } } else { var defaultMessage = ((Activity)context.Activity).CreateReply(QNABotSettings.sorrynextrelease);//Created a new Activity object which will prompt the user with a question – “Did you find what you need?” when the dialog starts defaultMessage.SuggestedActions = new SuggestedActions { Actions = CardActionDialogue.GetContactInfoCard() }; context.UserData.SetValue("firstCheck", "false"); await context.PostAsync(defaultMessage); context.Wait(ChoiceMenuLogic); } } catch (Exception) { throw; //telemetry.TrackEvent("QnA Dialog RespondFromQnAMakerResultAsync Exception", new Dictionary<string, string> { { "Exception", SimpleJson.SimpleJson.SerializeObject(ex) } }); } }