public async Task <int> AnalyseBadRequest(BotUser botUser, SocialNetworkType type, object bot, List <BotText> botTexts, List <VKApiRequestModel> Requests = null) { var texter = new BotTextHelper(botUser.Locale, type, botTexts); var sender = new ApiRouter(type, bot, botUser, Requests); switch (botUser.NowIs) { case MallBotWhatIsHappeningNow.SettingCustomer: return(await sender.SendText(texter.GetMessage("%badrequest1%"))); case MallBotWhatIsHappeningNow.SearchingOrganization: return(await sender.SendText(texter.GetMessage("%badrequest2%"))); case MallBotWhatIsHappeningNow.SearchingWay: return(await sender.SendText(texter.GetMessage("%badrequest3%"))); case MallBotWhatIsHappeningNow.GettingAllOrganizations: return(await sender.SendText(texter.GetMessage("%badrequest4%"))); default: return(0); } }
public async Task <FindedInformation> Main(object usefulData) { string query = ""; if (botUser.InputDataType == InputDataType.Text) { query = usefulData.ToString(); if (await AnaliseCommands(query) == 1) { return(null); } } FindedInformation answer; var searcher = new Search.Mall.SearchHelper(); List <FuzzySearchResult> res; object alreadyFinded; AnswerWithPhotoHelper answererWithPhoto; switch (botUser.NowIs) { case MallBotWhatIsHappeningNow.SettingCustomer: switch (botUser.InputDataType) { case InputDataType.GeoLocation: res = searcher.SearchCustomerByGeocode((DbGeography)usefulData, dataGetter.GetStructuredCustomers(Convert.ToBoolean(botUser.IsTestMode))); break; case InputDataType.Text: alreadyFinded = cacher.Get($"SETCUSTOMER{botUser.BotUserID}"); if (alreadyFinded == null) { res = searcher.SearchCustomerByName(query, dataGetter.GetStructuredCustomers(Convert.ToBoolean(botUser.IsTestMode))); } else { res = searcher.SearchCustomerByName(query, dataGetter.GetStructuredCustomers(Convert.ToBoolean(botUser.IsTestMode)), (string)alreadyFinded); } break; default: res = new List <FuzzySearchResult>(); break; } answer = new FindedInformation { Result = new SearchResult(query, res) }; await AnaliseSearchCustomerResult(res); break; case MallBotWhatIsHappeningNow.SearchingOrganization: cacher.Clear(botUser.BotUserID); var dataOfbot = dataGetter.GetDataForOneCustomer(currentCustomer.CustomerID, botUser.CustomerCompositeID); res = searcher.SearchOrganization(query, dataOfbot.Organizations.OfType <IOrganization>(), dataOfbot.Categories.OfType <ICategory>(), dataOfbot.Synonyms.OfType <IOrganizationSynonym>()); answer = new FindedInformation { Result = new SearchResult(query, res), GroopedResult = BotMapHelper.GroupFuzzySearchResult(res, dataOfbot) }; DrawHelper drawer; if (botUser.Locale == "ru_RU") { drawer = new DrawHelper(dataOfbot, answer, $"Этаж %floornumber% {currentCustomer.Name} {currentCustomer.LocaleCity[0]}"); } else { if (currentCustomer.LocaleCity.Length == 1) { drawer = new DrawHelper(dataOfbot, answer, $"Floor %floornumber% {currentCustomer.Name} {currentCustomer.LocaleCity[0]}"); } else { drawer = new DrawHelper(dataOfbot, answer, $"Floor %floornumber% {currentCustomer.Name} {currentCustomer.LocaleCity[1]}"); } } answer = drawer.DrawFindedShops(); answererWithPhoto = new AnswerWithPhotoHelper(type, answer, sender, botUser, texter, dataOfbot); await answererWithPhoto.AnalyseSearchOrganizationResult(); break; case MallBotWhatIsHappeningNow.SearchingWay: if (cacher.Get($"FINDEDFIRSTORG{botUser.BotUserID}") == null || query == "нет" || query == "no" || query == "не хочу" || query == "неа" || query == "не надо" || query == "но") { cacher.Clear(botUser.BotUserID); botUser.NowIs = MallBotWhatIsHappeningNow.SearchingOrganization; await sender.SendText(texter.GetMessage("%ready%", "%mall%", currentCustomer.Name, currentCustomer.LocaleCity) + "\\r\\n\\r\\n" + texter.GetMessage("%orgsrchstartback%")); return(null); } dataOfbot = dataGetter.GetDataForOneCustomer(currentCustomer.CustomerID, botUser.CustomerCompositeID); alreadyFinded = cacher.Get($"SEARCHWAY{botUser.BotUserID}"); if (alreadyFinded == null) { res = searcher.SearchOrganization(query, dataOfbot.Organizations.OfType <IOrganization>(), dataOfbot.Categories.OfType <ICategory>(), dataOfbot.Synonyms.OfType <IOrganizationSynonym>()); } else { res = searcher.SearchOrganization(query, dataOfbot.Organizations.OfType <IOrganization>().ToList(), dataOfbot.Categories.OfType <ICategory>().ToList(), dataOfbot.Synonyms.OfType <IOrganizationSynonym>().ToList(), (string)alreadyFinded); } answer = new FindedInformation { Result = new SearchResult(query, res) }; answererWithPhoto = new AnswerWithPhotoHelper(type, answer, sender, botUser, texter, dataOfbot); await answererWithPhoto.AnalyseSearchOrganizationForWayResult(); break; case MallBotWhatIsHappeningNow.GettingAllOrganizations: alreadyFinded = cacher.Get($"VIEWALLORG{botUser.BotUserID}"); dataOfbot = dataGetter.GetDataForOneCustomer(currentCustomer.CustomerID, botUser.CustomerCompositeID); botUser.NowIs = MallBotWhatIsHappeningNow.SearchingOrganization; if (alreadyFinded != null && (query == "да" || query == "хочу" || query == "конечно" || query == "yes" || query == "of corse" || query == "ага")) { answererWithPhoto = new AnswerWithPhotoHelper(type, (FindedInformation)alreadyFinded, sender, botUser, texter, dataOfbot); await answererWithPhoto.AnalyseSearchOrganizationResult(true); return((FindedInformation)alreadyFinded); } await sender.SendText(texter.GetMessage("%ready%", "%mall%", currentCustomer.Name, currentCustomer.LocaleCity) + "\\r\\n\\r\\n" + texter.GetMessage("%orgsrchstartback%")); if (alreadyFinded != null) { answer = (FindedInformation)alreadyFinded; } else { answer = null; } cacher.Remove($"VIEWALLORG{botUser.BotUserID}"); break; default: answer = null; break; } return(answer); }
public async Task <BotUserRequest> Main(object usefulData) { string query = ""; if (botUser.InputDataType == InputDataType.Text) { //добавлена возможность задать вопрос пользователю. isQuestion - кэшированный флаг. Говорит о том, что текущее сообщение это вопрос от пользователя #region Question query = usefulData.ToString(); var isQuestion = cacheHelper.Get($"QUESTION{botUser.BotUserVKID}"); //isQuestion - кэшированный флаг. Говорит о том, что текущее сообщение это вопрос от пользователя if (isQuestion != null && query != "назад" && query != "вопрос") { cacheHelper.Remove($"QUESTION{botUser.BotUserVKID}"); // пересылаем оператору, ID которого указано в конфиг файле thisRequest.IsSendingError = await VK.SendMessage(ulong.Parse(ConfigurationManager.AppSettings["OperatorVKID"]), $"Вопрос:\r\n{query}\U00002753\r\n\r\nКто задал -> https://vk.com/id{botUser.BotUserVKID} \U00002709"); if (thisRequest.IsSendingError == 0) {// все ок await sendHelper.SendText(textHelper.GetMessage("%questionsuccss%")); return(thisRequest); } else {// произошла ошибка при отправке сообщения оператору await sendHelper.SendText(textHelper.GetMessage("%questionfail%")); return(thisRequest); } } #endregion if (await AnaliseCommands(query) == 1) { return(thisRequest); } } var office = new DBHelpers.Models.MFCModels.Office(); var searchHelper = new SearchHelper(mfcDataOfBot); object alreadyFinded; switch (botUser.NowIs) { case MFCBotWhatIsHappeningNow.SettingOffice: #region SetOffice // включение/отключение расписаний филиалов if (ConfigurationManager.AppSettings["Schedules"] == "Enable") { mfcDataOfBot.Offices = SetSchedules(mfcDataOfBot.Offices); } List <FuzzySearchResult> result = null; switch (botUser.InputDataType) { case InputDataType.Image: //хз ваще break; case InputDataType.GeoLocation: result = searchHelper.SearchOfficeByGeocode((DbGeography)usefulData); thisRequest.Answer = GetAnswer(result); break; case InputDataType.Text: alreadyFinded = cacheHelper.Get($"SETOFFICES{botUser.BotUserVKID}"); if (alreadyFinded == null) { result = searchHelper.SearchOfficeByName(query); thisRequest.Answer = GetAnswer(result); } else { result = searchHelper.SearchOfficeByName(query, (string)alreadyFinded); thisRequest.Answer = GetAnswer(result); } break; } if (result.Count == 1 && ConfigurationManager.AppSettings["IsTestMode"] != "off") { result = DoDummy(); } thisRequest.Answer = GetAnswer(result); await AnaliseSearchOfficeResult(result); #endregion break; case MFCBotWhatIsHappeningNow.SettingOpportunity: //новый флаг! нужен для идентификации выбора (проверить статус/записаться на услугу) #region SetOpp int numFromList; if (int.TryParse(query, out numFromList) && (numFromList == 1 || numFromList == 2)) { if (numFromList == 1) // выбрана проверка статуса { botUser.NowIs = MFCBotWhatIsHappeningNow.GetingTicketInformation; office = mfcDataOfBot.Offices.FirstOrDefault(x => x.AisMFCID == botUser.OfficeID); await sendHelper.SendText(textHelper.GetMessage("%gtinfstart%", new string[] { "%officename%", "%adress%", "%business%" }, new string[] { office.DisplayName, office.DisplayAddress, GetBusynessOffice(office.AisMFCID) })); } if (numFromList == 2) // выбрана запись на услугу { botUser.NowIs = MFCBotWhatIsHappeningNow.SettingService; office = mfcDataOfBot.Offices.FirstOrDefault(x => x.AisMFCID == botUser.OfficeID); await SelectSendSetTenPopularServices(office.DisplayName, office.AisMFCID, office.DisplayAddress); } } else { // что-то другое await sendHelper.SendText(textHelper.GetMessage("%slctopfail%")); } #endregion break; case MFCBotWhatIsHappeningNow.SettingService: #region SetService alreadyFinded = cacheHelper.Get($"SETSERVICE{botUser.BotUserVKID}"); if (alreadyFinded == null) { alreadyFinded = cacheHelper.Get($"SETSERVICES{botUser.BotUserVKID}"); if (alreadyFinded == null) { office = mfcDataOfBot.Offices.FirstOrDefault(x => x.AisMFCID == botUser.OfficeID); await SelectSendSetTenPopularServices(office.DisplayName, office.AisMFCID, office.DisplayAddress); return(thisRequest); } //если есть информация о множестве услуг, значит ведем поиск по ним if (int.TryParse(query, out numFromList)) { //теперь поиск ведется по секциям, а не сервисам result = searchHelper.SearchSectionByName(query, (string)alreadyFinded); thisRequest.Answer = GetAnswer(result); if (result.Count == 0) { await sendHelper.SendText(textHelper.GetMessage("%slctsrvicefail%")); return(thisRequest); } } else { if (alreadyFinded.ToString().Last() == '¡' || alreadyFinded.ToString().Last() == '!') //в данном случае, это флаг, который говорит, что кэшированные данные относятся к списку 10-ти самых популярных услуг { //теперь поиск ведется по секциям, а не сервисам result = searchHelper.SearchSectionByName(query); thisRequest.Answer = GetAnswer(result); } else { await sendHelper.SendText(textHelper.GetMessage("%slctsrvicesucs%")); return(thisRequest); } } await AnaliseSearchServiceResult(result); } else // если есть информация об услуге, значит ждем подтвержденеия { if (!string.IsNullOrWhiteSpace(query) && query == "да") { var service = mfcDataOfBot.Sections.FirstOrDefault(x => x.SectionID == (int)alreadyFinded); office = mfcDataOfBot.Offices.FirstOrDefault(x => x.AisMFCID == botUser.OfficeID); var message = textHelper.GetMessage("%talon%"); var talon = mfcservice.Enqueue(service.SectionID, botUser.OfficeID); if (talon == null || talon?.ID == 0) //аис не выдал талон => не поставил пользователя в очередь { await sendHelper.SendText(textHelper.GetMessage("%talonerr%")); } else { message = Analiser.AnaliseTalon(talon, message, service.Name, office); botUser.TalonID = talon.ID; botUser.ServiceID = service.SectionID; botUser.NowIs = MFCBotWhatIsHappeningNow.QueueWaiting; await sendHelper.SendText(message); } cacheHelper.Clear(botUser.BotUserVKID); } else { office = mfcDataOfBot.Offices.FirstOrDefault(x => x.AisMFCID == botUser.OfficeID); await SelectSendSetTenPopularServices(office.DisplayName, office.AisMFCID, office.DisplayAddress); } cacheHelper.Remove($"SETSERVICE{botUser.BotUserVKID}"); } #endregion break; case MFCBotWhatIsHappeningNow.GetingTicketInformation: #region GetTicketInfo office = mfcDataOfBot.Offices.FirstOrDefault(x => x.AisMFCID == botUser.OfficeID); if (int.TryParse(query, out numFromList)) { //проверяем введенный номер await sendHelper.SendText(Analiser.GetAnalysedAnswer(botUser, office, numFromList, textHelper, mfcDataOfBot.WindowsOffices)); } else { await sendHelper.SendText(textHelper.GetMessage("%gtinfstart%", //начальное сообщение new string[] { "%officename%", "%adress%", "%business%" }, new string[] { office.DisplayName, office.DisplayAddress, GetBusynessOffice(office.AisMFCID) })); } #endregion break; case MFCBotWhatIsHappeningNow.QueueWaiting: #region QueueWait //var rnd = new Random(); //var joke = mfcDataOfBot.Jokes[rnd.Next(mfcDataOfBot.Jokes.Count)]; //await sendHelper.BotSendText(joke.Text); //thisRequest.Answer = "joke"; await sendHelper.SendText(textHelper.GetMessage("%waitinghelp%", "%number%", BotTextHelper.GetEmojiNumber((int)botUser.TalonID))); #endregion break; } return(thisRequest); }
private async Task <int> SendAllFindedInformation() { var groupes = (List <GroupedOrganization>)answer.GroopedResult; groupes.OrderByDescending(x => x.AverageRating).ToList(); string p = texter.GetMessage("%srchsuccess%") + "\\r\\n\\r\\n"; int i = 0; foreach (Floor f in dataOfBot.Floors) { var groupsFromFloor = groupes.Where(x => x.FloorID == f.FloorID).ToList(); if (groupsFromFloor.Count != 0) { char index = 'A'; foreach (var group in groupsFromFloor) { if (index != 'F') { p += $"{index}: "; index++; } foreach (var org in group.Orgs.DistinctBy(x => x.Name)) { p += org.Name + ", "; } p = p.Remove(p.Length - 2, 2); p += "\\r\\n\\r\\n"; } if (type == SocialNetworkType.VK) { await sender.SendPhoto(answer.FloorsPictures[i].Bmp, p); } else { await sender.SendText(p); await sender.SendPhoto(answer.FloorsPictures[i].Bmp); } p = ""; i++; } } return(1); }