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, "vk"); peopleParser.EvaluateState(user.UserId); var updatedState = container.Get <RegisterInProcessVK>(); vkMessageSender.SendNotification(user, text, updatedState.GetKeyboard()); break; } default: vkUnknownMessageProcessor.ProcessUnknownCommand(messageText, user, GetKeyboard(), new MessageResponse(ResponseType.NotRegisterError)); break; } }
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 ProcessUnknownCommand(string messageText, BotUser user, MessageKeyboard keyboard, MessageResponse messageResponse) { var helpCommands = helpCommandListProvider.GetCommands(); if (helpCommands.Contains(messageText)) { var helpMessage = new MessageResponse(ResponseType.Help).response; vkMessageSender.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); vkMessageSender.SendNotification(user, response.response, keyboard); }