pengrad / java-telegram-bot-api

Telegram Bot API for Java
https://core.telegram.org/bots
Apache License 2.0
1.81k stars 374 forks source link

One Message incoming twice #50

Closed Turael closed 8 years ago

Turael commented 8 years ago

Hey everyone,

I test a bit with that api in combination with Spring and I may found a bug or something? I have a Scheduled Bean with a fixedRate by 500ms - so every 500ms spring is calling that method. The rest of that method is like your example but if i write to the bot a bit faster then I get 2 messages with the same messageId... (see picture)

` GetUpdatesResponse updatesResponse = bot.execute(new GetUpdates().limit(0).offset(0).timeout(0)); List updates = updatesResponse.updates();

    // Collections.reverse(updates); // is that needed? 
    for (Update update : updates) {

        Message message = update.message();
        Chat chat = message.chat();
        User user = message.from();

        if (message.text() != null) {
            System.out.println("New message: " + message.text() + " id: " + message.messageId() + " from " + chat);
            SendResponse sendResponse = bot.execute(new SendMessage(chat.id(), "Selber: " + message.text()));

        }
    }

` Picture Terminaloutput and picture are not the same - it can reproduce...

Terminaloutput:

pengrad commented 8 years ago

Hi, you should increment offset parameter. See https://github.com/pengrad/java-telegram-bot-api/issues/30

Turael commented 8 years ago

ah thanks for that fast response - ok it works now :) Now i understand your Testclass

For other readers: Telegram Bot API tells you about the offset too