private void Client_OnMessageReceived(object sender, TwitchLib.Client.Events.OnMessageReceivedArgs e) { string botCommandResponse = _chatMessageService.HandleBotCommands(e.ChatMessage.Message.Trim()); if (string.IsNullOrEmpty(botCommandResponse)) // do something with luis { // Run async method in this sync method (read https://cpratt.co/async-tips-tricks/) IntentResponse intentResponse = AsyncHelper.RunSync(() => _luisService.GetIntentAsync(e.ChatMessage.Message.Trim())); decimal certaintyThreshold; if (!decimal.TryParse(_luisConfiguration.LuisChatCertaintyThreshold, out certaintyThreshold)) { throw new ArgumentException(nameof(_luisConfiguration.LuisChatCertaintyThreshold)); } if (intentResponse.Certainty > certaintyThreshold) { string luisMappedResponse = _chatMessageService.MapLuisIntentToResponse(intentResponse); _twitchClient.SendMessage(_twitchConfiguration.ChannelName, luisMappedResponse); } AddTwitchUserChatRecordToDb(e, intentResponse); } else // do something with explicit bot commands { _twitchClient.SendMessage(_twitchConfiguration.ChannelName, botCommandResponse); } }
private void Client_OnMessageReceived(object sender, TwitchLib.Client.Events.OnMessageReceivedArgs e) { string botMessageResponse = _chatMessageService.HandleBotCommands(e); IntentResponse intentResponse = new IntentResponse { Certainty = null, EmbeddedUrl = null, Intent = null }; // create with an empty default, for bot-command messages (those that are not fed through LUIS) if (string.IsNullOrEmpty(botMessageResponse)) // nothing from bot-commands, so try doing something with LUIS { // Run async method in this sync method (read https://cpratt.co/async-tips-tricks/) intentResponse = AsyncHelper.RunSync(() => _luisService.GetIntentAsync(e.ChatMessage.Message.Trim())); decimal certaintyThreshold; if (!decimal.TryParse(_luisConfiguration.LuisChatCertaintyThreshold, out certaintyThreshold)) { throw new ArgumentException(nameof(_luisConfiguration.LuisChatCertaintyThreshold)); } if (intentResponse.Certainty > certaintyThreshold) { botMessageResponse = _chatMessageService.MapLuisIntentToResponse(intentResponse); } } AddTwitchUserChatRecordToDb(e, intentResponse); _twitchClient.SendMessage(_twitchConfiguration.ChannelName, botMessageResponse); }
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 = $"不好意思,没有听明白你的意思。" }); }