From 412c033972744e049e70b3ecc891a19b74bf2253 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 21 Aug 2025 18:53:29 +0300 Subject: [PATCH] feat(bot): add unhandled command message and integrate unhandled feature - Introduced a new message for unhandled commands in Russian localization to improve user feedback. - Integrated the unhandled feature into the bot's middleware for better command handling. --- apps/bot/locales/ru.ftl | 1 + apps/bot/src/bot/features/unhandled.ts | 17 +++++++++++++++++ apps/bot/src/bot/index.ts | 3 +++ 3 files changed, 21 insertions(+) create mode 100644 apps/bot/src/bot/features/unhandled.ts diff --git a/apps/bot/locales/ru.ftl b/apps/bot/locales/ru.ftl index df3895d..2700c50 100644 --- a/apps/bot/locales/ru.ftl +++ b/apps/bot/locales/ru.ftl @@ -89,6 +89,7 @@ msg-share-bot = # Системные сообщения msg-cancel = ❌ Операция отменена +msg-unhandled = ❓ Неизвестная команда. Попробуйте /start # Ошибки err-generic = ⚠️ Что-то пошло не так. Попробуйте еще раз через несколько секунд diff --git a/apps/bot/src/bot/features/unhandled.ts b/apps/bot/src/bot/features/unhandled.ts new file mode 100644 index 0000000..b376890 --- /dev/null +++ b/apps/bot/src/bot/features/unhandled.ts @@ -0,0 +1,17 @@ +import { type Context } from '@/bot/context'; +import { logHandle } from '@/bot/helpers/logging'; +import { Composer } from 'grammy'; + +const composer = new Composer(); + +const feature = composer.chatType('private'); + +feature.on('message', logHandle('unhandled-message'), (ctx) => { + return ctx.reply(ctx.t('msg-unhandled')); +}); + +feature.on('callback_query', logHandle('unhandled-callback-query'), (ctx) => { + return ctx.answerCallbackQuery(); +}); + +export { composer as unhandledFeature }; diff --git a/apps/bot/src/bot/index.ts b/apps/bot/src/bot/index.ts index 7eb3b79..2c82d3b 100644 --- a/apps/bot/src/bot/index.ts +++ b/apps/bot/src/bot/index.ts @@ -1,5 +1,6 @@ import { type Context } from './context'; import * as features from './features'; +import { unhandledFeature } from './features/unhandled'; import { errorHandler } from './handlers/errors'; import { i18n } from './i18n'; import * as middlewares from './middlewares'; @@ -68,5 +69,7 @@ export function createBot({ token }: Parameters_) { protectedBot.use(feature); } + protectedBot.use(unhandledFeature); + return bot; }