public async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            var message = await argument;

            if (message != null && !string.IsNullOrEmpty(message.Text))
            {
                var tasks = this.services.Select(s => s.QueryServiceAsync(message.Text)).ToArray();
                await Task.WhenAll(tasks);

                if (tasks.Any())
                {
                    var sendDefaultMessageAndWait = true;
                    qnaMakerResults = tasks.FirstOrDefault(x => x.Result.ServiceCfg != null)?.Result;
                    if (tasks.Count(x => x.Result.Answers?.Count > 0) > 0)
                    {
                        var maxValue = tasks.Max(x => x.Result.Answers[0].Score);
                        qnaMakerResults = tasks.First(x => x.Result.Answers[0].Score == maxValue).Result;

                        if (qnaMakerResults != null && qnaMakerResults.Answers != null && qnaMakerResults.Answers.Count > 0)
                        {
                            if (this.IsConfidentAnswer(qnaMakerResults))
                            {
                                await this.RespondFromQnAMakerResultAsync(context, message, qnaMakerResults);

                                await this.DefaultWaitNextMessageAsync(context, message, qnaMakerResults);
                            }
                            else
                            {
                                feedbackRecord = new FeedbackRecord {
                                    UserId = message.From.Id, UserQuestion = message.Text
                                };
                                await this.QnAFeedbackStepAsync(context, qnaMakerResults);

                                //await context.PostAsync(FormatResponseMessage(context, qnaMakerResults.Answers));
                            }

                            sendDefaultMessageAndWait = false;
                        }
                    }

                    if (sendDefaultMessageAndWait)
                    {
                        await context.PostAsync(qnaMakerResults.ServiceCfg.DefaultMessage);

                        await this.DefaultWaitNextMessageAsync(context, message, qnaMakerResults);
                    }
                }
            }
        }
Exemple #2
0
        Uri IQnAService.BuildFeedbackRequest(string userId, string userQuery, string kbQuestion, string kbAnswer, out QnAMakerTrainingRequestBody postBody, out string authKey, out string knowledgebaseId)
        {
            knowledgebaseId = this.qnaInfo.KnowledgebaseId;
            authKey         = this.qnaInfo.AuthKey;
            var builder        = new UriBuilder($"{UriBaseV2}/{knowledgebaseId}/train");
            var feedbackRecord = new FeedbackRecord {
                UserId = userId, UserQuestion = userQuery, KbQuestion = kbQuestion, KbAnswer = kbAnswer
            };
            var feedbackRecords = new List <FeedbackRecord>();

            feedbackRecords.Add(feedbackRecord);
            postBody = new QnAMakerTrainingRequestBody {
                KnowledgeBaseId = knowledgebaseId, FeedbackRecords = feedbackRecords
            };
            return(builder.Uri);
        }