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

gramjs-node-telegram-bot-api-wrapper

v0.1.11

Published

Node-telegram-bot-api compatible wrapper built on top of GramJS (telegram npm package)

Readme

GramJS wrapper with node-telegram-bot-api ergonomics

A thin wrapper around telegram (GramJS) that mimics the familiar node-telegram-bot-api interface. It focuses on polling (no webhook) and supports both BotFather tokens and userbot logins.

Highlights

  • Familiar API surface: sendMessage, sendPhoto, sendDocument, sendAudio, sendVoice, sendVideo, sendAnimation, sendSticker, sendDice, sendLocation, sendVenue, sendContact, sendPoll, stopPoll, sendChatAction, editMessageText, editMessageCaption, deleteMessage, answerCallbackQuery, forwardMessage, getUpdates, getChat, getChatMember, getChatMemberCount, getChatAdministrators, leaveChat, onText, and events such as message, channel_post, edited_message, edited_channel_post, callback_query, and inline_query.
  • Polling only (no webhook) while still exposing a getUpdates queue for compatibility.
  • Works as a bot or userbot (via stringSession or one-time phoneCode login).
  • Builds for ESM and CJS and ships TypeScript typings.

Installation

npm install gramjs-wrapper-node-telegram-bot-api

Import styles

  • ESM / TypeScript

    import TelegramBot from "gramjs-wrapper-node-telegram-bot-api";
  • CommonJS

    const TelegramBot = require("gramjs-wrapper-node-telegram-bot-api");

TelegramBot is available as both the default export and a named export, so destructuring works if you prefer.

Quick start (bot token)

import TelegramBot from "gramjs-wrapper-node-telegram-bot-api";

const bot = new TelegramBot("BOT_TOKEN", {
  apiId: Number(process.env.TELEGRAM_API_ID),
  apiHash: process.env.TELEGRAM_API_HASH!,
  polling: true,
});

bot.on("message", (msg) => {
  bot.sendMessage(msg.chat.id, `Hello ${msg.from?.first_name ?? ""}`);
});

bot.onText(/\/start/, async (msg) => {
  await bot.sendMessage(msg.chat.id, "Bot is ready!");
});

Userbot login (interactive-friendly)

Common GramJS scenarios are supported:

  • Reuse an existing stringSession
  • First-time login with OTP sent via Telegram app or SMS ✅
  • Two-factor password (2FA) ✅

phoneNumber, phoneCode, and password can be strings or async functions that prompt for input (for example, via CLI). If they are omitted and the process runs in a TTY, the wrapper will prompt in the terminal.

const bot = new TelegramBot({
  stringSession: process.env.TELEGRAM_SESSION, // exported earlier
  phoneNumber: "+62123456789", // required if there is no session yet
  phoneCode: async () => {
    // Wait for manual input from CLI (readline or your own mechanism)
    return process.env.TELEGRAM_CODE ?? "";
  },
  password: process.env.TELEGRAM_PASSWORD, // optional when 2FA is enabled
}, {
  apiId: Number(process.env.TELEGRAM_API_ID),
  apiHash: process.env.TELEGRAM_API_HASH!,
  polling: true,
});

If codes or passwords are missing and stdin/stdout is a TTY, the wrapper will prompt directly in the terminal. This makes first-time logins easy without additional code.

After logging in once, export and store the session for future runs:

console.log(bot.exportSession());

Limitations

  • No webhook endpoint is provided (polling only).
  • Some file_id/file_unique_id values are synthesized for compatibility and are not official Bot API IDs.
  • For userbots, non-interactive login requires either a stored stringSession or a combination of phoneNumber + phoneCode (OTP) plus password when two-factor is enabled.
  • getUpdates reads from the internal real-time polling queue (not HTTP long polling). Offset and limit parameters are supported for compatibility.

Tips for userbots

  • Telegram usually sends OTP codes to the official app before SMS. The wrapper will prompt when GramJS asks for the code, so you can copy it from the app.
  • If two-factor is enabled, make sure password is provided (string or async function) so the login flow can finish.
  • Store the exportSession() result in an environment variable so subsequent runs skip OTP.