From bad65204c481b54e3ee12bf06b46fe01726b1cc9 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 25 Aug 2025 11:31:53 +0300 Subject: [PATCH] refactor(bot): streamline bot middleware and improve key generator function - Removed unused session middleware and sequentialize function from the bot's error boundary. - Simplified the key generator function for rate limiting by condensing its implementation. - Enhanced overall code clarity and maintainability in the bot's configuration. --- apps/bot/src/bot/index.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/apps/bot/src/bot/index.ts b/apps/bot/src/bot/index.ts index 2c82d3b..06f1b7e 100644 --- a/apps/bot/src/bot/index.ts +++ b/apps/bot/src/bot/index.ts @@ -4,18 +4,15 @@ import { unhandledFeature } from './features/unhandled'; import { errorHandler } from './handlers/errors'; import { i18n } from './i18n'; import * as middlewares from './middlewares'; -import { session } from './middlewares'; import { setCommands } from './settings/commands'; import { setInfo } from './settings/info'; import { env } from '@/config/env'; import { logger } from '@/utils/logger'; import { getRedisInstance } from '@/utils/redis'; -import { getSessionKey } from '@/utils/session'; import { autoChatAction } from '@grammyjs/auto-chat-action'; import { conversations } from '@grammyjs/conversations'; import { hydrate } from '@grammyjs/hydrate'; import { limit } from '@grammyjs/ratelimiter'; -import { sequentialize } from '@grammyjs/runner'; import { Bot } from 'grammy'; type Parameters_ = { @@ -31,9 +28,7 @@ export function createBot({ token }: Parameters_) { bot.use( limit({ - keyGenerator: (ctx) => { - return ctx.from?.id.toString(); - }, + keyGenerator: (ctx) => ctx.from?.id.toString(), limit: env.RATE_LIMIT, onLimitExceeded: async (ctx) => { await ctx.reply(ctx.t('err-limit-exceeded')); @@ -47,7 +42,6 @@ export function createBot({ token }: Parameters_) { context.logger = logger.child({ update_id: context.update.update_id, }); - await next(); }); @@ -58,9 +52,6 @@ export function createBot({ token }: Parameters_) { const protectedBot = bot.errorBoundary(errorHandler); - protectedBot.use(sequentialize(getSessionKey)); - protectedBot.use(session()); - protectedBot.use(middlewares.updateLogger()); protectedBot.use(autoChatAction(bot.api)); protectedBot.use(hydrate());