xooniverse / televerse

Your gateway to seamless Telegram Bot Development 💙
https://televerse.xooniverse.com
BSD 3-Clause "New" or "Revised" License
64 stars 11 forks source link

Error: Field 'api' has already been inizialized #281

Closed IsD4n73 closed 3 months ago

IsD4n73 commented 3 months ago

Hi!

I have a problem with the stop and start bot: On the first startup with bot.start(); there are no problems and the bot works correctly.

When I go to do the bot.stop(); and then bot.start();

I get this error:

LaterInitializationError: Field 'api' has already been inizialized.

I wanted to see if I am doing something wrong in the implementation

Here is the complete code:

if (botStarted) {
    await bot.stop();
} else {
    bot.onCommand(...);
    bot.onError(...);

    await bot.start();
} 

Thank you!

HeySreelal commented 3 months ago

Hey, thank you so much for raising this issue. I'll quickly check this and resolve this as soon as possible.

On the first glance, this seems like a bug with the library. I'll get back with more info soon. Thanks again :)

HeySreelal commented 3 months ago

Hey, just an update. It was a bug with the library. You can check the #282 for more details on what happened and what was changed to fix this.

I've already pushed the v1.22.2 to pub.dev. Please update the version and let me know if this works out for you. There's a minor change required at your side (explained down below).


In a nutshell, when the bot.start is called we blindly tried to set the Fetcher.api property even though it was final.

In this change I've added Bot.pause and Bot.resume methods. Please use these instead of Bot.stop and Bot.start if you're looking to temporarily stop the bot. This is because (as explained in #282) when Bot.stop is called we close all the connected resources (including the HTTP Client) - so you know, any request made after closing the HTTP client will throw an exception.


Just in case you're stuck anytime feel free to jump into our Telegram chat or feel free to raise a discussion or issue in the repo.

Hope this helps and thank you so much again for raising the issue. Happy Televersing! 🚀