public ChatResponse GetResponse(ResponseRequest responseRequest) { if (responseRequest.requestTime == null) { responseRequest.requestTime = DateTime.Now; } var queueItem = new ConversationQueueItem { ConversationName = responseRequest.conversationName, RequestTime = responseRequest.requestTime }; if (!ConversationTracker.requestQueue.Any(i => i.ConversationName == queueItem.ConversationName && i.RequestTime == queueItem.RequestTime)) { ConversationTracker.requestQueue.Enqueue(queueItem); } ConversationQueueItem peekedQueueItem; if (ConversationTracker.requestQueue.TryPeek(out peekedQueueItem)) { if (peekedQueueItem.ConversationName == queueItem.ConversationName && peekedQueueItem.RequestTime == queueItem.RequestTime) { var conversation = _conversationService.GetConversation(responseRequest.conversationName, responseRequest.type); var response = _botService.GetChatResponse(conversation, responseRequest.exclusiveTypes, responseRequest.requiredProperyMatches, responseRequest.excludedTypes, responseRequest.subjectGoals); ConversationTracker.requestQueue.TryDequeue(out peekedQueueItem); return(response); } CleanQueue(); } return(Task.Delay(queueDelay).ContinueWith((task) => { return GetResponse(responseRequest); }).Result); }
public bool UpdateDatabases(ChatRequest chat) { var conversation = _conversationService.GetConversation(chat); AnalyzedChat inResponseTo = null; if (conversation.responses.Count() > 1) { inResponseTo = conversation.responses[conversation.responses.Count() - 2]; } var analyzedConversation = _analyzationService.AnalyzeConversationAsync(conversation); var conversationUdpdated = _covnersationUpdateService.UpdateConversation(analyzedConversation, chat.type); _userService.UpdateUsers(analyzedConversation.responses.Last(), inResponseTo); return(conversationUdpdated); }
public ChatResponse ProcessChat(ChatRequest chat) { var conversation = conversationService.GetConversation(chat); var analyzedConversation = analyzationService.AnalyzeConversation(conversation); var conversationUdpdated = covnersationUpdateService.UpdateConversation(analyzedConversation, chat.type); AnalyzedChat inResponseTo = null; if (analyzedConversation.responses.Count() > 1) { inResponseTo = analyzedConversation.responses[analyzedConversation.responses.Count() - 2]; } userService.UpdateUsers(analyzedConversation.responses.Last(), inResponseTo); return(GetChatResponse(conversation, chat.exclusiveTypes, chat.requiredProperyMatches, chat.excludedTypes, chat.subjectGoals)); }