private JsonResult BuildEndOfChatJsonFromItem(Item item) { var model = new EndChat() { EndOfChat = GetBoolvalue(item, "End of Chat"), EndMessage = FieldValue(item, "End Message") }; return(BuildResponseJson(model)); }
private JsonResult BuildNextQuestionResponse(Item item) { var nextQuestion = GetNextItem(item); //Chat has Next Question to Process & also not end of chat if (nextQuestion != null) { return(BuildChartModel(nextQuestion)); } Sitecore.Diagnostics.Log.Error("ChatBot: Item {0} has no Next Question Setup", this); var chatItem = getItem(ChatItemId); var model = new EndChat() { ChatId = ChatItemId, EndOfChat = true, EndMessage = FieldValue(chatItem, "Incorrect Flow") }; return(BuildResponseJson(model)); }
public JsonResult GetData(string chatId = null, string questionId = null, string answerId = null, string value = null, string goBack = null) { Guid answerItemId = Guid.Empty; ChatItemId = GetChat(chatId); Guid questionItemId = Guid.Empty; if (ChatItemId == Guid.Empty) { var chatItemData = getItem(ChatItemId); return(BuildResponseJson(new EndChat() { EndOfChat = true, EndMessage = FieldValue(chatItemData, "Injection Error") })); } //To Go to Previous Question if (!string.IsNullOrEmpty(goBack) && goBack == "1") { //From Analytics get the last stored records and get the Question Id and then do get item and return here var id = GetPreviousQuestionFromAnalytics(ChatItemId); //If the Analytics returns proper Id we Return previous Question if (id.Guid != Guid.Empty) { return(BuildChartModel(getItem(ChatItemId))); } } //1st Time chat - Answer not provided if ((!IsValidGuid(questionId, ref questionItemId) && string.IsNullOrEmpty(value)) && !IsValidGuid(answerId, ref answerItemId)) { XDbProcessing ob = new XDbProcessing(); var identifier = Tracker.Current?.Contact.ContactId.ToString("N"); var chatList = ob.GetLastStoredChat(ChatItemId.ToString(), identifier); List <ChatRequest> chatRequestList = new List <ChatRequest>(); if (chatList != null && chatList.Any()) { foreach (var list in chatList) { var itemCB = getItem(new Guid(list.QuestionId)); var modelCB = BuildBaseRequest(itemCB); BuildRequestOptions(itemCB, modelCB); Guid _AnswerItemId = Guid.Empty; if (!IsValidGuid(list.AnswerId.ToString(), ref _AnswerItemId)) { modelCB.AnswerChoosed = list.AnswerId.ToString(); } else { var answer = getItem(_AnswerItemId); modelCB.AnswerChoosed = answer.Fields["Option Display Text"].Value; } chatRequestList.Add(modelCB); } } return(BuildChartModel(getItem(ChatItemId), chatRequestList)); } if (IsValidGuid(questionId, ref questionItemId)) { IsValidGuid(answerId, ref answerItemId); //If User Submited manual Answer, then question id and value will have content if (!string.IsNullOrEmpty(value)) { InsertAnalyticsData(chatId, questionItemId, value); var questionItem = getItem(questionItemId); return(ReturnNextQuestionOrEndChat(questionItem)); } else if (answerItemId != Guid.Empty) { //2nd Time Onwards var item = getItem(answerItemId); //to Make Sure the Answer is of Sent Question Id if (item != null && item.ParentID.Guid == questionItemId) { InsertAnalyticsData(chatId, questionItemId, answerItemId); return(ReturnNextQuestionOrEndChat(item)); } else //Fake Request { return(BuildEndOfChatJsonFromItem(item)); } } //If the request Doesnt have proper Answer, we then return same question to UI return(BuildChartModel(getItem(questionItemId))); } var chatItem = getItem(ChatItemId); var model = new EndChat() { EndOfChat = true, EndMessage = FieldValue(chatItem, "Injection Error") }; return(BuildResponseJson(model)); }