From cf2e3c99ded0f48bd565858aedc7f10a0d932a61 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sun, 18 Apr 2021 20:10:34 +0300 Subject: Add db connection --- src/index.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index 71e239f..4edfc2f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,16 +1,14 @@ import { App } from "@tinyhttp/app"; import { logger } from "@tinyhttp/logger"; -import { Telegraf } from "telegraf"; import config from "./config"; -import { tgMiddleware } from "./middleware"; +import { bot } from "./tg"; -const app = new App(); -console.log(`Setting up Telegram bot with token ${config.tgBotToken}`); -const bot = new Telegraf(config.tgBotToken); - -bot.use(tgMiddleware.auth); -bot.command("/start", (ctx) => ctx.reply("started")); -bot.command("/stop", (ctx) => ctx.reply("stopped")); +const app = new App({ + onError: (err, _req, res) => { + console.log(err); + res.status(500).send("Something bad happened"); + }, +}); app .use(logger({ @@ -19,7 +17,7 @@ app }, })) .use(bot.webhookCallback("/webhook/telegram")) - .get("/", (_, res) => { + .get("/", async (_, res) => { res.send({ service: "hommabot2 API" }); }) .post("/scheduler/trigger", (_req, res) => { -- cgit v1.3