Example #1
0
        public static async Task NoneofTheAbove(WaterfallStepContext step)
        {
            var context        = step.Context;
            var defaultMessage = context.Activity.CreateReply(QNABotSettings.sorrynextrelease);

            defaultMessage.SuggestedActions = new SuggestedActions {
                Actions = CardActionDialog.GetContactInfoCard()
            };

            await context.SendActivityAsync(defaultMessage);
        }
Example #2
0
        public static async Task Carousel(Activity msg, RecognizerResult recognizerResult, BotAccessors accessors, WaterfallStepContext step, CancellationToken cancellationToken = default(CancellationToken))
        {
            List <HeroCard> herocardlst = new List <HeroCard>();
            var             questions   = new QnaEntity();

            questions.answers = new List <Answer>();

            TextInfo textInfo             = new CultureInfo("en-US", false).TextInfo;
            int      TotalNextBestAnswers = Convert.ToInt32(Settings.TotalBestNextAnswers);
            await accessors.UserState.SaveChangesAsync(step.Context, true, cancellationToken);

            int counter = 0;
            var intents = recognizerResult.Intents.OrderByDescending(i => i.Value.Score);

            foreach (var item in intents)
            {
                var luisscore = item.Value.Score * 100;
                step.Context.Activity.Text = item.Key;

                if (/*(luisscore <= MedConfidenceThresholdValue1 && luisscore >= MedConfidenceThresholdValue2)*/ counter <= Counter)
                {
                    var qnaResponse = await accessors.QnAServices[Settings.QnAName01].GetAnswersAsync(step.Context);
                    counter++;
                    if (qnaResponse != null && qnaResponse.Length > 0)
                    {
                        Answer answer = new Answer
                        {
                            answer    = qnaResponse[0].Answer,
                            metadata  = qnaResponse[0].Metadata.ToList(),
                            questions = qnaResponse[0].Questions.ToList() //added this so that I can map the question to the variable
                        };
                        questions.answers.Add(answer);
                    }
                }
            }

            if (questions != null && questions.answers != null && questions.answers.Any() && questions.answers[0].answer != "No good match found in KB.")
            {
                foreach (var item in questions.answers.Where(i => i.metadata != null && i.metadata.Count > 0 && i.answer != "No good match found in KB."))
                {
                    var        title    = (from b in item.metadata where b.Name == CarouselSettings.carouseltitle select b.Value).FirstOrDefault();
                    var        question = item.questions?.FirstOrDefault();
                    CardButton cButton  = new CardButton();
                    cButton.value = question;// question;
                    herocardlst.Add(new HeroCard
                    {
                        Title    = textInfo.ToTitleCase(title),
                        Subtitle = FirstCharToUpper((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: JsonConvert.SerializeObject(cButton))
                        },                                                                                                                                                 //qnaResponse.questions[0] JsonConvert.SerializeObject(cButton) changed instead of title, takes
                    });
                }

                msg.SuggestedActions = new SuggestedActions
                {
                    Actions = CardActionDialog.GetNoneoftheAbove()
                };
                msg.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                herocardlst.ForEach(i => msg.Attachments.Add(i.ToAttachment()));
                await step.Context.SendActivityAsync(msg);
            }
            else
            {
                var defaultMessage = step.Context.Activity.CreateReply(QNABotSettings.sorrynextrelease);
                defaultMessage.SuggestedActions = new SuggestedActions {
                    Actions = CardActionDialog.GetContactInfoCard()
                };
                await step.Context.SendActivityAsync(defaultMessage);
            }
        }