From 6f416a05206ba28030a2ed3e0edd00192cb11bcd Mon Sep 17 00:00:00 2001 From: AntoXa PRO Date: Fri, 29 Nov 2024 12:34:11 +0300 Subject: [PATCH] add test handlers --- src/errors/index.ts | 3 +++ src/handlers/index.ts | 1 + src/handlers/test.ts | 5 +++++ src/index.ts | 9 +++++---- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 src/errors/index.ts create mode 100644 src/handlers/index.ts create mode 100644 src/handlers/test.ts diff --git a/src/errors/index.ts b/src/errors/index.ts new file mode 100644 index 0000000..eee5edf --- /dev/null +++ b/src/errors/index.ts @@ -0,0 +1,3 @@ +export const errorHandler = (e: any) => { + console.log('Error Handler:', e.message) +} diff --git a/src/handlers/index.ts b/src/handlers/index.ts new file mode 100644 index 0000000..ac3f46b --- /dev/null +++ b/src/handlers/index.ts @@ -0,0 +1 @@ +export * from './test' diff --git a/src/handlers/test.ts b/src/handlers/test.ts new file mode 100644 index 0000000..3b6b1b0 --- /dev/null +++ b/src/handlers/test.ts @@ -0,0 +1,5 @@ +import { Context } from 'telegraf' + +export const testHandler = (ctx: Context) => { + console.log('Test handler:', ctx) +} diff --git a/src/index.ts b/src/index.ts index 3be39a7..a795513 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,9 @@ // Импорт сторонних библиотек. import * as dotenv from 'dotenv' import { Telegraf } from 'telegraf' +import { errorHandler } from './errors' +import { testHandler } from './handlers' + // Главная функция приложения (Точка входа). const main = () => { @@ -17,15 +20,13 @@ const main = () => { const bot = new Telegraf(token) // Обработчик команды /start - bot.start(async ctx => { - await ctx.reply('Привет!') - }) + bot.start(testHandler) // Запуск бота bot.launch() } catch (e) { // Обработка ошибок. - console.log('Ошибка:', e) + errorHandler(e) } }