Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TelegramBot.setUpdatesListener(UpdatesListener, GetUpdates) #105

Closed
theskylineguy opened this issue Jul 20, 2017 · 9 comments
Closed

TelegramBot.setUpdatesListener(UpdatesListener, GetUpdates) #105

theskylineguy opened this issue Jul 20, 2017 · 9 comments

Comments

@theskylineguy
Copy link

Hi,

I am having some problems here: when I run the application it prints out the same first Update in an infinite loop, acting like it doesn't confirm it. I'm pretty sure it's an offset issue, though I don't understand how to increment its value like you explained in your documentation, since I am using the UpdatesListener with the getUpdates request and not just the second one - using this because I need to filter only some kind of Updates. Could you clarify me how to achieve this?

Here's part of the code:

public final class Main
{
    public static void main (String[] args)
    {
        final TelegramBot bot = TelegramBotAdapter.build ("<TOKEN>");
        
        final UpdatesListener updateListener = new UpdatesListener ()
        {
            @Override
            public int process (List<Update> updates)
            {
                Update lastUpdate = updates.get (updates.size() - 1);
                
                for (Update update : updates)
                {
                    out.println (update);
                }
                
                
                return UpdateManager.confirm (lastUpdate);
            }
        };
        
        
        bot.setUpdatesListener (updateListener, new GetUpdates().offset(0).limit(10).timeout(30).allowedUpdates("message", "callback_query", "channel_post"));
    }
}


public class UpdateManager
{
    public static int confirm (Update update)
    {
        return (update.updateId().intValue() + 1);
    }
}

Thanks in advance.

@pengrad
Copy link
Owner

pengrad commented Jul 20, 2017

Hi,
Just returning return UpdatesListener.CONFIRMED_UPDATES_ALL; will work for you?

https://github.com/pengrad/java-telegram-bot-api#updates-listener

@theskylineguy
Copy link
Author

I already tried this, but it doesn't seem to work for me. What else can I do?

@pengrad
Copy link
Owner

pengrad commented Jul 21, 2017

I'm afraid it can happens because allowedUpdates.
Try to test Api directly, or use this one
https://rapidapi.com/package/TelegramBot/functions/getUpdates

And return here if it will work for you

@theskylineguy
Copy link
Author

theskylineguy commented Jul 23, 2017

I get the right Updates both on https://api.telegram.org/botTOKEN/getUpdates and https://rapidapi.com/package/TelegramBot/functions/getUpdates.

The problem is not in the Telegram API, but how to confirm incoming Updates via the GetUpdates request in setUpdatesListener method.

@pengrad
Copy link
Owner

pengrad commented Jul 23, 2017

I dont handle allowedUpdates. Will release 3.1.1 today with fix

@pengrad
Copy link
Owner

pengrad commented Jul 23, 2017

Btw, returning CONFIRMED_UPDATES_ALL or updates.get(updates.size() - 1).updateId() (don't increment it by yourself) works fine for me now

@theskylineguy
Copy link
Author

Can you post a snippet of any bot of yours code for comparison?

@pengrad
Copy link
Owner

pengrad commented Jul 23, 2017

I fixed it in 3.2.0 together with Sticker updates.
Use updates.get(updates.size() - 1).updateId() or CONFIRMED_UPDATES_ALL

@pengrad pengrad closed this as completed Jul 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants