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

@mkzstyleee/telega

v1.0.2

Published

A modern, production-ready Telegram Bot API library for Node.js with full TypeScript support

Readme

Telega

A modern, production-ready Telegram Bot API library for Node.js with full TypeScript support.

Features

  • Full TypeScript Support - Complete type definitions for all Telegram Bot API types
  • ESM & CommonJS - Works with both module systems
  • Modern Architecture - Built with async/await, Promises, and modern JavaScript
  • Tree-shakeable - Optimized for minimal bundle size
  • Zero Dependencies - Uses native fetch for HTTP requests
  • Both Polling & Webhook - Flexible update receiving methods
  • Middleware System - Powerful middleware for request processing
  • Command Handler - Built-in command parsing and handling
  • Plugin System - Extensible via plugins
  • Rate Limit Handling - Automatic retry on rate limits
  • Comprehensive API - All Telegram Bot API methods implemented

Installation

npm install @mkzstyleee/telega

Quick Start

import { Telega } from '@mkzstyleee/telega';

const bot = new Telega({
  token: 'YOUR_BOT_TOKEN',
});

// Handle /start command
bot.command('start', async (ctx) => {
  await ctx.reply('Hello! I am a bot powered by Telega.');
});

// Handle /ping command
bot.command('ping', async (ctx) => {
  await ctx.reply('Pong!');
});

// Echo messages
bot.on('message', async (ctx) => {
  const text = ctx.getText();
  if (text && !ctx.message?.isCommand) {
    await ctx.reply(`You said: ${text}`);
  }
});

// Start polling
bot.startPolling();

Documentation

Table of Contents

Sending Messages

// Simple text message
await bot.sendMessage(chatId, 'Hello World!');

// With reply markup
await bot.sendMessage(chatId, 'Choose an option:', {
  replyMarkup: {
    inline_keyboard: [
      [{ text: 'Option 1', callback_data: 'opt1' }],
      [{ text: 'Option 2', callback_data: 'opt2' }],
    ],
  },
});

// With formatting (MarkdownV2)
await bot.sendMessage(chatId, '*Bold* and _italic_ text', {
  parseMode: 'MarkdownV2',
});

Keyboard Builder

import { keyboard } from '@mkzstyleee/telega';

const inlineKeyboard = keyboard()
  .text('Button 1', 'callback_1')
  .text('Button 2', 'callback_2')
  .row()
  .url('Visit Website', 'https://example.com')
  .build();

await bot.sendMessage(chatId, 'Choose:', {
  replyMarkup: inlineKeyboard,
});

Middleware

// Global middleware
bot.use(async (ctx, next) => {
  console.log(`Update ${ctx.update.update_id} received`);
  await next();
});

// Logging middleware for errors
bot.use(async (ctx, next) => {
  try {
    await next();
  } catch (error) {
    console.error('Error:', error);
    await ctx.reply('An error occurred');
  }
});

Commands

// Simple command
bot.command('hello', async (ctx) => {
  await ctx.reply('Hello there!');
});

// Command with aliases
bot.command('start', async (ctx) => {
  await ctx.reply('Welcome!');
}, { aliases: ['begin', 'init'] });

// Command with description (for help)
bot.command('help', showHelp, { description: 'Show help message' });

Webhook

// Start webhook server
await bot.startWebhook({
  url: 'https://your-domain.com/webhook',
  port: 3000,
  path: '/webhook',
  secretToken: 'your-secret-token',
});

// Express integration
import express from 'express';
const app = express();

app.post('/webhook', bot.webhook.getExpressMiddleware());

app.listen(3000);

Context

The context object provides convenient methods and properties:

bot.on('message', async (ctx) => {
  // Access update data
  const user = ctx.from;        // User who sent the message
  const chat = ctx.chat;        // Chat where message was sent
  const message = ctx.message;  // The message object

  // Reply methods
  await ctx.reply('Text');
  await ctx.replyWithPhoto('https://example.com/photo.jpg');
  await ctx.replyWithDocument(buffer);
  await ctx.replyWithSticker('sticker_id');

  // Edit message
  await ctx.editMessageText('New text');

  // Delete message
  await ctx.deleteMessage();

  // Get message text
  const text = ctx.getText();

  // Get command
  const cmd = ctx.getCommand();

  // Chat type checks
  ctx.isPrivate();    // true if private chat
  ctx.isGroup();      // true if group
  ctx.isSupergroup(); // true if supergroup
  ctx.isChannel();    // true if channel
});

Plugins

import { createSessionPlugin, createRateLimitPlugin } from '@mkzstyleee/telega';

// Session plugin
await bot.plugin(createSessionPlugin({ ttl: 3600000 }));

// Rate limiting
await bot.plugin(createRateLimitPlugin({
  windowMs: 60000,
  max: 5,
  message: 'Too many messages!',
}));

API Reference

Constructor

const bot = new Telega({
  token: 'BOT_TOKEN',           // Required
  baseUrl: 'https://...',       // Optional: API URL
  timeout: 30000,               // Optional: Request timeout
  maxRetries: 3,                // Optional: Max retries
  autoRetryOnRateLimit: true,   // Optional: Auto retry on 429
  logger: { level: 'info' },    // Optional: Logger config
});

Methods

| Method | Description | |--------|-------------| | startPolling(options?) | Start long polling | | stopPolling() | Stop polling | | startWebhook(options) | Start webhook server | | stopWebhook() | Stop webhook server | | use(middleware) | Add middleware | | command(name, handler, options?) | Register command | | on(event, handler) | Register event handler | | plugin(plugin) | Install plugin | | sendMessage(chatId, text, options?) | Send text message | | sendPhoto(chatId, photo, options?) | Send photo | | sendDocument(chatId, document, options?) | Send document | | getMe() | Get bot information | | getFile(fileId) | Get file info | | downloadFile(path) | Download file |

Examples

Check the examples/ directory for more examples:

  • Basic bot
  • Commands
  • Middleware
  • Webhook
  • TypeScript

License

MIT