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

Stage should not passThru by default #1850

Open
MKRhere opened this issue Jun 9, 2023 · 0 comments
Open

Stage should not passThru by default #1850

MKRhere opened this issue Jun 9, 2023 · 0 comments

Comments

@MKRhere
Copy link
Member

MKRhere commented Jun 9, 2023

⚠️ Note: Leave your opinions on this issue if you don't want this to happen. Upvote if you want it to happen.

Currently this code:

const scene = new Scene("demo");
scene.enter(ctx => ctx.reply("welcome"));
scene.command("scene", ctx => ctx.reply("inside scene"));
scene.command("leave", ctx => ctx.scene.leave());

bot.use(new Stage([scene]));
bot.use(session());

bot.command("hello", ctx => ctx.reply("ohayo"));
bot.command("enter", ctx => ctx.scene.enter("demo"));
bot.start();

With this input, behaves like this:

User: /enter
Bot: welcome <- scene entered
User: /scene
Bot: inside scene <- handler inside scene responds
User: /hello
Bot: ohayou <- handler outside scene responds

The common expectation seems to be that once in a scene, handlers outside the scene do not work for this user. However, this is not the current behaviour. If no listeners on the scene match, Telegraf passes through and calls the next middleware.

This issue proposes this behaviour changes in v5, with the addition of an option to Stage:

new Stage([scene], { passThru: true })

passThru will be false by default, and will prevent users from escaping a scene. It can be set to true for current behaviour. Per-scene passThru may also be possible.

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