public async Task ProcessMessageAsync(Message inputMessage) { try { IMessage resultMessage = null; if (inputMessage == null || string.IsNullOrEmpty(inputMessage.Text)) { resultMessage = BaseTgMessageHandler.GetDefaultResponse(inputMessage.Chat.Id); } _logger.Info($"Incoming message from {inputMessage.Chat.Id}. Message content: \"{inputMessage.Text}\""); var user = DefineUser(inputMessage.Chat); _historyLogger.LogHistory(inputMessage.Chat.Id, DateTime.Now, false, inputMessage.Text); var userInput = inputMessage.Text.Split("|||", System.StringSplitOptions.RemoveEmptyEntries); var handler = _myMessageHandlers.FirstOrDefault(han => han.UsedUserInput == userInput.FirstOrDefault()) ?? _myMessageHandlers.FirstOrDefault(han => han.UsedChatState == user.State); resultMessage = handler != null ? handler.GetResponseTo(inputMessage, user) : BaseTgMessageHandler.GetDefaultResponse(inputMessage.Chat.Id); await _messageSender.SendMessageToUser(resultMessage); } catch (Exception ex) { _logger.Error(ex, $"Exception happened in TelegramMessageRouter. {ex}"); } }
public OutputUserMessage ProcessMessage(Message inputMessage) { if (inputMessage == null || string.IsNullOrEmpty(inputMessage.Text)) { return(BaseTgMessageHandler.GetDefaultResponse(inputMessage.Chat.Id)); } _logger.Info($"Incoming message from {inputMessage.Chat.Id}. Message content: \"{inputMessage.Text}\""); var user = GetOrCreateUser(inputMessage.Chat.Id); if (_messageHandlers.ContainsKey(user.State)) { return(_messageHandlers[user.State].GetResponseTo(inputMessage, user)); } if (_commandHandlers.ContainsKey(inputMessage.Text)) { return(_commandHandlers[inputMessage.Text].GetResponseTo(inputMessage, user)); } return(BaseTgMessageHandler.GetDefaultResponse(inputMessage.Chat.Id)); }