Skip to content

gramiojs/broadcast

Repository files navigation

@gramio/broadcast

npm npm downloads JSR JSR Score

Simple wrapper for jobify (BullMQ) to make broadcast easier. Automatically handles rate limits and ignore user blocks. Provide simple API for pre-defined broadcasts.

This implementation is ready for production use because, thanks to Redis, it won't lose planned users during reloads and will send notifications to all of them.

import { Bot, InlineKeyboard } from "gramio";
import Redis from "ioredis";
import { initJobify } from "jobify";
import { Broadcast } from "@gramio/broadcast";

const redis = new Redis({
    maxRetriesPerRequest: null,
});

const bot = new Bot(process.env.BOT_TOKEN as string);

const broadcast = new Broadcast(redis).type("test", (chatId: number) =>
    bot.api.sendMessage({
        chat_id: chatId,
        text: "test",
    })
);

console.log("prepared to start");

const chatIds = [617580375];

await broadcast.start(
    "test",
    chatIds.map((x) => [x])
);

// graceful shutdown
async function gracefulShutdown() {
    console.log(`Process ${process.pid} go to sleep`);

    await broadcast.job.queue.close();

    console.log("closed");
    process.exit(0);
}

process.on("SIGTERM", gracefulShutdown);

process.on("SIGINT", gracefulShutdown);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published