mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-27 08:18:08 +03:00
38 lines
978 B
TypeScript
38 lines
978 B
TypeScript
import {
|
|
Injectable,
|
|
Inject,
|
|
OnApplicationBootstrap,
|
|
Logger,
|
|
OnApplicationShutdown,
|
|
} from '@nestjs/common';
|
|
import { Telegraf } from 'telegraf';
|
|
import { Context, TelegrafModuleOptions } from './interfaces';
|
|
import { TELEGRAF_MODULE_OPTIONS } from './telegraf.constants';
|
|
|
|
@Injectable()
|
|
export class TelegrafProvider extends Telegraf<Context>
|
|
implements OnApplicationBootstrap, OnApplicationShutdown {
|
|
private logger = new Logger('Telegraf');
|
|
private readonly launchOptions;
|
|
|
|
constructor(@Inject(TELEGRAF_MODULE_OPTIONS) options: TelegrafModuleOptions) {
|
|
super(options.token, options.options);
|
|
this.launchOptions = options.launchOptions;
|
|
}
|
|
|
|
async onApplicationBootstrap() {
|
|
this.catch((err, ctx: Context) => {
|
|
this.logger.error(
|
|
`Encountered an error for ${ctx.updateType} update type`,
|
|
err,
|
|
);
|
|
});
|
|
|
|
await this.launch(this.launchOptions);
|
|
}
|
|
|
|
async onApplicationShutdown() {
|
|
await this.stop();
|
|
}
|
|
}
|