Search code examples
pythonlong-pollingtelegram-botpython-telegram-bot

Why does telegram.Bot.getUpdates() long polling returns immediately?


According to telegram api, the getUpdates function receives incoming updates using long polling (wiki). From wiki:

If the server does not have any information available for the client when the poll is received, instead of sending an empty response, the server holds the request open and waits for response information to become available. Once it does have new information, the server immediately sends an HTTP/S response to the client, completing the open HTTP/S Request.

Then, why does the function getUpdates() returns immediately, even though the timeout parameter is set?

The function call: bot.getUpdates(offset=lastUpdateID, timeout=120)

There are no new updates and the offset=lastUpdateID is the last update.

I'm using library python telegram bot library


Solution

  • The problem was I asked for offset=lastUpdateID x, and I should have asked for offset=lastUpdateID x + 1