mirror of
				https://github.com/Maks1mS/nestjs-telegraf.git
				synced 2025-10-31 14:01:22 +03:00 
			
		
		
		
	feat: add launch options
This commit is contained in:
		
							
								
								
									
										18
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								README.md
									
									
									
									
									
								
							| @@ -158,9 +158,23 @@ const telegrafProvider = app.get('TelegrafProvider'); | ||||
| Now you can connect middleware: | ||||
| ```typescript | ||||
| app.use(telegrafService.webhookCallback('/secret-path')); | ||||
| ``` | ||||
|  | ||||
| // set up a webhook immediately if necessary | ||||
| telegrafService.telegram.setWebhook('https://server.tld:3000/secret-path'); | ||||
| The last step is to specify launchOptions in `forRoot` method: | ||||
| ```typescript | ||||
| TelegrafModule.forRootAsync({ | ||||
|   imports: [ConfigModule], | ||||
|   useFactory: async (configService: ConfigService) => ({ | ||||
|     token: configService.get<string>('TELEGRAM_BOT_TOKEN'), | ||||
|     launchOptions: { | ||||
|       webhook: { | ||||
|         domain: 'domain.tld', | ||||
|         hookPath: '/secret-path', | ||||
|       } | ||||
|     } | ||||
|   }), | ||||
|   inject: [ConfigService], | ||||
| }); | ||||
| ``` | ||||
|  | ||||
| ## Support | ||||
|   | ||||
| @@ -1,9 +1,17 @@ | ||||
| import { ModuleMetadata, Type } from '@nestjs/common/interfaces'; | ||||
| import { TelegrafOptions } from 'telegraf'; | ||||
| import { | ||||
|   TelegrafOptions, | ||||
|   LaunchPollingOptions, | ||||
|   LaunchWebhookOptions, | ||||
| } from 'telegraf'; | ||||
|  | ||||
| export interface TelegrafModuleOptions { | ||||
|   token: string; | ||||
|   options?: TelegrafOptions; | ||||
|   launchOptions?: { | ||||
|     polling?: LaunchPollingOptions; | ||||
|     webhook?: LaunchWebhookOptions; | ||||
|   }; | ||||
| } | ||||
|  | ||||
| export interface TelegrafOptionsFactory { | ||||
|   | ||||
| @@ -15,16 +15,19 @@ export class TelegrafProvider<TContext extends ContextMessageUpdate> | ||||
|   extends Telegraf<TContext> | ||||
|   implements OnApplicationBootstrap, OnApplicationShutdown { | ||||
|   private logger = new Logger('Telegraf'); | ||||
|   private launchOptions; | ||||
|  | ||||
|   constructor(@Inject(TELEGRAF_MODULE_OPTIONS) options: TelegrafModuleOptions) { | ||||
|     super(options.token, options.options); | ||||
|     this.launchOptions = options.launchOptions; | ||||
|   } | ||||
|  | ||||
|   onApplicationBootstrap() { | ||||
|     this.catch((e) => { | ||||
|       this.logger.error(e); | ||||
|     }); | ||||
|     this.startPolling(); | ||||
|  | ||||
|     this.launch(this.launchOptions); | ||||
|   } | ||||
|  | ||||
|   async onApplicationShutdown(signal?: string) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user