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

Issue with middlewares #1133

Open
destyk opened this issue Aug 31, 2023 · 1 comment
Open

Issue with middlewares #1133

destyk opened this issue Aug 31, 2023 · 1 comment

Comments

@destyk
Copy link

destyk commented Aug 31, 2023

Issue:

Found an issue with middlewares: regular middlewares doesn't fire when the user moves through scenes.

Solution:

Add a UseStage decorator that will work similar to the Use decorator, but instead of using this.bot.use(), use this.stage.use(). Such middlewares work regardless of whether the user is in the scene or not

@destyk
Copy link
Author

destyk commented Aug 31, 2023

The problem is currently solved like this:

@Update()
export class Middleware implements OnModuleInit {
    constructor(
        @Inject(TELEGRAF_STAGE)
        private readonly stage: Scenes.Stage<any>,
    ) {}

    public onModuleInit(): void {
        this.stage.use((ctx: SceneContext, next: () => Promise<void>) => {
            // something...
            return next();
        });
    }
}

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

No branches or pull requests

1 participant