public async Task <IActionResult> Post(string question, [FromHeader(Name = "x-dd-userid")] string userId, [FromHeader(Name = "x-yc-conversationid")] string conversationId) { // continue if (string.IsNullOrEmpty(conversationId) == false) { return(await ContinueConversation(question, conversationId, userId)); } var minimumMatchingDegree = await _settings.GetIntentMinimumMatchingDegreeAsync(0.7d); _logger.LogInformation($"最小匹配度为:【{minimumMatchingDegree}】"); if (string.IsNullOrWhiteSpace(question)) { return(Ok(new MessageResponse(true, "不好意思,没有听明白你的意思。"))); //return Ok(new { success = true, message = $"不好意思,没有听明白你的意思。" }); } var intent = await _luis.GetIntentAsync(question, minimumMatchingDegree); if (intent != null) { var matchIntent = intent.TopScoringIntent; if (matchIntent != null) { // 当前钉钉用户 var ddUser = await GetCurrentDDUserInfoAsync(userId); _answerService.SetCurrentDingDingUser(ddUser); // 获取当前钉钉用户所在部门及父级部门 var departIds = GetCurrentDDUserDepartIds(ddUser); await RecordMatchIntentCountAsync(matchIntent.Intent); // 获取答案(权限过滤) var answer = await _answerService.GetAnswerByIntent(intent.TopScoringIntent.Intent, departIds); return(Ok(new MessageResponse(true, answer.Answer, answer.AnswerType == Infrastructure.Enums.AnswerTypes.ProcessFlow, new { answer.ConversationId, intent.TopScoringIntent.Score, intent.TopScoringIntent.Intent, question, userId }))); //return Ok(new { success = true, message = answer.Answer, data = new { answer.ConversationId, intent.TopScoringIntent.Score, intent.TopScoringIntent.Intent, question, userId } }); } } // 未找到意图,记录问题 await _issueService.Record(new Unknown { Id = Guid.NewGuid(), Content = question, TimeOfOccurrence = DateTime.Now, Remarks = "此问题未匹配到意图", Type = 1 }); return(Ok(new MessageResponse(true, "不好意思,没有听明白你的意思。"))); //return Ok(new { success = true, message = $"不好意思,没有听明白你的意思。" }); }
public async Task <DialogDto> GetAnswerByIntent(string intent, List <long> departIds, string conversationId = null) { if (string.IsNullOrEmpty(conversationId)) { conversationId = Guid.NewGuid().ToString(); } if (!string.IsNullOrEmpty(intent)) { // 获取回答列表 var answers = await GetAnswers(intent, departIds); QandA answer = null; if (answers?.Count > 0) { // 随机一个回复 if (answers.Count > 1) { var r = new Random(); var index = r.Next(0, answers.Count); answer = answers[index]; } else { answer = answers.First(); } } if (answer != null) { switch (answer.AnswerType) { case AnswerTypes.ProcessFlow: return(await StartFlowAnswer(answer, conversationId)); default: return(await ReplaceAnswer(answer, string.Empty)); } } // 未找到答案,记录此意图 await _issueService.Record(new Unknown { Id = Guid.NewGuid(), Content = intent, TimeOfOccurrence = DateTime.Now, Remarks = "此意图未设置回复内容", Type = 2 }); } return(new DialogDto(string.Empty, "不好意思,我不明白你的意思!")); }