public QuoteValueCriterionSubscriptionCommand(QuoteValueCriterionSubscriptionRequest request, ISubscriptionsManager subscriptionsManager, IExchangeRatesProvider exchangeRatesProvider) { _request = request ?? throw new ArgumentException($"{nameof(QuoteValueCriterionSubscriptionRequest)} {MessageTexts.NotSpecified}"); _subscriptionsManager = subscriptionsManager ?? throw new ArgumentException($"{nameof(ISubscriptionsManager)} {MessageTexts.NotSpecified}"); _exchangeRatesProvider = exchangeRatesProvider ?? throw new ArgumentException($"{nameof(IExchangeRatesProvider)} {MessageTexts.NotSpecified}"); }
private async void BotOnMessage(object sender, MessageEventArgs e) { var message = e.Message; if (message == null || message.Type != MessageType.Text) { return; } var cmdArgs = message.Text.Split(' '); try { switch (cmdArgs.First()) { case QuoteValueCriterionSubscriptionRequest.CommandShortcutStatic : // e.g. - /quote Sberbank>250 then signal await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.Typing); await Task.Delay(_chatInteractionDelay); var quoteRequest = new QuoteValueCriterionSubscriptionRequest(cmdArgs, message.Chat.Id); var quoteCmd = new QuoteValueCriterionSubscriptionCommand(quoteRequest, _subscriptionsManager, _ratesProvider); var requestValid = await quoteCmd.Validate(); if (!requestValid) { await Bot.SendTextMessageAsync(message.Chat.Id, _quoteUsageFormat); break; } var response = await quoteCmd.Process(); await Bot.SendTextMessageAsync(message.Chat.Id, response.ResultMessage); break; default: await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.Typing); await Task.Delay(_chatInteractionDelay); await Bot.SendTextMessageAsync(message.Chat.Id, _quoteUsageFormat); break; } } catch (ArgumentException) { await Bot.SendTextMessageAsync(message.Chat.Id, _quoteUsageFormat); } catch (NotImplementedException) { await Bot.SendTextMessageAsync(message.Chat.Id, _notImplementedExcMsg); } catch (Exception) { await Bot.SendTextMessageAsync(message.Chat.Id, _internalErrorMsg); } }