2020-12-29 22:41:06 +03:00
|
|
|
import { Provider } from '@nestjs/common';
|
2020-12-29 22:48:19 +03:00
|
|
|
import { Telegraf } from 'telegraf';
|
2020-12-29 22:41:06 +03:00
|
|
|
import { TELEGRAF_MODULE_OPTIONS } from './telegraf.constants';
|
|
|
|
import { TelegrafModuleOptions } from './interfaces';
|
|
|
|
|
|
|
|
export const TelegrafProvider = {
|
|
|
|
provide: Telegraf,
|
|
|
|
useFactory: (options: TelegrafModuleOptions) => {
|
|
|
|
const telegraf = new Telegraf(options.token, options.options);
|
2020-12-30 01:49:09 +03:00
|
|
|
telegraf.use(...options.middlewares);
|
2020-12-29 22:41:06 +03:00
|
|
|
return telegraf;
|
|
|
|
},
|
2020-12-30 01:49:09 +03:00
|
|
|
inject: [TELEGRAF_MODULE_OPTIONS],
|
2020-12-29 22:41:06 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
export function createProviders(options: TelegrafModuleOptions): Provider[] {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
provide: TELEGRAF_MODULE_OPTIONS,
|
|
|
|
useValue: options,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|