mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-09-23 09:49:06 +03:00
feat: add launch options
This commit is contained in:
@@ -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