2020-03-19 16:21:35 +03:00
|
|
|
import {
|
|
|
|
Injectable,
|
|
|
|
Inject,
|
|
|
|
OnApplicationBootstrap,
|
|
|
|
Logger,
|
2020-03-19 18:20:07 +03:00
|
|
|
OnApplicationShutdown,
|
2020-03-19 16:21:35 +03:00
|
|
|
} from '@nestjs/common';
|
|
|
|
import Telegraf, { ContextMessageUpdate } from 'telegraf';
|
|
|
|
import { TELEGRAF_MODULE_OPTIONS } from './telegraf.constants';
|
|
|
|
import { TelegrafModuleOptions } from './interfaces';
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
// @ts-ignore
|
|
|
|
export class TelegrafProvider<TContext extends ContextMessageUpdate>
|
|
|
|
extends Telegraf<TContext>
|
2020-03-19 18:20:07 +03:00
|
|
|
implements OnApplicationBootstrap, OnApplicationShutdown {
|
2020-03-19 16:21:35 +03:00
|
|
|
private logger = new Logger('Telegraf');
|
|
|
|
|
|
|
|
constructor(@Inject(TELEGRAF_MODULE_OPTIONS) options: TelegrafModuleOptions) {
|
|
|
|
super(options.token, options.options);
|
|
|
|
}
|
|
|
|
|
|
|
|
onApplicationBootstrap() {
|
2020-03-28 11:00:33 +03:00
|
|
|
this.catch((e) => {
|
2020-03-19 16:21:35 +03:00
|
|
|
this.logger.error(e);
|
|
|
|
});
|
|
|
|
this.startPolling();
|
|
|
|
}
|
2020-03-19 18:20:07 +03:00
|
|
|
|
|
|
|
async onApplicationShutdown(signal?: string) {
|
|
|
|
await this.stop();
|
|
|
|
}
|
2020-03-19 16:21:35 +03:00
|
|
|
}
|