Telegraf Webhook Multiple Bots

 avatar
rain
javascript
a year ago
621 B
11
Indexable
Never
import "dotenv/config";

import express from "express";
import { Telegraf } from "telegraf";

const env = process.env;

const bot1 = new Telegraf(env.BOT_TOKEN_1);
const bot2 = new Telegraf(env.BOT_TOKEN_2);

const server = express();
const bots = [bot1, bot2];
const totalBots = bots.length;
const port = env.PORT || 8080;
const domain = env.WEBHOOK_URL; // for example: https://telegraf-webhook.username.repl.co

for (let i = 0; i < totalBots; i++) {
  server.use(
    await bots[i].createWebhook({
      domain,
      path: "/" + i,
    })
  );
}
server.listen(port, () => console.log(`Server listening on ${port}`));