public static async Task <ChatbotMessage> ProcessIntent() { var answer = "Sorry, I couldn't get you."; var intentName = ResolvedIntent.IntentName; var responseObj = new ChatbotMessage() { Text = answer, IsBotResponse = true }; if (intentName.Equals("HELLO")) { responseObj = ChatbotResponseHelper.HelloIntentResponse(); } else if (intentName.Equals("NONE")) { responseObj = ChatbotResponseHelper.NoneIntentResponse(); } else if (intentName.Equals("BYE")) { responseObj = ChatbotResponseHelper.ByeIntentResponse(); } else if (intentName.StartsWith("HELP_")) { responseObj = ChatbotResponseHelper.HelpIntentResponse(intentName); } else if (intentName.StartsWith("SEARCH_")) { if (!string.IsNullOrEmpty(ResolvedIntent.InputParameter.MetroRefNumber)) { var metroRefNum = ResolvedIntent.InputParameter.MetroRefNumber; Debug.WriteLine("----------------Metro ref number: " + metroRefNum); responseObj = await ChatbotResponseHelper.SearchIntentResponse(intentName, metroRefNum); } else if (!string.IsNullOrEmpty(ResolvedIntent.InputParameter.ContainerNumber)) { var containerNum = ResolvedIntent.InputParameter.ContainerNumber; Debug.WriteLine("----------------Container number: " + containerNum); responseObj = await ChatbotResponseHelper.SearchIntentResponse(intentName, containerNum); } else if (!string.IsNullOrEmpty(ResolvedIntent.InputParameter.CustomerRefNumber)) { var customerRefNum = ResolvedIntent.InputParameter.CustomerRefNumber; Debug.WriteLine("----------------Customer ref number: " + customerRefNum); responseObj = await ChatbotResponseHelper.SearchIntentResponse(intentName, customerRefNum); } } return(responseObj); }
void OnMessageDisappearing(ChatbotMessage message) { var idx = Messages.IndexOf(message); if (idx >= 6) { Device.BeginInvokeOnMainThread(() => { ShowScrollTap = true; LastMessageVisible = false; }); } }
void OnMessageAppearing(ChatbotMessage message) { var idx = Messages.IndexOf(message); if (idx <= 6) { Device.BeginInvokeOnMainThread(() => { while (DelayedMessages.Count > 0) { Messages.Insert(0, DelayedMessages.Dequeue()); } ShowScrollTap = false; LastMessageVisible = true; PendingMessageCount = 0; }); } }
private static ChatbotMessage PopulateResponseObj(IList <Shipment> searchedItemList, string searchType, string searchTerm, ChatbotMessage responseObj) { var response = "Sorry you don't have any shipments for the given metro rerefence number."; var text = "Below are the details of the shipment with {0} {1}.\n\n" + "Final Destination: {2}\n" + "Estimated Time of Arrival: {3}"; if (searchedItemList != null) { if (searchedItemList.Count == 1) { var shipment = searchedItemList[0]; response = String.Format(text, searchType.ToLower(), shipment.JobReferenceNumber, shipment.FinalDestination, shipment.ETA); responseObj.IsSingleSearch = true; responseObj.ShipmentObj = shipment; } else if (searchedItemList.Count > 1) { response = (searchedItemList.Count < AppSettings.ListItemCount) ? String.Format("I have found {0} matches for {1} {2}.", searchedItemList.Count, searchType.ToLower(), searchTerm.ToUpper()) : String.Format("Here are the first {0} matches for {1} {2}.", AppSettings.ListItemCount, searchType.ToLower(), searchTerm.ToUpper()); responseObj.IsMultiSearch = true; List <ChatbotMessage> searchedItems = new List <ChatbotMessage>(); foreach (var shipment in searchedItemList) { var searchedItem = new ChatbotMessage() { Text = String.Format(text, searchType.ToLower(), shipment.JobReferenceNumber, shipment.FinalDestination, shipment.ETA), ShipmentObj = shipment }; searchedItems.Add(searchedItem); } responseObj.SearchedItems = searchedItems; } } responseObj.Text = response; return(responseObj); }
public static async Task <ChatbotMessage> SearchIntentResponse(string intentName, string entity) { string response = ""; bool isValidEntity = true; var responseObj = new ChatbotMessage() { IsBotResponse = true }; if (entity.Length < 4) { response = "Please enter at least 4 characters for {0} of the shipment."; isValidEntity = false; } switch (intentName) { case ChatbotConstants.SearchIntents.MetroRefNumberIntent: if (isValidEntity) { var SearchedItemListResponse = await shipmentTrackingService.GetShipments(Constants.SEARCH_TYPE_METRO_REF_NUM, entity, AppSettings.ListItemCount, 0); var SearchedItemList = SearchedItemListResponse != null ? SearchedItemListResponse.Shipments : null; //Delete Later if (SearchedItemList != null && entity.Equals("j0001")) { SearchedItemList = ((List <Shipment>) SearchedItemList).FindAll( delegate(Shipment sm) { return(sm.JobReferenceNumber.ToLowerInvariant().Contains(entity)); }); } responseObj = PopulateResponseObj(SearchedItemList, Constants.SEARCH_TYPE_METRO_REF_NUM, entity, responseObj); } else { response = String.Format(response, Constants.SEARCH_TYPE_METRO_REF_NUM.ToLower()); responseObj.Text = response; } break; case ChatbotConstants.SearchIntents.ContainerIntent: if (isValidEntity) { var SearchedItemListResponse = await shipmentTrackingService.GetShipments(Constants.SEARCH_TYPE_CONTAINER_NUM, entity, AppSettings.ListItemCount, 0); var SearchedItemList = SearchedItemListResponse != null ? SearchedItemListResponse.Shipments : null; responseObj = PopulateResponseObj(SearchedItemList, Constants.SEARCH_TYPE_CONTAINER_NUM, entity, responseObj); } else { response = String.Format(response, Constants.SEARCH_TYPE_CONTAINER_NUM.ToLower()); responseObj.Text = response; } break; case ChatbotConstants.SearchIntents.CustomerRefNumberIntent: if (isValidEntity) { var SearchedItemListResponse = await shipmentTrackingService.GetShipments(Constants.SEARCH_TYPE_CUSTOMER_REF_NUM, entity, AppSettings.ListItemCount, 0); var SearchedItemList = SearchedItemListResponse != null ? SearchedItemListResponse.Shipments : null; responseObj = PopulateResponseObj(SearchedItemList, Constants.SEARCH_TYPE_CUSTOMER_REF_NUM, entity, responseObj); } else { response = String.Format(response, Constants.SEARCH_TYPE_CUSTOMER_REF_NUM.ToLower()); responseObj.Text = response; } break; default: response = String.Format("Please rephrase your question."); responseObj.Text = response; break; } return(responseObj); }