Esempio n. 1
0
        protected override async Task ExecuteAsync(CancellationToken token)
        {
            if (!await IsValid(token).ConfigureAwait(false))
            {
                throw new ArgumentException("Invalid Bot Token");
            }

            var offset = 0;

            while (!token.IsCancellationRequested)
            {
                var bot = GetBotClient();

                var response = await bot.HandleAsync(new GetUpdates
                {
                    Offset         = offset,
                    Limit          = _config.Limit,
                    Timeout        = _config.Timeout,
                    AllowedUpdates = _config.AllowedUpdates
                }, token)
                               .ConfigureAwait(false);

                if (!response.Ok || response.Result.Count <= 0)
                {
                    continue;
                }

                foreach (var update in response.Result)
                {
                    await _handler.HandleAsync(bot, update, token);
                }

                offset = response.Result[^ 1].Id + 1;