Skip to content

Commit

Permalink
catch telegram bot api errors
Browse files Browse the repository at this point in the history
  • Loading branch information
0x467 committed Jun 26, 2024
1 parent 6897cca commit a94cad7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/utils/create-bot-factory.util.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Telegraf } from 'telegraf';
import { TelegrafModuleOptions } from '../interfaces';
import { Logger } from '@nestjs/common';

export async function createBotFactory(
options: TelegrafModuleOptions,
): Promise<Telegraf<any>> {
const bot = new Telegraf<any>(options.token, options.options);

bot.use(...(options.middlewares ?? []));
bot.catch((err, ctx) =>
Logger.error(err, `Telegraf: ${ctx.botInfo.username}`),
);

if (options.launchOptions !== false) {
bot.launch(options.launchOptions);
Expand Down

0 comments on commit a94cad7

Please sign in to comment.