mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 23:14:39 +03:00
26 lines
646 B
TypeScript
26 lines
646 B
TypeScript
import { Injectable, Inject } from '@nestjs/common'
|
|
import Telegram from 'telegraf/telegram'
|
|
|
|
import { TokenInjectionToken } from './TokenInjectionToken'
|
|
import { TelegramModuleOptionsFactory } from './TelegramModuleOptionsFactory'
|
|
|
|
@Injectable()
|
|
export class TelegramClient {
|
|
private telegram: any
|
|
|
|
public constructor(
|
|
@Inject(TokenInjectionToken) factory: TelegramModuleOptionsFactory,
|
|
) {
|
|
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)
|
|
}
|
|
}
|