@toptl/telegraf
v1.0.1
Published
Telegraf plugin for TOP.TL — auto-post bot stats & check votes
Downloads
283
Maintainers
Readme
toptl-telegraf
Telegraf plugin for TOP.TL — auto-post bot stats and check votes.
Installation
npm install toptl-telegrafQuick start
import { Telegraf } from "telegraf";
import { TopTLClient } from "toptl";
import { toptlTelegraf, voteRequired } from "toptl-telegraf";
const client = new TopTLClient("your-api-token");
const bot = new Telegraf("BOT_TOKEN");
// Track stats & add ctx.toptl
bot.use(toptlTelegraf(client, "mybot"));
bot.start((ctx) => ctx.reply("Hello!"));
bot.launch();Vote-gating
Block commands for users who haven't voted:
bot.command(
"premium",
voteRequired(client, "mybot", "Vote first! https://top.tl/mybot"),
(ctx) => {
ctx.reply("Thanks for voting!");
}
);Manual vote check
bot.command("check", async (ctx) => {
const voted = await ctx.toptl.hasVoted();
ctx.reply(voted ? "You voted!" : "Please vote.");
});How it works
- Tracking — The middleware records unique user, group, and channel IDs from every update.
- Auto-posting — A
setIntervaltimer posts aggregated stats to TOP.TL at a server-controlled interval. - Vote checks —
ctx.toptl.hasVoted()and thevoteRequiredmiddleware query the TOP.TL API.
License
MIT
