From 78fe1d98867e9099869f273933d9d6cc46156fb5 Mon Sep 17 00:00:00 2001 From: Aleksandr Bukhalo Date: Sun, 12 Jan 2020 15:23:19 +0300 Subject: [PATCH] feat(telegram-service): extend TelegramClient class for expose all functions --- lib/telegraf-telegram.service.ts | 36 +++++++------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/lib/telegraf-telegram.service.ts b/lib/telegraf-telegram.service.ts index 5b672d7..8b262b7 100644 --- a/lib/telegraf-telegram.service.ts +++ b/lib/telegraf-telegram.service.ts @@ -1,33 +1,13 @@ -import { Injectable, Inject } from '@nestjs/common' -const Telegram = require('telegraf/telegram') +import { Injectable, Inject } from '@nestjs/common'; +const Telegram = require('telegraf/telegram'); +import { Telegram as TelegramClient } from 'telegraf'; -import { TokenInjectionToken } from './telegraf.constants' -import { TelegrafOptionsFactory } from './interfaces' +import { TELEGRAF_MODULE_OPTIONS } from './telegraf.constants'; +import { TelegrafModuleOptions } from './interfaces'; @Injectable() -export class TelegrafTelegramService { - private telegram: any - - public constructor( - @Inject(TokenInjectionToken) options: TelegrafOptionsFactory, - ) { - const { token } = options.createTelegrafOptions() - this.telegram = new Telegram(token) - } - - public async sendMessage( - chatId: string | number, - text: string, - ): Promise { - await this.telegram.sendMessage(chatId, text) - } - - public async sendMarkdown( - chatId: string | number, - markdown: string, - ): Promise { - await this.telegram.sendMessage(chatId, markdown, { - parse_mode: 'Markdown', - }) +export class TelegrafTelegramService extends TelegramClient { + constructor(@Inject(TELEGRAF_MODULE_OPTIONS) options: TelegrafModuleOptions) { + super(options.token, {}); } }