mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-01-25 21:31:07 +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'
|
import { Injectable, Inject } from '@nestjs/common';
|
||||||
const Telegram = require('telegraf/telegram')
|
const Telegram = require('telegraf/telegram');
|
||||||
|
import { Telegram as TelegramClient } from 'telegraf';
|
||||||
|
|
||||||
import { TokenInjectionToken } from './telegraf.constants'
|
import { TELEGRAF_MODULE_OPTIONS } from './telegraf.constants';
|
||||||
import { TelegrafOptionsFactory } from './interfaces'
|
import { TelegrafModuleOptions } from './interfaces';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TelegrafTelegramService {
|
export class TelegrafTelegramService extends TelegramClient {
|
||||||
private telegram: any
|
constructor(@Inject(TELEGRAF_MODULE_OPTIONS) options: TelegrafModuleOptions) {
|
||||||
|
super(options.token, {});
|
||||||
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',
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user