Closed Aliph0th closed 7 months ago
I get an error Cannot read properties of undefined (reading 'enter'), although the middleware with the session is called earlier than commandMiddleware
Cannot read properties of undefined (reading 'enter')
commandMiddleware
How to fix it?
app.update.ts
@Module({ imports: [ TelegrafModule.forRootAsync({ imports: [ConfigModule], inject: [ConfigService], useFactory(configService: ConfigService): TelegrafModuleOptions { const store = Mongo({ url: configService.getOrThrow<string>('MONGO_URI'), database: configService.getOrThrow<string>('MONGO_DB_SESSION_NAME') }); return { token: configService.getOrThrow<string>('BOT_TOKEN'), middlewares: [session({ store }), commandMiddleware] // <==================== }; } }) ], providers: [AppUpdate, HelpScene, AdminScene, RequestScene] }) export class AppModule {}
commandMiddleware.ts
export const commandMiddleware: Middleware<TelegrafSceneContext> = async ( ctx, next ) => { const text = (ctx.message as Message.TextMessage)?.text; if (text && text.startsWith('/')) { switch (text.slice(1)) { case 'help': ctx.scene.enter('help_scene'); break; case 'admin': ctx.scene.enter('admin_scene'); break; case 'request': ctx.scene.enter('request_scene'); break; } } next(); };
I get an error
Cannot read properties of undefined (reading 'enter')
, although the middleware with the session is called earlier thancommandMiddleware
How to fix it?
app.update.ts
commandMiddleware.ts