mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-01-11 22:51:06 +03:00
feat(telegram-service): extend TelegramClient class for expose all functions
This commit is contained in:
parent
c25d71cf7d
commit
78fe1d9886
@ -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<void> {
|
||||
await this.telegram.sendMessage(chatId, text)
|
||||
}
|
||||
|
||||
public async sendMarkdown(
|
||||
chatId: string | number,
|
||||
markdown: string,
|
||||
): Promise<void> {
|
||||
await this.telegram.sendMessage(chatId, markdown, {
|
||||
parse_mode: 'Markdown',
|
||||
})
|
||||
export class TelegrafTelegramService extends TelegramClient {
|
||||
constructor(@Inject(TELEGRAF_MODULE_OPTIONS) options: TelegrafModuleOptions) {
|
||||
super(options.token, {});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user