npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zero-bot.net/tg-bot-api

v1.5.4

Published

Lightweight, dependency-light Telegram Bot API library for Node.js

Readme

A lightweight, dependency-light Node.js library for the Telegram Bot API.

Bot API npm package

✨ Features

  • 203 methods — full Telegram Bot API 10.3 coverage
  • No build step — ships native CommonJS, runs on Node.js 18+
  • Small dependency tree — file-type detection and MIME lookup are built in
  • Built-in TypeScript definitions
  • Both update modes — long polling and webhooks (with a built-in HTTP(S) server)
  • Rich Messages, Ephemeral Messages, Guest Mode, Business Accounts
  • Gifts, Stars & Payments, Checklists, Media Polls, Live Photos, Stories
  • Communities, Managed Bots, Suggested Posts, and more

📦 Install

npm i @zero-bot.net/tg-bot-api

🚀 Usage

const TelegramBot = require('@zero-bot.net/tg-bot-api');

const token = 'YOUR_TELEGRAM_BOT_TOKEN';

// Polling mode
const bot = new TelegramBot(token, { polling: true });

bot.onText(/\/echo (.+)/, (msg, match) => {
  bot.sendMessage(msg.chat.id, match[1]);
});

bot.on('message', (msg) => {
  console.log(msg.chat.id, msg.text);
});

Sending files

sendPhoto, sendDocument, sendAudio, ... accept a local path, a stream, a Buffer, a URL, or a file_id:

await bot.sendPhoto(chatId, './cat.png');          // path
await bot.sendPhoto(chatId, buffer);               // Buffer (type auto-detected)
await bot.sendPhoto(chatId, 'https://x/y.png');    // URL
await bot.sendPhoto(chatId, fileId);               // previously uploaded file

Webhooks

const bot = new TelegramBot(token, {
  webHook: { port: 8443, host: '0.0.0.0', healthEndpoint: '/healthz' },
});

bot.on('message', (msg) => bot.sendMessage(msg.chat.id, 'hi'));
await bot.setWebHook('https://example.com:8443');

Error handling

All API errors are errors.TelegramError (code ETELEGRAM) and carry the raw server response. Transport failures are errors.FatalError (code EFATAL) with the original error preserved as .cause.

const { TelegramError } = require('@zero-bot.net/tg-bot-api');

bot.on('polling_error', (err) => {
  if (err instanceof TelegramError) console.error(err.response.body);
  else console.error(err.message, err.cause);
});

⚡ Performance & latency

Warm (keep-alive) requests take 20–80ms. Cold connections pay DNS + TCP + TLS plus Node's 250ms IPv6 fallback window — that is what pushes a request to 200–600ms. Ranked fixes:

  1. Host near Telegram (EU/US) — RTT drops from ~200ms to ~10–30ms. No code.
  2. Self-hosted Bot API server — biggest win for media; files never leave your machine:
    const bot = new TelegramBot(token, { baseApiUrl: 'http://127.0.0.1:8081' });
  3. Remove the IPv6 fallback penalty (up to −250ms per connection):
    TelegramBot.applyNetworkTuning();          // ipv4-first + 100ms fallback window
    // or: new TelegramBot(token, { ipv4First: true });
  4. Pre-warm the connection so the first request is not a cold start:
    const bot = new TelegramBot(token, { prewarm: true });
    // or: await bot.preheat();
  5. Tune polling for instant updates: { polling: { params: { timeout: 30 }, interval: 50 } }.
  6. Fewer round-trips — batch with sendMediaGroup / forwardMessages / copyMessages, and reuse file_ids instead of re-uploading.

Keep-alive is enabled by default (forever: true); tune the pool if needed:

new TelegramBot(token, {
  request: {
    agentOptions: { keepAlive: true, keepAliveMsecs: 10000, maxSockets: 64 },
  },
});

📚 Documentation

🧪 Development

npm test          # offline mocha test suite
npm run lint      # eslint
npm run doc       # regenerate doc/api.md

Requires Node.js >= 18.

👥 Contributors

License

The MIT License (MIT)

Copyright © 2026 Grandpa EJ