Skip to content

Commit

Permalink
Added OnModuleInit
Browse files Browse the repository at this point in the history
  • Loading branch information
ashkuc committed Oct 16, 2022
1 parent 768e9e5 commit 26af3d8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/telegram/service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<Context<Update>>;

private readonly ttl: number;
Expand All @@ -26,11 +32,9 @@ export class TelegramService {
) {
this.ttl = this.configService.get<CacheConfig>('cache').ttl;
this.adminAddresses = this.configService.get('adminAddresses');

this.startBot();
}

async startBot(): Promise<void> {
async onModuleInit(): Promise<void> {
this.bot = new Telegraf(this.configService.get('telegramToken'));

this.bot.on('message', this.onMessage.bind(this));
Expand Down

0 comments on commit 26af3d8

Please sign in to comment.