Add options to telegraf instance

This commit is contained in:
Alexey Lepskii 2020-02-29 12:38:32 +03:00
parent 9e02f3aebf
commit ade4088551

View File

@ -1,17 +1,16 @@
import { Injectable, Inject, Logger } from '@nestjs/common' import { Inject, Injectable, Logger } from '@nestjs/common'
import { ModuleRef } from '@nestjs/core' import { ModuleRef } from '@nestjs/core'
import Telegraf, { ContextMessageUpdate } from 'telegraf'
import { flatten, head } from 'lodash' import { flatten, head } from 'lodash'
import Telegraf, { ContextMessageUpdate } from 'telegraf'
import { TelegramCatch, TelegramActionHandler } from './decorators' import { TelegramActionHandler, TelegramCatch } from './decorators'
import { TokenInjectionToken } from './telegraf.constants' import { InvalidConfigurationException } from './exeptions'
import { import {
ContextTransformer,
Handler,
TelegrafOptionsFactory, TelegrafOptionsFactory,
TelegramErrorHandler, TelegramErrorHandler,
Handler,
ContextTransformer,
} from './interfaces' } from './interfaces'
import { InvalidConfigurationException } from './exeptions' import { TokenInjectionToken } from './telegraf.constants'
@Injectable() @Injectable()
export class TelegrafService { export class TelegrafService {
@ -23,9 +22,13 @@ export class TelegrafService {
public constructor( public constructor(
@Inject(TokenInjectionToken) options: TelegrafOptionsFactory @Inject(TokenInjectionToken) options: TelegrafOptionsFactory
) { ) {
const { token, sitePublicUrl } = options.createTelegrafOptions() const {
token,
sitePublicUrl,
telegrafOptions,
} = options.createTelegrafOptions()
this.sitePublicUrl = sitePublicUrl this.sitePublicUrl = sitePublicUrl
this.bot = new Telegraf(token) this.bot = new Telegraf(token, telegrafOptions)
} }
public init(ref: ModuleRef, devMode: boolean = false) { public init(ref: ModuleRef, devMode: boolean = false) {