mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 15:04:38 +03:00
26 lines
707 B
TypeScript
26 lines
707 B
TypeScript
import { Provider } from '@nestjs/common';
|
|
import { Telegraf } from 'telegraf';
|
|
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);
|
|
if (options.middlewares?.length > 0) {
|
|
telegraf.use(...options.middlewares);
|
|
}
|
|
return telegraf;
|
|
},
|
|
inject: [TELEGRAF_MODULE_OPTIONS],
|
|
};
|
|
|
|
export function createProviders(options: TelegrafModuleOptions): Provider[] {
|
|
return [
|
|
{
|
|
provide: TELEGRAF_MODULE_OPTIONS,
|
|
useValue: options,
|
|
},
|
|
];
|
|
}
|