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

@jengkhaw95/tbot

v1.1.4

Published

A simple and easy-to-use Telegram bot API wrapper for TypeScript.

Readme

@jengkhaw95/tbot

A simple and easy-to-use Telegram bot API wrapper for TypeScript.

Installation

npm install @jengkhaw95/tbot
# or
yarn add @jengkhaw95/tbot
# or
pnpm add @jengkhaw95/tbot

Quick Start

import { Bot } from '@jengkhaw95/tbot';

// Initialize bot with your token
const bot = new Bot({
  token: 'YOUR_BOT_TOKEN',
  secretToken: 'YOUR_SECRET_TOKEN' // Optional, for webhook security
});

// Handle messages
bot.onMessage(async (message) => {
  if (message.text) {
    await bot.message(message.chat.id)
      .text(`You said: ${message.text}`)
      .send();
  }
});

// Handle commands
bot.command('/start', async (ctx) => {
  await bot.message(ctx.message.chat.id)
    .text('Welcome! Bot is started.')
    .send();
});

// Start polling for updates
bot.startPolling();

Features

  • 🚀 Simple and intuitive API
  • 💪 Full TypeScript support
  • 🛠 Built-in message builder
  • 🔄 Supports both polling and webhook modes
  • ⚡️ Middleware support
  • 🎮 Inline keyboard support

API Reference

Bot Class

Constructor

const bot = new Bot(token: string);

Methods

  • message(chatId: number): Creates a new MessageBuilder instance
  • startPolling(interval?: number): Starts polling for updates
  • stopPolling(): Stops polling for updates
  • setWebhook(url: string): Sets up a webhook
  • deleteWebhook(): Removes the webhook
  • onMessage(handler: MessageHandler): Handles incoming messages
  • onUpdate(handler: UpdateHandler): Handles all updates
  • onCallbackQuery(handler: CallbackQueryHandler): Handles callback queries
  • command(cmd: string, handler: CommandHandler): Handles specific commands
  • use(middleware: MiddlewareFn): Adds middleware

MessageBuilder

Used for constructing messages with inline keyboards.

bot.message(chatId)
  .text('Choose an option:')
  .buttons([[
    { text: 'Option 1', callback_data: 'opt1' },
    { text: 'Option 2', callback_data: 'opt2' }
  ]])
  .send();

Examples

Using Middleware

// Log all updates
bot.use(async (ctx, next) => {
  console.log('Update received:', ctx.update);
  await next();
});

Handling Inline Keyboards

// Create buttons
bot.command('/menu', async (ctx) => {
  await bot.message(ctx.message.chat.id)
    .text('Select an option:')
    .buttons([[
      { text: 'Option 1', callback_data: 'opt1' },
      { text: 'Option 2', callback_data: 'opt2' }
    ]])
    .send();
});

// Handle button clicks
bot.onCallbackQuery((query) => {
  if (query.data === 'opt1') {
    // Handle Option 1
  }
});

Using Webhook Mode

// Initialize bot with token and optional secret token
const bot = new Bot({
  token: 'YOUR_BOT_TOKEN',
  secretToken: 'YOUR_SECRET_TOKEN' // Optional, for webhook security
});

// Set up webhook
await bot.setWebhook('https://your-domain.com/webhook');

// In your HTTP server, validate the secret token
app.post('/webhook', async (req, res) => {
  // Validate using headers
  if (!bot.validateSecretToken(req.headers)) {
    return res.sendStatus(401);
  }

  // Alternatively, validate using the token string directly
  if (!bot.validateSecretToken(req.headers['X-Telegram-Bot-Api-Secret-Token'])) {
    // Handle invalid token
  }
  
  await bot.handleWebhookRequest(req.body);
  res.sendStatus(200);
});

The validateSecretToken method helps secure your webhook endpoint by verifying the X-Telegram-Bot-Api-Secret-Token header or comparing directly with a token string. When a secret token is set during bot initialization, Telegram will include this token in webhook requests, allowing you to verify that the requests are genuine.