2019-02-28 11:29:26 +03:00
|
|
|
import {
|
|
|
|
MiddlewareConsumer,
|
|
|
|
Module,
|
|
|
|
NestModule,
|
|
|
|
DynamicModule,
|
|
|
|
} from '@nestjs/common'
|
|
|
|
import { ModuleMetadata, Type } from '@nestjs/common/interfaces'
|
2019-05-11 20:55:15 +03:00
|
|
|
|
2019-02-28 11:29:26 +03:00
|
|
|
import { TelegramBot } from './TelegramBot'
|
|
|
|
import { TelegramModuleOptionsFactory } from './TelegramModuleOptionsFactory'
|
|
|
|
import { TokenInjectionToken } from './TokenInjectionToken'
|
2019-05-11 20:55:15 +03:00
|
|
|
import { TelegramClient } from './TelegramClient'
|
2019-02-28 11:29:26 +03:00
|
|
|
|
|
|
|
interface TelegramFactory extends Pick<ModuleMetadata, 'imports'> {
|
|
|
|
useClass?: Type<TelegramModuleOptionsFactory>
|
|
|
|
inject?: any[]
|
|
|
|
}
|
|
|
|
|
|
|
|
@Module({})
|
|
|
|
export class TelegramModule implements NestModule {
|
|
|
|
public configure(consumer: MiddlewareConsumer) {
|
|
|
|
// pass
|
|
|
|
}
|
|
|
|
|
|
|
|
static fromFactory(factory: TelegramFactory): DynamicModule {
|
|
|
|
return {
|
|
|
|
module: TelegramModule,
|
|
|
|
providers: [
|
|
|
|
TelegramBot,
|
2019-05-11 20:55:15 +03:00
|
|
|
TelegramClient,
|
2019-02-28 11:29:26 +03:00
|
|
|
{
|
|
|
|
provide: TokenInjectionToken,
|
|
|
|
useClass: factory.useClass,
|
|
|
|
},
|
|
|
|
],
|
2019-05-11 21:10:14 +03:00
|
|
|
exports: [TelegramBot, TelegramClient],
|
2019-02-28 11:29:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|