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
Awaiting for telegraf.launch() stops the code. #1749
Comments
|
Thanks for opening this issue. Since 4.11 (4.11.0 release notes: see "Other changes"), we made a choice to make We're aware that although the previous behaviour was undocumented, many users have relied on it to get a "bot started" event. I'm holding off on "fixing" this prematurely by rolling back, so that we can still provide a way for errors to be caught. Meanwhile, you can do this: const config = require("./config.json");
const { Telegraf } = require(https://github.com/telegraf/telegraf);
(async () => {
const telegraf = new Telegraf(config.telegram.token);
console.log("Telegram started.");
await telegraf.launch();
})(); Note that awaiting I'll leave this issue open until we've provided a new solution to both sides. |
You could also do this: bot.botInfo = await bot.telegram.getMe();
console.log("Bot started");
bot.launch(); This will prevent launch() from calling getMe on its own, and has all the same guarantees pre-4.11.0 had. |
Thanks! It works, but as you said, I won't close the problem until you come up with a better solution. |
Thanks for pointing this out. I ran into a similar scenario and just omitted the await keyword |
Having the same issue after upgrade. |
not work for 4.12.2 |
Please update the documentation. |
I solved the problem, for me this solution is suitable. [email protected]
I hope, I solved your question. |
This is basically the same solution as @MKRhere provided year ago |
I don't think this works, my test failed at [email protected]. |
This worked for me
|
Here we go! #1949 adds a callback to bot.launch(() => console.log("Bot is starting!")); If you pass LaunchOptions, the callback goes after the options. bot.launch({ dropPendingUpdates: true }, () => console.log("Bot is starting!")); This is available on npm as a release candidate: 4.16.0-rc.2. Stable release when #1949 is merged. |
How does this solve the original issue? |
Read https://github.com/telegraf/telegraf/releases/tag/v4.11.0 for more details on why that change was made. |
Context
Trying to await for the bot to launch stops the code. I think this is done so that the code does not close after the bot is launched, but my code requires waiting for the bot to connect for the rest code to work. Is there any better way of doing so?
It worked before with older version of telegraf (4.10.0).
Minimal Example Code Reproducing the Issue
Expected Behavior
"Telegram started." in console.
Current Behavior
Nothing
Error Message and Logs (
export DEBUG='telegraf:*'
)The text was updated successfully, but these errors were encountered: