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

After upgrade to 7.2.x AbilityBot.onRegister must be called manually or it will fail to accept messages #1354

Open
chpasha opened this issue Apr 17, 2024 · 3 comments
Labels
Abilities Bugs related to abilities module bug Spring Bugs related to spring module

Comments

@chpasha
Copy link

chpasha commented Apr 17, 2024

Describe the bug
After upgrade to 7.2.x if I don't call AbilityBot.onRegister() method manually after bot creation, it will fail to receive any messages from API with following exception

Exception in thread "pool-2-thread-1" java.lang.NullPointerException: Cannot invoke "java.util.List.stream()" because "this.replies" is null
	at org.telegram.telegrambots.abilitybots.api.bot.BaseAbilityBot.filterReply(BaseAbilityBot.java:621)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:178)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
	at java.base/java.util.stream.Streams$StreamBuilderImpl.forEachRemaining(Streams.java:411)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at org.telegram.telegrambots.abilitybots.api.bot.BaseAbilityBot.consume(BaseAbilityBot.java:201)
	at org.telegram.telegrambots.abilitybots.api.bot.AbilityBot.consume(AbilityBot.java:37)

this.replies is indeed null until onRegister is called. So my question is, am I doing something wrong? Documentation says nothing about it and yet everything works fine only if I call this method manually. If it is an intention? If so, why it is not mentioned anywhere. And if it is an intention, it looks like a bad design choice, because some magic method on bot must be called additionally to its creation and registration in TelegramBotApplication

To Reproduce
Steps to reproduce the behavior:

implementation 'org.telegram:telegrambots-springboot-longpolling-starter:7.2.1'
implementation 'org.telegram:telegrambots-abilities:7.2.1'
implementation 'org.telegram:telegrambots-client:7.2.1'

class MyBot extends AbilityBot implements SpringLongPollingBot  {}


Expected behavior
Ideally, onRegister would be called automatically OR at least mentioned in the documentation and examples provided

@Chase22 Chase22 added bug Spring Bugs related to spring module labels May 29, 2024
@rubenlagus
Copy link
Owner

@chpasha have you try adding this to your bot?

    @AfterBotRegistration
    @Override
    public void onRegister() {
        super.onRegister();
    }

That should ensure that, after registering the bot in spring, the onRegister method is autocalled.

@chpasha
Copy link
Author

chpasha commented Jul 8, 2024

Hi, thanks. I used the @PostConstruct annotation which might be not the 100% right one, since post construction doesn't mean, the bot is already registered, but because the default implementation creates some stuff and doesn't seem to depend on being really registered, that did the trick. But like I wrote before, I found such design decision questionable, that some method has to be called before bot is usable. Is there any reason why you can't call onRegister on public method of the bot, when registerBot is called?

@rubenlagus
Copy link
Owner

I don't think abilities was built with spring boot in mind. Hence it requires some extra workarounds to make it work.

@rubenlagus rubenlagus added the Abilities Bugs related to abilities module label Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Abilities Bugs related to abilities module bug Spring Bugs related to spring module
Projects
None yet
Development

No branches or pull requests

3 participants