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

Scenes usage #926

Open
ddtch opened this issue Aug 29, 2022 · 1 comment
Open

Scenes usage #926

ddtch opened this issue Aug 29, 2022 · 1 comment

Comments

@ddtch
Copy link

ddtch commented Aug 29, 2022

Hello, my issue is more about the question of how to work with scenes?
This part is really not described well in docs.

I was trying to create scene like this

@Update()
@Injectable()
@Scene('mainScene')
export class TbotService {
  constructor(
    @InjectBot() private bot: Telegraf<any>,
  ) {
  }

  @Start()
  async startCommand(ctx: SceneContext) {
    console.log(this.bot)
    await ctx.reply('Welcome ss');
  }
}
// other scene
@Update()
@Injectable()
@Scene('authScene')
export class TbotService {
  constructor(
    @InjectBot() private bot: Telegraf<any>,
  ) {
  }

  @SceneEnter()
  async sayHi(ctx: SceneContext) {
    await ctx.reply('Welcome ss');
  }
}

But after I add SceneEnter decorator, I see an error.

/Users/backend/node_modules/nestjs-telegraf/dist/services/listeners-explorer.service.js:133
            composer[method](...args, async (ctx, next) => {
                            ^
TypeError: Function.prototype.apply was called on undefined, which is a undefined and not a function
    at ListenersExplorerService.registerIfListener (/Users/backend/node_modules/nestjs-telegraf/dist/services/listeners-explorer.service.js:133:29)
    at MapIterator.iteratee (/Users/backend/node_modules/nestjs-telegraf/dist/services/listeners-explorer.service.js:92:82)
    at MapIterator.next (/Users/backend/node_modules/iterare/src/map.ts:9:39)
    at FilterIterator.next (/Users/backend/node_modules/iterare/src/filter.ts:11:34)
    at IteratorWithOperators.next (/Users/backend/node_modules/iterare/src/iterate.ts:19:28)
    at Function.from (<anonymous>)
    at IteratorWithOperators.toArray (/Users/backend/node_modules/iterare/src/iterate.ts:227:22)
    at MetadataScanner.scanFromPrototype (/Users/backend/node_modules/@nestjs/core/metadata-scanner.js:12:14)
    at ListenersExplorerService.registerListeners (/Users/backend/node_modules/nestjs-telegraf/dist/services/listeners-explorer.service.js:92:30)
    at /Users/backend/node_modules/nestjs-telegraf/dist/services/listeners-explorer.service.js:53:41

Any Ideas, advices ?

@DBTK1990
Copy link

you need to add the session middleware
and update telegraf to the latest version
if you won't update you will get depracted notice

import { Module } from '@nestjs/common';
import { TelegrafModule } from 'nestjs-telegraf';
import { TestBotModule } from './test-bot/test-bot.module';
import { session } from 'telegraf';


@Module({
  imports: [
    TelegrafModule.forRoot({
      token: 'TALGRAM_TOKEN',
      middlewares: [session()],
    }),
    TestBotModule
  ],
})
export class AppModule { }

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

2 participants