public void ProcessMessage(string messageText, BotUser user) { switch (messageText) { default: { if (groupProvider.GetAllGroups().Contains(messageText.ToUpper())) { if (messageHandler.SaveGroup(messageText.ToUpper(), user)) { peopleParser.EvaluateState(user.UserId); var updatedState = container.Get <RegisterTG>(); tgMessageSender.SendNotification(user, new MessageResponse(ResponseType.SuccessfulRegistration).response, updatedState.GetKeyboard()); } else { tgMessageSender.SendNotification(user, new MessageResponse(ResponseType.GroupError).response, GetKeyboard()); } } else { tgUnknownMessageProcessor.ProcessUnknownCommand(messageText, user, GetKeyboard(), new MessageResponse(ResponseType.RegisterInProgressError)); } break; } } }
public void ProcessMessage(string messageText, BotUser user) { switch (messageText) { case "расписание на сегодня": { messageHandler.GetScheduleForToday(user); break; } case "расписание на завтра": { messageHandler.GetScheduleForNextDay(user); break; } case var n when n == registerCommandListProvider.GettingDiningRoom: { var visitorsCount = messageHandler.GetDiningRoom(user); var text = new MessageResponse(ResponseType.DiningRoom).response; tgMessageSender.SendNotification(user, text + visitorsCount, GetKeyboard()); break; } case "ссылки на учебные чаты": { messageHandler.GetLinks(user); break; } case "добавить ссылку на чат": { peopleParser.ChangeState(user.UserId, UserStates.AddingLink); var newUserState = container.Get <AddingLinkTG>(); tgMessageSender.SendNotification(user, new MessageResponse(ResponseType.LinksMessage).response, newUserState.GetKeyboard()); break; } default: { tgUnknownMessageProcessor.ProcessUnknownCommand(messageText, user, GetKeyboard(), new MessageResponse(ResponseType.RegisterError)); break; } } }
public void ProcessUnknownCommand(string messageText, BotUser user, ReplyKeyboardMarkup keyboard, MessageResponse messageResponse) { var helpCommands = helpCommandListProvider.GetCommands(); if (helpCommands.Contains(messageText)) { var helpMessage = new MessageResponse(ResponseType.Help).response; tgMessageSender.SendNotification(user, helpMessage, keyboard); return; } var allCommands = registerCommandListProvider.GetCommands() .Concat(notRegicterCommandListProvider.GetCommands()) .Concat(registerInProcessCommandListProvider.GetCommands()) .Concat(helpCommands) .ToArray(); var response = allCommands.Contains(messageText) ? messageResponse : new MessageResponse(ResponseType.Error); tgMessageSender.SendNotification(user, response.response, keyboard); }
private void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs) { var message = messageEventArgs.Message; var user = new BotUser(message.Chat.Id.ToString(), "tg"); var messageText = message.Text.ToLower(); if (message?.Type != MessageType.Text) { return; } var currentCommand = DefineCommand(user); try { currentCommand.ProcessMessage(messageText, user); } catch (Exception e) { var text = new MessageResponse(ResponseType.CatchError).response; Console.WriteLine(e); tgMessageSender.SendNotification(user, text, currentCommand.GetKeyboard()); } }
public void ProcessMessage(string messageText, BotUser user) { switch (messageText) { case "/start": case "start": case "начать": { var text = new MessageResponse(ResponseType.Start).response; peopleParser.AddNewUser(user.UserId, "tg"); peopleParser.EvaluateState(user.UserId); var updatedState = container.Get <RegisterInProcessTG>(); tgMessageSender.SendNotification(user, text, updatedState.GetKeyboard()); break; } default: tgUnknownMessageProcessor.ProcessUnknownCommand(messageText, user, GetKeyboard(), new MessageResponse(ResponseType.NotRegisterError)); break; } }