public async Task StartAsync(CancellationToken cancellationToken) { try { var me = await _botClient.GetMeAsync(); Console.WriteLine(me.FirstName + ": Бот готов к работе!"); await _botClient.ReceiveAsync(_handler, cancellationToken); } catch (Exception ex) { _logger.LogError(ex, "Error occurred while receiving updates"); } }
/// <summary> /// Start to service Updates with provided Update Handler class /// </summary> /// <param name="stoppingToken"></param> /// <returns></returns> public async Task ReceiveAsync(CancellationToken stoppingToken) { // ToDo: we can inject ReceiverOptions through IOptions container var receiverOptions = new ReceiverOptions() { AllowedUpdates = Array.Empty <UpdateType>(), ThrowPendingUpdates = true, }; var me = await _botClient.GetMeAsync(stoppingToken); _logger.LogInformation("Start receiving updates for {BotName}", me.Username ?? "My Awesome Bot"); // Start receiving updates await _botClient.ReceiveAsync( updateHandler : _updateHandlers, receiverOptions : receiverOptions, cancellationToken : stoppingToken); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _logger.LogInformation("BotHandlerService started"); await _client.ReceiveAsync(_updateHandler, stoppingToken).ConfigureAwait(false); }