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

@tgwrapper/core

v0.17.1

Published

Serverless-first Telegram bot framework without external bot libraries

Readme

TGWrapper

Production Telegram bots in TypeScript — with Redis state, observability, and reliability semantics built in.

When your bot stops being a side project and becomes a core service, TGWrapper is where teams land.

npm version License


⚡ Quick Start

Requirements

  • Node.js >=22.13
  • pnpm (workspace-aware package manager)
  • Redis when you need distributed state or multi-instance coordination
import { createBotClient } from "@tgwrapper/core"

const bot = createBotClient({ token: process.env.BOT_TOKEN!, mode: "polling" })
bot.on("message", async (msg) => {
  if ("text" in msg) await bot.sendMessage(msg.chat.id, `Echo: ${msg.text}`)
})
await bot.start()
pnpm add @tgwrapper/core   # install
pnpm build && pnpm test       # validate types + tests

Reference apps: Polling bot · Multi-instance + Redis · Serverless / edge · AI-native bot


🧭 Choose Your Path

Whether you're starting a new bot or migrating an existing production workload, choose the path that fits you:


🎯 Who this is for

TGWrapper is built for teams and senior engineers running serious Telegram bots who have already felt the pain of their current stack:

  • Duplicate sends from webhook retries because your handler didn't return in time
  • Multi-instance state conflicts because there's no distributed session primitive
  • Debugging a production incident with no trace IDs, no structured logs, no span context
  • Self-rolled rate limiting that's either too loose or causes unfair blocks under burst
  • An AI-native bot that needs token metrics, tool-call tracing, and timeout contracts

If any of those sound familiar — this is where you land next.

🚫 Who this is NOT for (consciously)

  • First-time bot builders — Telegraf and grammY are excellent starting points; TGWrapper adds structure that you don't need yet
  • Toy bots — if you need 30 lines and a /start handler, any framework works fine
  • No Redis, no observability, no multi-instance needs — in-memory session and polling work, but the framework's main value is in the distributed layer
  • Non-TypeScript stacks — TS-first only

⚡ What gets easier with TGWrapper

  • No silent concurrent session overwrites: Redis Compare-and-Swap (CAS) returns explicit conflicts instead of silently replacing newer state.
  • Trace incidents with structured context: Correlation fields (trace_id, span_id) are attached to update processing, with strongest async propagation support in Node.js.
  • Fail gracefully under load: Native distributed rate limiting (sliding-window via Redis ZSETs) and built-in timeout abort signals protect your API limits and prevent webhook retry loops.
  • Robust type safety: Pure TypeScript contracts with typed handlers and typed session state instead of implicit any context magic.

🛡️ Proof Snapshot

Direct operational evidence backing the framework's reliability:

| Gate / Quality Metric | Status / Evidence | | :------------------------ | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Comprehensive Tests | 100% Passed — 21 test files / 57 integration & FSM fuzz tests. | | Drift Watchdog | Active — Weekly automated checks against Telegram upstream schemas. | | Benchmark Performance | Validated with caveats — Synthetic core benchmark profiles have reached up to 180,000 updates/sec excluding Telegram API, Redis, user handlers, exporters, and network. | | Disaster Recovery | Verified — Chaos drills simulating Redis reconnect storms & network partition splits. | | Runtime Portability | Capability-specific — Core webhook handling targets Node.js, Cloudflare Workers, and AWS Lambda; polling, Redis, observability exporters, and shutdown semantics vary by runtime. |

🔬 Proof & Release Safeguards

  • Runtime Portability: Compatibility is tracked per capability in the Compatibility Matrix.
  • Auto Drift Protection: Weekly watchdog scripts validate our generated types against the latest official Bot API schema, preventing drift.
  • Benchmark Budgets: Core processing budget is monitored with synthetic benchmark gates; see Proof Map for reproduction scope.
  • Disaster Drills: Automated tests simulate network packet losses, 429 backpressures, and thread locks to verify robust recovery.

👥 Early Adopters in Production

  • FinTech Notification Bot: Switched from Telegraf to solve message duplicate issues. Runs 3 replicas on Kubernetes using webhook mode and Redis CAS sessions.
  • AI Coding Companion Bot: Migrated from Python to track LLM token counts and trace latency per tool-call via @tgwrapper/observability.
  • Read more detailed case studies in the Field Notes.

🎯 Quick Decision Matrix

Choose the right framework for your workload:

| Feature / Workload | TGWrapper | grammY | Telegraf | | :--------------------------- | :------------------------------------------------------------------ | :--------------------------------- | :--------------------------------- | | Simple Bot | ✅ Good (Clean, direct) | ✅ Excellent (Many features) | ✅ Good (Simplicity) | | Distributed / Scaled Bot | ✅ Strong fit when Redis CAS and shared rate limits matter | ⚠️ Possible with additional design | ⚠️ Possible with additional design | | AI / Conversational Bot | ✅ Strong fit when multi-turn state and token/latency traces matter | ⚠️ Add your own state safety | ⚠️ Add your own state safety | | Observability-Heavy Bot | ✅ Built-in hooks for structured logs, metrics, and traces | ⚠️ External instrumentation | ⚠️ External instrumentation | | Serverless Webhooks | ✅ Core webhook path is designed for fetch-style runtimes | ✅ Supported with runtime adapters | ⚠️ Usually Node-server oriented |


🧭 Which Path Should You Take?

Choose the canonical template matching your architecture:


📈 Maturity & Stability Matrix

| Package | Notes | | :------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------- | | @tgwrapper/core (Core) | Stable API surface; see docs/API_STABILITY.md for the canonical stability policy. | | @tgwrapper/adapter-redis | Redis-backed coordination layer; see docs/API_STABILITY.md for stability definitions. | | @tgwrapper/observability | Telemetry layer with evolving trace schema; see docs/API_STABILITY.md for the canonical stability policy. |

For the platform-wide truth table, see Platform Guarantees, Compatibility Matrix, and Deployment Profiles.


🚀 The Golden Path Onboarding (10-15 Minutes)

Deploying a production-ready Telegram bot follows a single, non-branching workflow:

  1. Install Core & Initialize: Install the core package.
  2. Develop with Polling: Create your bot using polling mode for rapid local iteration.
  3. Add State & Caching (Redis): Plug in the Redis adapter for multi-instance persistence.
  4. Attach Telemetry: Plug in observability to trace errors and metrics.
  5. Switch to Webhook & Deploy: Toggle mode to webhook and export to serverless runtimes.

Check out our comprehensive Grow with TGWrapper guide to walk through this onboarding flow step-by-step.


🛡️ Distributed Rate Limiting

[!WARNING] The default TokenBucketRateLimiter included in the core package operates in-memory. It is designed solely for local development and single-instance applications.

In multi-instance or serverless deployments, you must switch to the distributed rate limiter via the Redis adapter:

import { RedisKvStore, createRateLimiter } from "@tgwrapper/adapter-redis"

const kv = new RedisKvStore({
  redisUrl: process.env.REDIS_URL!,
  prefix: "mybot",
})
const limiter = createRateLimiter(kv, {
  namespace: "spam-protection",
  windowMs: 60_000,
  limit: 20,
  blockDurationMs: 30_000,
})

🛑 Limitations & Non-goals

Before adopting TGWrapper, review the architectural boundaries of the core package:

  • No Built-in UI Builder: Unlike heavy frameworks, TGWrapper does not contain custom templating DSLs or markup generators. You generate raw Telegram markdown/HTML payloads directly.
  • No Media Download/Upload Server: The framework wraps standard multipart and file fetch API endpoints but does not ship with automatic file caching or download streaming proxies.
  • Single-threaded Polling Loop: While webhook scaling is distributed, polling relies on a single loop. Large workloads on polling should switch to webhook ingestion.
  • Non-goal: Multi-platform Unified Client: The project is dedicated specifically to the Telegram Bot API and does not plan to support Discord, Slack, or other platforms.

🛡️ Evidence & Validation

We back our quality claims with evidence-driven gates running on every commit:

  • Comprehensive Unit Tests: 100% pass status on Vitest suite covering FSM state machines, routers, client endpoints, and update processing.
  • Auto Type-Drift Baseline Check: Enforced via automated scripts checking code types against upstream Telegram API releases.
  • Bundle Budget Restrictions: Monitored on build to keep cold-start latency low on edge platforms.

Verify validation checks locally:

pnpm install
pnpm build
pnpm test

📑 Core Documentation Index

Getting Started

Development

Production Operations

Quality & Evidence