Beispiel #1
0
        protected override async Task RespondFromQnAMakerResultAsync(IDialogContext context,
                                                                     IMessageActivity message,
                                                                     QnAMakerResults result)
        {
            var answers = GetAnswerData(result);
            var counter = answers.Count();

            if (counter == 0)
            {
                if (isComingFromLuis)
                {
                    AppInsightsTelemetryClient.TrackEvent(message.Id);
                    AppInsightsTelemetryClient.InsertTransaction(context.Activity as IMessageActivity,
                                                                 originalQuestion, 0, 0, SharedObjects.NO_RESULT_ANSWER_IN_DB, (context.Activity as IMessageActivity).Text,
                                                                 AnswerType.noAnswer);
                    typeResultInQnA = SharedObjects.ResultFromQnA.NO_RESULT_FROM_QNA_AND_LUIS;
                }

                else
                {
                    typeResultInQnA = SharedObjects.ResultFromQnA.NO_RESULT_FROM_QNA;
                }
            }
            else
            {
                typeResultInQnA = SharedObjects.ResultFromQnA.RESULT_FROM_QNA;

                AppInsightsTelemetryClient.TrackEvent(message.Id);
                AppInsightsTelemetryClient.InsertTransaction(context.Activity as IMessageActivity,
                                                             originalQuestion, counter, answers[0].Score, answers[0].Questions[0],
                                                             (isComingFromLuis ? message.Text : "None"),
                                                             (isComingFromLuis ? AnswerType.QnALuis : AnswerType.QnA));

                var carrusel = context.MakeMessage();
                carrusel.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                var options = new List <Attachment>();

                if (counter == 1)
                {
                    await context.PostAsync($"I found 1 answer:");
                }
                else
                {
                    await context.PostAsync($"Are any of these {counter} answers helpful?");
                }

                foreach (var qnaMakerResult in answers)
                {
                    options.Add(CreateCard(qnaMakerResult));
                }

                carrusel.Attachments = options;

                await context.PostAsync(carrusel);
            }
        }
Beispiel #2
0
        private async Task AfterQnADialog(IDialogContext context, IAwaitable <object> result)
        {
            var    message         = context.Activity as IMessageActivity;
            string typeResultInQnA = (await result as Activity).Text;

            switch (typeResultInQnA)
            {
            case SharedObjects.ResultFromQnA.NO_RESULT_FROM_QNA:
                QnADialog dialog = new QnADialog();
                dialog.isComingFromLuis = true;


                string LuisAnswer = GetLuisAnswer(message.Text, out double score);

                if (LuisAnswer == "None")
                {
                    await context.PostAsync(SharedObjects.NO_RESULT_ANSWER);

                    AppInsightsTelemetryClient.TrackEvent(message.Id);
                    AppInsightsTelemetryClient.InsertTransaction(message, message.Text, 0, score, SharedObjects.NO_RESULT_ANSWER_IN_DB, LuisAnswer, AnswerType.noAnswer);
                }
                else
                {
                    dialog.originalQuestion = message.Text;
                    message.Text            = LuisAnswer;
                    await context.Forward(dialog, AfterQnADialog, message);
                }
                break;

            case SharedObjects.ResultFromQnA.NO_RESULT_FROM_QNA_AND_LUIS:
                await context.PostAsync(SharedObjects.NO_RESULT_ANSWER);

                break;

            default:
                context.Done(this);
                break;
            }
        }