From 26af3d89f9828abc3916a26e9b70877ae0d0f608 Mon Sep 17 00:00:00 2001 From: ashkuc Date: Sun, 16 Oct 2022 21:52:21 +0200 Subject: [PATCH] Added OnModuleInit --- src/telegram/service.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/telegram/service.ts b/src/telegram/service.ts index 152d9ca..9cfc78b 100644 --- a/src/telegram/service.ts +++ b/src/telegram/service.ts @@ -1,4 +1,10 @@ -import { CACHE_MANAGER, Inject, Injectable, Logger } from '@nestjs/common'; +import { + CACHE_MANAGER, + Inject, + Injectable, + Logger, + OnModuleInit, +} from '@nestjs/common'; import { Cache } from 'cache-manager'; import { ConfigService } from '@nestjs/config'; import { Telegraf, Context } from 'telegraf'; @@ -9,7 +15,7 @@ import { CacheConfig } from '../config/cache.config'; import { formatDuration } from './utils'; @Injectable() -export class TelegramService { +export class TelegramService implements OnModuleInit { private bot: Telegraf>; private readonly ttl: number; @@ -26,11 +32,9 @@ export class TelegramService { ) { this.ttl = this.configService.get('cache').ttl; this.adminAddresses = this.configService.get('adminAddresses'); - - this.startBot(); } - async startBot(): Promise { + async onModuleInit(): Promise { this.bot = new Telegraf(this.configService.get('telegramToken')); this.bot.on('message', this.onMessage.bind(this));