mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-03-28 04:13:44 +03:00
refactor(module options): some changes
This commit is contained in:
parent
fb067b5174
commit
aa2af992b0
@ -10,7 +10,7 @@ import { Handler } from './Handler'
|
||||
import { Bot } from './Bot'
|
||||
import { TelegramActionHandler } from './decorators/TelegramActionHandler'
|
||||
import { TokenInjectionToken } from './TokenInjectionToken'
|
||||
import { TelegramModuleOptionsFactory } from './TelegramModuleOptionsFactory'
|
||||
import { TelegrafOptionsFactory } from './interfaces'
|
||||
import { InvalidConfigurationException } from './InvalidConfigurationException'
|
||||
|
||||
@Injectable()
|
||||
@ -20,7 +20,7 @@ export class TelegramBot {
|
||||
private ref: ModuleRef
|
||||
|
||||
public constructor(
|
||||
@Inject(TokenInjectionToken) factory: TelegramModuleOptionsFactory,
|
||||
@Inject(TokenInjectionToken) factory: TelegrafOptionsFactory,
|
||||
) {
|
||||
const { token, sitePublicUrl } = factory.createOptions()
|
||||
|
||||
|
@ -2,14 +2,14 @@ import { Injectable, Inject } from '@nestjs/common'
|
||||
const Telegram = require('telegraf/telegram')
|
||||
|
||||
import { TokenInjectionToken } from './TokenInjectionToken'
|
||||
import { TelegramModuleOptionsFactory } from './TelegramModuleOptionsFactory'
|
||||
import { TelegrafOptionsFactory } from './interfaces'
|
||||
|
||||
@Injectable()
|
||||
export class TelegramClient {
|
||||
private telegram: any
|
||||
|
||||
public constructor(
|
||||
@Inject(TokenInjectionToken) factory: TelegramModuleOptionsFactory,
|
||||
@Inject(TokenInjectionToken) factory: TelegrafOptionsFactory,
|
||||
) {
|
||||
const { token } = factory.createOptions()
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
export interface TelegramModuleOptions {
|
||||
token: string
|
||||
sitePublicUrl?: string
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
import { TelegramModuleOptions } from './TelegramModuleOptions'
|
||||
|
||||
export interface TelegramModuleOptionsFactory {
|
||||
createOptions(): TelegramModuleOptions
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
export { TelegramModule } from './telegram.module'
|
||||
export * from './telegraf.module'
|
||||
export * from './interfaces'
|
||||
|
||||
export { TelegramBot } from './TelegramBot'
|
||||
export { TelegramClient } from './TelegramClient'
|
||||
|
||||
export { TelegramModuleOptionsFactory } from './TelegramModuleOptionsFactory'
|
||||
export { TelegramModuleOptions } from './TelegramModuleOptions'
|
||||
|
||||
export { PipeContext } from './decorators/PipeContext'
|
||||
export { TelegramActionHandler } from './decorators/TelegramActionHandler'
|
||||
export { TelegramCatch } from './decorators/TelegramCatch'
|
||||
|
1
lib/interfaces/index.ts
Normal file
1
lib/interfaces/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './telegraf-options.interface'
|
16
lib/interfaces/telegraf-options.interface.ts
Normal file
16
lib/interfaces/telegraf-options.interface.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { ModuleMetadata, Type } from '@nestjs/common/interfaces'
|
||||
|
||||
export interface TelegrafModuleOptions {
|
||||
token: string
|
||||
sitePublicUrl?: string
|
||||
}
|
||||
|
||||
export interface TelegrafOptionsFactory {
|
||||
createOptions(): TelegrafModuleOptions
|
||||
}
|
||||
|
||||
export interface TelegrafModuleAsyncOptions
|
||||
extends Pick<ModuleMetadata, 'imports'> {
|
||||
useClass?: Type<TelegrafOptionsFactory>
|
||||
inject?: any[]
|
||||
}
|
@ -4,27 +4,20 @@ import {
|
||||
NestModule,
|
||||
DynamicModule,
|
||||
} from '@nestjs/common'
|
||||
import { ModuleMetadata, Type } from '@nestjs/common/interfaces'
|
||||
|
||||
import { TelegramBot } from './TelegramBot'
|
||||
import { TelegramModuleOptionsFactory } from './TelegramModuleOptionsFactory'
|
||||
import { TelegrafModuleAsyncOptions } from './interfaces'
|
||||
import { TokenInjectionToken } from './TokenInjectionToken'
|
||||
import { TelegramClient } from './TelegramClient'
|
||||
|
||||
interface TelegramFactory extends Pick<ModuleMetadata, 'imports'> {
|
||||
useClass?: Type<TelegramModuleOptionsFactory>
|
||||
inject?: any[]
|
||||
}
|
||||
|
||||
@Module({})
|
||||
export class TelegramModule implements NestModule {
|
||||
export class TelegrafModule implements NestModule {
|
||||
public configure(consumer: MiddlewareConsumer) {
|
||||
// pass
|
||||
}
|
||||
|
||||
static fromFactory(factory: TelegramFactory): DynamicModule {
|
||||
static fromFactory(factory: TelegrafModuleAsyncOptions): DynamicModule {
|
||||
return {
|
||||
module: TelegramModule,
|
||||
module: TelegrafModule,
|
||||
providers: [
|
||||
TelegramBot,
|
||||
TelegramClient,
|
Loading…
Reference in New Issue
Block a user