2019-05-11 20:55:15 +03:00
|
|
|
import { Injectable, Inject } from '@nestjs/common'
|
2019-05-11 21:10:14 +03:00
|
|
|
const Telegram = require('telegraf/telegram')
|
2019-05-11 20:55:15 +03:00
|
|
|
|
|
|
|
import { TokenInjectionToken } from './TokenInjectionToken'
|
2020-01-12 01:15:32 +03:00
|
|
|
import { TelegrafOptionsFactory } from './interfaces'
|
2019-05-11 20:55:15 +03:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class TelegramClient {
|
|
|
|
private telegram: any
|
|
|
|
|
|
|
|
public constructor(
|
2020-01-12 01:15:32 +03:00
|
|
|
@Inject(TokenInjectionToken) factory: TelegrafOptionsFactory,
|
2019-05-11 20:55:15 +03:00
|
|
|
) {
|
|
|
|
const { token } = factory.createOptions()
|
|
|
|
|
|
|
|
this.telegram = new Telegram(token)
|
|
|
|
}
|
|
|
|
|
|
|
|
public async sendMessage(
|
|
|
|
chatId: string | number,
|
|
|
|
text: string,
|
|
|
|
): Promise<void> {
|
|
|
|
await this.telegram.sendMessage(chatId, text)
|
|
|
|
}
|
2019-07-18 14:32:33 +03:00
|
|
|
|
|
|
|
public async sendMarkdown(
|
|
|
|
chatId: string | number,
|
|
|
|
markdown: string,
|
|
|
|
): Promise<void> {
|
|
|
|
await this.telegram.sendMessage(chatId, markdown, {
|
|
|
|
parse_mode: 'Markdown',
|
|
|
|
})
|
|
|
|
}
|
2019-05-11 20:55:15 +03:00
|
|
|
}
|