rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.64k stars 1.18k forks source link

Long polling bot receiving multiple updates for the same user command #679

Open krasawa opened 4 years ago

krasawa commented 4 years ago

On low connection my long polling bot receives multiple onUpdateReceived() for the same command. It's hard to reproduce, but I thing it may be related to offset param. https://core.telegram.org/bots/api#getupdates says:

In order to avoid getting duplicate updates, recalculate offset after each server response.

Maybe someone met this problem?

rubenlagus commented 4 years ago

Offset parameter is correctly updated everytime a new group of updates is received, so it shouldn't be necessary to do any extra processing here. Do you get any error in the logs?

In addition, it may make sense to change it to:

lastReceivedUpdate = updates.parallelStream()
                                        .map(
                                                Update::getUpdateId)
                                        .max(Integer::compareTo)
                                        .orElse(lastReceivedUpdate); // See change here
krasawa commented 4 years ago

@rubenlagus could you suggest how to enable logs in library? I don't see any errors now.