Esempio n. 1
0
 public void PostMessage(TelegramMessage message)
 {
     _logger.LogTrace("Telegram message: {text}", message.Text);
     if (IsEnabled)
     {
         _botMessageQueue.Enqueue(message);
     }
 }
Esempio n. 2
0
        public void PostMessage(string text, string ticker, long chatId = 0)
        {
            if (chatId == 0)
            {
                chatId = _chatId;
            }
            _logger.LogTrace("Telegram message: {text}", text);
            var message = new TelegramMessage(ticker, text, chatId);

            if (IsEnabled)
            {
                _botMessageQueue.Enqueue(message);
            }
        }
Esempio n. 3
0
        internal async Task <bool?> ExecuteWithBot(Func <TelegramBotClient, Task> botAction, TelegramMessage messageForEnqueueOnTooMuchRequests)
        {
            try
            {
                await botAction(_bot);
            }
            catch (HttpRequestException httpEx)
            {
                _logger.LogError(httpEx.Message);
                if (httpEx.Message.Contains("429"))
                {
                    await Task.Delay(1000);

                    if (messageForEnqueueOnTooMuchRequests != null)
                    {
                        _botMessageQueue.Enqueue(messageForEnqueueOnTooMuchRequests);
                    }
                    return(false);
                }
            }
            catch
            {
                return(null);
            }
            return(true);
        }