import { MiddlewareConsumer, Module, NestModule, DynamicModule, } from '@nestjs/common' import { ModuleMetadata, Type } from '@nestjs/common/interfaces' import { TelegramBot } from './TelegramBot' import { TelegramModuleOptionsFactory } from './TelegramModuleOptionsFactory' import { TokenInjectionToken } from './TokenInjectionToken' interface TelegramFactory extends Pick { useClass?: Type inject?: any[] } @Module({}) export class TelegramModule implements NestModule { public configure(consumer: MiddlewareConsumer) { // pass } static fromFactory(factory: TelegramFactory): DynamicModule { return { module: TelegramModule, providers: [ TelegramBot, { provide: TokenInjectionToken, useClass: factory.useClass, }, ], exports: [TelegramBot], } } }