Exemple #1
0
        internal virtual async Task Send(TelegramManager tgManager)
        {
            InlineKeyboardMarkup markup = null;
            bool?sentState = null;

            if (Ticker != null)
            {
                markup = new InlineKeyboardMarkup(
                    new[]
                {
                    new[]
                    {
                        InlineKeyboardButton.WithUrl($"Открыть {Ticker} в Инвестициях",
                                                     String.Format(TelegramManager.TinkoffInvestStocksUrl, Ticker))
                    }
                });
                var chartUrl = tgManager.GetStockChart(Ticker);
                if (chartUrl != null && AddTickerImage)
                {
                    sentState = await tgManager.ExecuteWithBot(async (bot)
                                                               => await bot.SendPhotoAsync(ChatId, new InputOnlineFile(chartUrl),
                                                                                           Text, ParseMode.Markdown, replyMarkup: markup), this);

                    if (sentState == false)
                    {
                        return;
                    }
                }
            }
            if (sentState == null)
            {
                await tgManager.ExecuteWithBot(async (bot)
                                               => await bot.SendTextMessageAsync(ChatId, Text, replyMarkup: markup, parseMode: ParseMode.Markdown), this);
            }
        }
Exemple #2
0
        public void Init()
        {
            if (_telegram != null)
            {
                _telegram.Stop();
            }

            if (TgBotToken != null && TgChatId > long.MinValue)
            {
                _telegram = new TelegramManager(_services, TgBotToken, TgChatId);
            }

            if (TiApiToken == null)
            {
                return;
            }

            PrepareConnection();

            if (CommonConnectionQueueTask == null)
            {
                CommonConnectionQueueTask = Task.Factory
                                            .StartNew(() => BrokerQueueLoopAsync()
                                                      .ConfigureAwait(false),
                                                      _cancellationTokenSource.Token,
                                                      TaskCreationOptions.LongRunning,
                                                      TaskScheduler.Default);

                _responseProcessingTasks = new Task[1];
                for (int i = 0; i < _responseProcessingTasks.Length; i++)
                {
                    _responseProcessingTasks[i] = Task.Factory
                                                  .StartNew(() => RespProcessingLoopAsync()
                                                            .ConfigureAwait(false),
                                                            _cancellationTokenSource.Token,
                                                            TaskCreationOptions.LongRunning,
                                                            TaskScheduler.Default);
                }
            }
        }
Exemple #3
0
 public SandboxBot(StocksManager broker, TelegramManager telegram)
 {
     _broker   = broker;
     _telegram = telegram;
 }