mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-09-23 09:49:06 +03:00
refactor(): extract bot instace factory
This commit is contained in:
13
lib/utils/create-bot-factory.util.ts
Normal file
13
lib/utils/create-bot-factory.util.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Telegraf } from 'telegraf';
|
||||
import { TelegrafModuleOptions } from '../interfaces';
|
||||
|
||||
export async function createBotFactory(
|
||||
options: TelegrafModuleOptions,
|
||||
): Promise<Telegraf<never>> {
|
||||
const bot = new Telegraf<never>(options.token, options.options);
|
||||
|
||||
bot.use(...(options.middlewares ?? []));
|
||||
await bot.launch(options.launchOptions);
|
||||
|
||||
return bot;
|
||||
}
|
Reference in New Issue
Block a user