Merge pull request #308 from Morb0/feature/export-stage

[Feature] Export Stage provider
This commit is contained in:
Alexander Bukhalo 2021-03-06 15:24:13 +03:00 committed by GitHub
commit 932832cc30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 3 deletions

View File

@ -12,6 +12,7 @@ import {
PARAM_ARGS_METADATA,
TELEGRAF_BOT_NAME,
TELEGRAF_MODULE_OPTIONS,
TELEGRAF_STAGE,
} from '../telegraf.constants';
import { BaseExplorerService } from './base-explorer.service';
import { TelegrafParamsFactory } from '../factories/telegraf-params-factory';
@ -23,10 +24,11 @@ export class ListenersExplorerService
extends BaseExplorerService
implements OnModuleInit {
private readonly telegrafParamsFactory = new TelegrafParamsFactory();
private readonly stage = new Scenes.Stage();
private bot: Telegraf<any>;
constructor(
@Inject(TELEGRAF_STAGE)
private readonly stage: Scenes.Stage<any>,
@Inject(TELEGRAF_MODULE_OPTIONS)
private readonly telegrafOptions: TelegrafModuleOptions,
@Inject(TELEGRAF_BOT_NAME)

8
lib/stage.provider.ts Normal file
View File

@ -0,0 +1,8 @@
import { Provider } from '@nestjs/common';
import { Scenes } from 'telegraf';
import { TELEGRAF_STAGE } from './telegraf.constants';
export const telegrafStageProvider: Provider = {
provide: TELEGRAF_STAGE,
useClass: Scenes.Stage,
};

View File

@ -18,6 +18,7 @@ import {
TELEGRAF_MODULE_OPTIONS,
} from './telegraf.constants';
import { ListenersExplorerService, MetadataAccessorService } from './services';
import { telegrafStageProvider } from './stage.provider';
import { createBotFactory, getBotToken } from './utils';
@Global()
@ -52,10 +53,15 @@ export class TelegrafCoreModule implements OnApplicationShutdown {
provide: TELEGRAF_MODULE_OPTIONS,
useValue: options,
},
telegrafStageProvider,
telegrafBotNameProvider,
telegrafBotProvider,
],
exports: [
telegrafStageProvider,
telegrafBotNameProvider,
telegrafBotProvider,
],
exports: [telegrafBotProvider],
};
}
@ -82,10 +88,15 @@ export class TelegrafCoreModule implements OnApplicationShutdown {
imports: options.imports,
providers: [
...asyncProviders,
telegrafStageProvider,
telegrafBotNameProvider,
telegrafBotProvider,
],
exports: [
telegrafStageProvider,
telegrafBotNameProvider,
telegrafBotProvider,
],
exports: [telegrafBotNameProvider, telegrafBotProvider],
};
}

View File

@ -9,3 +9,5 @@ export const SCENE_METADATA = 'SCENE_METADATA';
export const LISTENER_METADATA = 'LISTENER_METADATA';
export const PARAM_ARGS_METADATA = ROUTE_ARGS_METADATA;
export const TELEGRAF_STAGE = 'TelegrafStage';