コード例 #1
0
        private async Task HandleQnaAnswer(IDialogContext context, IQnaResponse qnaAnswer)
        {
            if (Regex.IsMatch(qnaAnswer.Answer, GREETINGTAG, RegexOptions.IgnoreCase))
            {
                await SendEndUserQuestionEvent(context, qnaAnswer.Question, qnaAnswer.Answer, true);

                await context.PostAsync(Regex.Replace(qnaAnswer.Answer, GREETINGTAG, string.Empty));
            }
            else if (Regex.IsMatch(qnaAnswer.Answer, INTERNALTAG, RegexOptions.IgnoreCase))
            {
                if (configuration.GetConfiguration <List <string> >("InternalChannels").Contains(context.Activity.ChannelId))
                {
                    await GiveQnAAnswer(context, qnaAnswer);
                }
                else
                {
                    await SendEndUserQuestionEvent(context, qnaAnswer.Question, qnaAnswer.Answer, true);

                    await context.PostAsync(messageProvider.GetMessage("Confidential"));
                    await WhatMoreCanIDo(context);
                }
            }
            else
            {
                await GiveQnAAnswer(context, qnaAnswer);
            }
        }
コード例 #2
0
        public async Task <bool> ReplaceAnswer(string question, string answer, IQnaResponse qnaResponse)
        {
            var url      = $"{qnamakerManagementUriBase}/knowledgebases/{knowledgebaseId}/Prod/qna ";
            var response = await SendQnAMakerManagementRequest(HttpMethod.Get, url);

            QnaDbResponse kb = null;

            if (response.IsSuccessStatusCode)
            {
                kb = JsonConvert.DeserializeObject <QnaDbResponse>(await response.Content.ReadAsStringAsync());
            }

            if (kb != null)
            {
                var qnaPair = kb.qnaDocuments.FirstOrDefault(x => x.answer == qnaResponse.Answer && x.questions.Contains(question));

                if (qnaPair != null)
                {
                    var inputObject = new QnAMakerUpdateKBInput();
                    inputObject.Update.qnaList = new List <QnAMakerUpdateKBInput.QnaUpdateDto>()
                    {
                        new QnAMakerUpdateKBInput.QnaUpdateDto()
                        {
                            id     = qnaPair.id,
                            answer = answer,
                        }
                    };
                    return(await SendUpdateKbRequest(inputObject));
                }
            }
            return(false);
        }
コード例 #3
0
        private async Task StorePositiveFeedback(IDialogContext context, IQnaResponse qnaResponse)
        {
            var feedbackEntry = new FeedbackEntity()
            {
                Answer       = qnaResponse.Answer,
                Question     = qnaResponse.Question,
                FeedbackType = FeedbackType.POSITIVE
            };

            await SentToFeedbackTable(feedbackEntry);
        }
コード例 #4
0
        private async Task StoreWrongAnswerFeedback(IDialogContext context, IQnaResponse qnaMakerResponse)
        {
            var feedbackEntry = new FeedbackEntity()
            {
                Answer       = qnaMakerResponse.Answer,
                Question     = qnaMakerResponse.Question,
                FeedbackType = FeedbackType.NEGATIVE
            };

            await SentToFeedbackTable(feedbackEntry);
        }
コード例 #5
0
 private async Task StoreOnStillInterestedTable(IDialogContext context, IQnaResponse qnaAnswer)
 {
     var entity = new StillInterestedEntity(context.Activity.ChannelId, context.Activity.From.Id, MessageHelper.NormalizeString(qnaAnswer.Question))
     {
         ConversationId        = context.Activity.Conversation.Id,
         Timestamp             = DateTime.UtcNow,
         Answer                = qnaAnswer.Answer,
         ReceivedAnswer        = true,
         ConversationReference = JsonConvert.SerializeObject(context.Activity.AsMessageActivity().ToConversationReference())
     };
     var tableContent = await tableStorageProvider.SendToTableAsync("stillInterested", entity);
 }
コード例 #6
0
 private async Task SendToQuestionToQueue(IDialogContext context, IQnaResponse qnaAnswer, MessageType type)
 {
     var messageToSend = new MessageEntity()
     {
         Question              = qnaAnswer.Question,
         OriginalAnswer        = qnaAnswer.Answer,
         MessageType           = type,
         OriginalQuestion      = qnaAnswer.MatchingQuestion,
         QuestionCorrelationId = Guid.NewGuid()
     };
     await queueProvider.InsertInQueueAsync("usertoexpert", messageToSend);
 }
コード例 #7
0
        private async Task <bool> HasEnoughCorrectFeedback(IQnaResponse qnaAnswer)
        {
            TableQuery <FeedbackEntity> tableQuery = new TableQuery <FeedbackEntity>().Where(TableQuery.CombineFilters(
                                                                                                 TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, FeedbackType.POSITIVE.ToString()),
                                                                                                 TableOperators.And,
                                                                                                 TableQuery.CombineFilters(
                                                                                                     TableQuery.GenerateFilterCondition("Answer", QueryComparisons.Equal, qnaAnswer.Answer),
                                                                                                     TableOperators.And,
                                                                                                     TableQuery.GenerateFilterCondition("Question", QueryComparisons.Equal, qnaAnswer.Question))));

            var positiveFeedbacks = await tableStorageProvider.RetrieveFromTableAsync("feedbackTable", tableQuery);

            return(positiveFeedbacks.Count() >= configuration.GetConfiguration <int>("MinPositiveFeedback"));
        }
コード例 #8
0
        private async Task GiveQnAAnswer(IDialogContext context, IQnaResponse qnaAnswer)
        {
            await context.PostAsync(string.Format(messageProvider.GetMessage("FoundAnswer"), Regex.Replace(qnaAnswer.Answer, INTERNALTAG, "")));

            if (await HasEnoughCorrectFeedback(qnaAnswer))
            {
                await SendEndUserQuestionEvent(context, qnaAnswer.Question, qnaAnswer.Answer, true);

                await context.PostAsync(messageProvider.GetMessage("GladToHelp"));
                await WhatMoreCanIDo(context);
            }
            else
            {
                context.ConversationData.SetValue("qnaAnswer", qnaAnswer);
                PromptDialog.Confirm(context, AfterAnswerConfirmation, messageProvider.GetMessage("IsMessageCorrect"));
            }
        }
コード例 #9
0
        protected async Task KeepNewAnswer(IDialogContext context, string question, string answer, IQnaResponse qnaResponse)
        {
            await context.PostAsync(messageProvider.GetMessage("KeepingNew"));

            await qnaMakerProvider.ReplaceAnswer(question, answer, qnaResponse);

            await SendAnswerToUsers(context, question, answer);
        }