aboutsummaryrefslogtreecommitdiffstats
path: root/src/middleware.ts
blob: 9aa0775c5c5657757f213d208715fe69391a1f80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { Context } from "telegraf";
import { getPermittedUsers } from "./db";

const auth = async (ctx: Context, next: () => Promise<void>): Promise<void> => {
  const userId = ctx.message?.from.id;

  const tgUsers = await getPermittedUsers();
  const tgUserIds = tgUsers.map(u => u.id);

  if (!userId || !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 = {};