aboutsummaryrefslogtreecommitdiffstats
path: root/src/tg.ts
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@valuemotive.com>2021-04-18 20:10:34 +0300
committerJan Tuomi <jan.tuomi@valuemotive.com>2021-04-18 20:10:34 +0300
commitcf2e3c99ded0f48bd565858aedc7f10a0d932a61 (patch)
tree699e9c6b78456474b4b0e680a15a6b1bc49aab08 /src/tg.ts
parentbaacc7676c688cd2728033e9051208d655255ee5 (diff)
Add db connection
Diffstat (limited to 'src/tg.ts')
-rw-r--r--src/tg.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/tg.ts b/src/tg.ts
new file mode 100644
index 0000000..da8d02d
--- /dev/null
+++ b/src/tg.ts
@@ -0,0 +1,21 @@
+import { Telegraf } from "telegraf";
+import config from "./config";
+import { addActiveChat, removeActiveChat } from "./db";
+import { tgMiddleware } from "./middleware";
+
+console.log(`Setting up Telegram bot with token ${config.tgBotToken}`);
+const bot = new Telegraf(config.tgBotToken);
+
+bot.use(tgMiddleware.auth);
+
+bot.command("/start", async (ctx) => {
+ await addActiveChat(ctx.chat.id);
+ await ctx.reply("HommaBot startattu. Uusia hommapäivityksiä viikon välein.");
+});
+
+bot.command("/stop", async (ctx) => {
+ await removeActiveChat(ctx.chat.id);
+ await ctx.reply("HommaBot pysäytetty!");
+});
+
+export { bot };