toptl-node-telegram-bot-api

April 12, 2026 · View on GitHub

npm version npm downloads MIT License

toptl-node-telegram-bot-api

node-telegram-bot-api plugin for TOP.TL — automatically post bot stats and check user votes.

Installation

npm install toptl-node-telegram-bot-api toptl node-telegram-bot-api

Usage

import TelegramBot from "node-telegram-bot-api";
import { TopTLClient } from "toptl";
import { createTopTLPlugin, hasVoted } from "toptl-node-telegram-bot-api";

const bot = new TelegramBot(process.env.BOT_TOKEN!, { polling: true });
const client = new TopTLClient(process.env.TOPTL_TOKEN!);

const plugin = createTopTLPlugin(client, "my_bot", bot, {
  autoPostInterval: 30 * 60 * 1000, // 30 minutes (default)
});

// Check if a user has voted
bot.onText(/\/voted/, async (msg) => {
  const voted = await hasVoted(client, "my_bot", msg.from!.id);
  bot.sendMessage(msg.chat.id, voted ? "Thanks for voting!" : "Please vote at https://top.tl/my_bot");
});

Options

OptionTypeDefaultDescription
autoPostIntervalnumber1800000Interval between auto-posts in ms
autoPostbooleantrueStart auto-posting immediately

License

MIT