nestjs-telegraf/lib/TelegramClient.ts
2020-01-12 01:36:53 +03:00

35 lines
828 B
TypeScript

import { Injectable, Inject } from '@nestjs/common'
const Telegram = require('telegraf/telegram')
import { TokenInjectionToken } from './TokenInjectionToken'
import { TelegrafOptionsFactory } from './interfaces'
@Injectable()
export class TelegramClient {
private telegram: any
public constructor(
@Inject(TokenInjectionToken) factory: TelegrafOptionsFactory,
) {
const { token } = factory.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',
})
}
}