Giter Club home page Giter Club logo

Comments (1)

AmanAgnihotri avatar AmanAgnihotri commented on July 20, 2024

Hi! Apologies for the late reply. The pandemic situation made my life such that I did not notice this issue until now.

To get updates, you need only configure the BotClient and then make the GetUpdates request with relevant parameters.

I have created a separate project, Telegram.Bots.Extensions.Polling, which polls for the updates as a background service and sends each update to a user-defined handler to manage it. It basically works as follows:

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;
}

You can either try using its approach to poll for your own purposes or can use the project (it comes as a NuGet package too) to then simply define your update handler and work with it. That project has its own README that you can check for more info on how to setup your update handler. The static typing will make defining the various cases for the update handler much easier and you can always ask more questions for clarification.

from telegram.bots.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.