private void test() { MsgCommand command = new("stringa1"); BaseCommandHandler <MsgCommand> handler = _container.Resolve <BaseCommandHandler <MsgCommand> >(); handler.Handle(command); }
private async void OnMessage(object sender, MessageEventArgs e) { var selectedCommand = _selectedCommands?.FirstOrDefault(x => x.ChatId == e.Message.Chat.Id); if (selectedCommand != null) { BaseCommandHandler commandHandler = selectedCommand.Command switch { ECommandType.Images => _imagesCommandHandler, ECommandType.Voice => _voiceCommandHandler, ECommandType.Pdf => _pdfCommandHandler, ECommandType.Docx => _docxCommandHandler }; await commandHandler.Handle(e.Message); _selectedCommands.Remove(selectedCommand); } else if (e.Message.Text != null && TryParseCommand(e.Message.Text, out var command)) { if (command == ECommandType.Start) { await _botClient.SendTextMessageAsync(e.Message.Chat.Id, "Welcome! I am waiting for your command.."); return; } _selectedCommands.Add(new UserCommand { ChatId = e.Message.Chat.Id, Command = command }); var response = "Ok. Now send " + command switch { ECommandType.Images => "image or multiple images", ECommandType.Voice => "voice message", ECommandType.Pdf => "text or images or voice message", ECommandType.Docx => "text or images or voice message", }; await _botClient.SendTextMessageAsync(e.Message.Chat.Id, response); } else { await _botClient.SendTextMessageAsync(e.Message.Chat.Id, "Send a valid command"); } }