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

Warn on adding listeners after bot start #1861

Open
MKRhere opened this issue Jul 19, 2023 · 0 comments
Open

Warn on adding listeners after bot start #1861

MKRhere opened this issue Jul 19, 2023 · 0 comments

Comments

@MKRhere
Copy link
Member

MKRhere commented Jul 19, 2023

New users of Telegraf often mistakenly write listeners within listeners like so:

bot.command("form", async ctx => {
	await ctx.reply("Send first input");
	bot.on("message", async ctx => {
//	^^^ BUG! This attaches a new global listener every time!
		await ctx.reply("Send second input");
		...
	});
});

When exploring ideas to resolve this, @trgwii suggested that we log a warning when we detect new listeners added after bot.launch() (perhaps after the first bot.handleUpdate() to account for webhooks?). We don't really need to track all composers, because this problem almost exclusively happens with the base Telegraf instance. The warning can link to a doc page about this specific behaviour with alternatives (Wizard, ...?) and ways to disable the warning if they know what they're doing.

Before implementing this, I'd like to know if any plugins rely on this kind of behaviour at runtime. We may not want to go through with this if any popular plugin attaches listeners on Telegraf at runtime for a valid reason (Is there one? Ready to discuss).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant