mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-25 15:34:38 +03:00
23 lines
623 B
TypeScript
23 lines
623 B
TypeScript
|
import { Provider } from '@nestjs/common';
|
||
|
import { session, Telegraf } from 'telegraf';
|
||
|
import { TELEGRAF_MODULE_OPTIONS } from './telegraf.constants';
|
||
|
import { TelegrafModuleOptions } from './interfaces';
|
||
|
|
||
|
export const TelegrafProvider = {
|
||
|
provide: Telegraf,
|
||
|
inject: [TELEGRAF_MODULE_OPTIONS],
|
||
|
useFactory: (options: TelegrafModuleOptions) => {
|
||
|
const telegraf = new Telegraf(options.token, options.options);
|
||
|
return telegraf;
|
||
|
},
|
||
|
};
|
||
|
|
||
|
export function createProviders(options: TelegrafModuleOptions): Provider[] {
|
||
|
return [
|
||
|
{
|
||
|
provide: TELEGRAF_MODULE_OPTIONS,
|
||
|
useValue: options,
|
||
|
},
|
||
|
];
|
||
|
}
|