mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 15:04:38 +03:00
feat(): make stage provider & export from module
This commit is contained in:
parent
67067d519f
commit
48c183a8ff
@ -12,6 +12,7 @@ import {
|
|||||||
PARAM_ARGS_METADATA,
|
PARAM_ARGS_METADATA,
|
||||||
TELEGRAF_BOT_NAME,
|
TELEGRAF_BOT_NAME,
|
||||||
TELEGRAF_MODULE_OPTIONS,
|
TELEGRAF_MODULE_OPTIONS,
|
||||||
|
TELEGRAF_STAGE,
|
||||||
} from '../telegraf.constants';
|
} from '../telegraf.constants';
|
||||||
import { BaseExplorerService } from './base-explorer.service';
|
import { BaseExplorerService } from './base-explorer.service';
|
||||||
import { TelegrafParamsFactory } from '../factories/telegraf-params-factory';
|
import { TelegrafParamsFactory } from '../factories/telegraf-params-factory';
|
||||||
@ -23,10 +24,11 @@ export class ListenersExplorerService
|
|||||||
extends BaseExplorerService
|
extends BaseExplorerService
|
||||||
implements OnModuleInit {
|
implements OnModuleInit {
|
||||||
private readonly telegrafParamsFactory = new TelegrafParamsFactory();
|
private readonly telegrafParamsFactory = new TelegrafParamsFactory();
|
||||||
private readonly stage = new Scenes.Stage();
|
|
||||||
private bot: Telegraf<any>;
|
private bot: Telegraf<any>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@Inject(TELEGRAF_STAGE)
|
||||||
|
private readonly stage: Scenes.Stage<any>,
|
||||||
@Inject(TELEGRAF_MODULE_OPTIONS)
|
@Inject(TELEGRAF_MODULE_OPTIONS)
|
||||||
private readonly telegrafOptions: TelegrafModuleOptions,
|
private readonly telegrafOptions: TelegrafModuleOptions,
|
||||||
@Inject(TELEGRAF_BOT_NAME)
|
@Inject(TELEGRAF_BOT_NAME)
|
||||||
|
8
lib/stage.provider.ts
Normal file
8
lib/stage.provider.ts
Normal 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,
|
||||||
|
};
|
@ -18,6 +18,7 @@ import {
|
|||||||
TELEGRAF_MODULE_OPTIONS,
|
TELEGRAF_MODULE_OPTIONS,
|
||||||
} from './telegraf.constants';
|
} from './telegraf.constants';
|
||||||
import { ListenersExplorerService, MetadataAccessorService } from './services';
|
import { ListenersExplorerService, MetadataAccessorService } from './services';
|
||||||
|
import { telegrafStageProvider } from './stage.provider';
|
||||||
import { createBotFactory, getBotToken } from './utils';
|
import { createBotFactory, getBotToken } from './utils';
|
||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@ -52,10 +53,15 @@ export class TelegrafCoreModule implements OnApplicationShutdown {
|
|||||||
provide: TELEGRAF_MODULE_OPTIONS,
|
provide: TELEGRAF_MODULE_OPTIONS,
|
||||||
useValue: options,
|
useValue: options,
|
||||||
},
|
},
|
||||||
|
telegrafStageProvider,
|
||||||
|
telegrafBotNameProvider,
|
||||||
|
telegrafBotProvider,
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
telegrafStageProvider,
|
||||||
telegrafBotNameProvider,
|
telegrafBotNameProvider,
|
||||||
telegrafBotProvider,
|
telegrafBotProvider,
|
||||||
],
|
],
|
||||||
exports: [telegrafBotProvider],
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,10 +88,15 @@ export class TelegrafCoreModule implements OnApplicationShutdown {
|
|||||||
imports: options.imports,
|
imports: options.imports,
|
||||||
providers: [
|
providers: [
|
||||||
...asyncProviders,
|
...asyncProviders,
|
||||||
|
telegrafStageProvider,
|
||||||
|
telegrafBotNameProvider,
|
||||||
|
telegrafBotProvider,
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
telegrafStageProvider,
|
||||||
telegrafBotNameProvider,
|
telegrafBotNameProvider,
|
||||||
telegrafBotProvider,
|
telegrafBotProvider,
|
||||||
],
|
],
|
||||||
exports: [telegrafBotNameProvider, telegrafBotProvider],
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,3 +9,5 @@ export const SCENE_METADATA = 'SCENE_METADATA';
|
|||||||
export const LISTENER_METADATA = 'LISTENER_METADATA';
|
export const LISTENER_METADATA = 'LISTENER_METADATA';
|
||||||
|
|
||||||
export const PARAM_ARGS_METADATA = ROUTE_ARGS_METADATA;
|
export const PARAM_ARGS_METADATA = ROUTE_ARGS_METADATA;
|
||||||
|
|
||||||
|
export const TELEGRAF_STAGE = 'TelegrafStage';
|
||||||
|
Loading…
Reference in New Issue
Block a user