diff options
| author | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-04-19 14:51:34 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-04-19 14:51:34 +0300 |
| commit | 7f3a70c396b498a8b10553d11cf78c3ea9a872b1 (patch) | |
| tree | 29e8063a080b1bb83bd92a5cc8ff8f5365b186e7 /src/tg.ts | |
| parent | 2725e84e199e1d0b5e6ce01e405c035481e49c0d (diff) | |
Should be ready now
Diffstat (limited to 'src/tg.ts')
| -rw-r--r-- | src/tg.ts | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -1,12 +1,12 @@ import { Telegraf } from "telegraf"; import config from "./config"; -import { addActiveChat, removeActiveChat } from "./db"; +import { addActiveChat, getActiveChats, 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.use(tgMiddleware.tgAuth); bot.command("/start", async (ctx) => { await addActiveChat(ctx.chat.id); @@ -18,4 +18,13 @@ bot.command("/stop", async (ctx) => { await ctx.reply("HommaBot pysäytetty!"); }); -export { bot }; +const broadcastMessage = async (msg: string): Promise<void> => { + const activeChats = await getActiveChats(); + const chatIds = activeChats.map(c => c.id); + + await Promise.all(chatIds.map(async chatId => + bot.telegram.sendMessage(chatId, msg), + )); +}; + +export { bot, broadcastMessage }; |
