From baacc7676c688cd2728033e9051208d655255ee5 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sun, 18 Apr 2021 18:07:54 +0300 Subject: Work on tg bot --- src/middleware.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/middleware.ts') diff --git a/src/middleware.ts b/src/middleware.ts index bdc006a..e2814e0 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -1,5 +1,18 @@ -import { NextFunction, Request, Response } from "@tinyhttp/app"; +import { Context } from "telegraf"; +import config from "./config"; -export const auth = async (_req: Request, _res: Response, next: NextFunction): Promise => { - await next(); +const auth = async (ctx: Context, next: () => Promise): Promise => { + const userId = ctx.message?.from.id; + + if (!userId || !config.tgUserIds.includes(userId)) { + ctx.reply("Käyttäjälläsi ei ole oikeuksia startata HommaBottia."); + } else { + await next(); + } +}; + +export const tgMiddleware = { + auth, }; + +export const httpMiddleware = {}; -- cgit v1.3