Library / SDK
telegraf/telegraf avatar
telegraf/telegraf

Telegraf's nine export subpaths, webhook launch, and undocumented edges

Modern Telegram Bot Framework for Node.js

9,211 stars945 forksTypeScriptMIT

At a glance

What is it?
Telegraf is the TypeScript Telegram bot framework published as version 4.16.3. Its package manifest, its webhook options and the middleware list the README keeps commented out tell you more about the boundaries than the feature list does.
Who is it for?
Take Telegraf when you want typed Telegram Bot API handlers in Node.js and can live with the 4.16.3 published tag. Before committing, read the eight generated declaration shims, choose your own session and throttling middleware, and register the SIGINT and SIGTERM handlers in your entry file.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 6 days ago.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • telegraf/telegraf9,211 ★ · +18
Star history
Repository2026-09-302026-11-22
telegraf/telegraf9.2k9.2k

18 Stars in the last 53 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

The published tarball ships TypeScript sources and declaration maps

The npm package is named telegraf, describes itself as Modern Telegram Bot Framework, is MIT licensed, and lists The Telegraf Contributors as author. Its files array publishes bin/*, src/**/*.ts, lib/**/*.js, typings/**/*.d.ts and the declaration maps, plus the root shims types.*, format.*, filters.*, future.*, scenes.*, utils.*, markup.* and session.*. So the tarball carries the TypeScript sources and the declaration maps next to the compiled JavaScript, which is worth knowing before you read the feature list's Lightweight item and its packagephobia link as a size promise. The README header spells the project telegraf.js and links the Telegram Bot API page, so confirm that description before you clone a repository carrying this name.

shellscript
$ npm install telegraf
shellscript
$ yarn add telegraf
shellscript
$ pnpm add telegraf

A token comes from BotFather in the form 123456789:AbCdefGhIJKlmNoPQRsTUVwxyZ, and the first working bot is a short script:

js
const { Telegraf } = require('telegraf')
const { message } = require('telegraf/filters')

const bot = new Telegraf(process.env.BOT_TOKEN)
bot.start((ctx) => ctx.reply('Welcome'))
bot.help((ctx) => ctx.reply('Send me a sticker'))
bot.on(message('sticker'), (ctx) => ctx.reply('👍'))
bot.hears('hi', (ctx) => ctx.reply('Hey there'))
bot.launch()

Nine export subpaths, eight wired to generated declaration shims

package.json resolves the root import to typings/index.d.ts and lib/index.js, then pairs each subpath with its own declaration and JavaScript file:

json
  "exports": {
    ".": {
      "types": "./typings/index.d.ts",
      "default": "./lib/index.js"
    },
    "./filters": {
      "types": "./filters.d.ts",
      "default": "./filters.js"
    },
    "./scenes": {
      "types": "./scenes.d.ts",
      "default": "./scenes.js"
    },
    "./session": {
      "types": "./session.d.ts",
      "default": "./session.js"
    }
  },

Each entry carries one default condition with no import or require split, main stays CommonJS at lib/index.js while the bin entry named telegraf points at lib/cli.mjs. The shims are produced by the build:

json
  "build": "tsc && npm run expose",
  "expose": "tsx build/expose.ts types scenes filters format future utils markup session",

Two consequences follow. A build that stops after tsc, without the expose step, produces no subpath declarations, so a telegraf/scenes or telegraf/session import fails to resolve with nothing pointing at the missing step. npm install also drops a telegraf CLI, with its bin entry at lib/cli.mjs.

The middleware catalogue sits inside a commented out TODO

Between the Context section and the shorthand methods, the README carries a block that opens with a TODO to verify and update list and ends with a pointer to npm search for telegraf-. The whole thing sits inside an HTML comment, so nothing between those markers renders on the project page.

What it names is still the best map of the extension surface: telegraf-i18n for picking a translation, telegraf-session-redis and telegraf-session-local through lowdb for session data, telegraf-ratelimit, telegraf-throttler for throttling incoming updates and outgoing API calls, telegraf-inline-menu, telegraf-stateless-question, telegraf-wit, telegraf-recast, telegraf-experiments for multivariate and A/B tests, telegraf-mixpanel and telegraf-statsd. Not one carries a version, a compatibility statement against 4.16.3, or a note about who keeps it going. Treat the list as leads and read each repository before your bot depends on it, because the project page will not tell you whether a plugin tracks the v4 branch.

Examples live in a repository under feathers-studio now

Examples no longer live in the library repository. The line under the code samples sends you to the new docs repo at github.com/feathers-studio/telegraf-docs, a different owner, while the API reference link goes to telegraf.js.org/modules.html. For 3.x users the page still links telegraf.js.org/v3 and the 4.0 release notes on the v4.0.0 tag, and the Excellent TypeScript typings item in the feature list resolves to that same release page rather than to any type reference.

The consequence for a reader is that anything written against Telegraf 3 still looks plausible next to this code, and this page does not enumerate what changed between the two, it only points at one tag. Compare any snippet against the modules reference before you copy it. Support channels are also split across places: four Telegram groups sorted by member count (English, Russian, Uzbek, Ethiopian) plus GitHub Discussions, with bug reports pointed at the issues URL in package.json.

Webhook mode hands you the domain, the port, and the path

The webhook branch of bot.launch takes an options object with a public domain, a port to listen on, an optional path that defaults to bot.secretPathComponent(), and an optional secret to be sent back in a header:

TS
bot.launch({
  webhook: {
    // Public domain for webhook; e.g.: example.com
    domain: webhookDomain,

    // Port to listen on; e.g.: 8080
    port: port,

The comment above the call marks this the preferred way to start a webhook, and the text after the block points at createWebhook() as the alternative. Long polling needs nothing from you because the instance obtains updates itself; webhooks move every one of those values onto your side of the wire, and they have to stay in step with what Telegram holds on its side. The feature list names http, https, fastify, Connect.js and express.js as compatible webhook hosts and nothing else.

Every update gets a fresh Context and nothing stores state for you

A Telegraf instance obtains updates and passes them to your handlers, and for each incoming update it builds a Context carrying update, botInfo and telegram, described as the handle for making arbitrary Bot API requests, plus shorthand methods and getters.

js
bot.on(message('text'), async (ctx) => {
  // Explicit usage
  await ctx.telegram.sendMessage(ctx.message.chat.id, `Hello ${ctx.state.role}`)

  // Using context shortcut
  await ctx.reply(`Hello ${ctx.state.role}`)
})

Each pair sends the same request twice, once through ctx.telegram.leaveChat(ctx.message.chat.id) and once through ctx.leaveChat(). The example reads ctx.state.role, a value none of the core classes described here sets. The exports map offers ./session, and the commented list names two session stores, one on Redis (telegraf/telegraf-session-redis) and one on a local file through lowdb (RealSpeaker/telegraf-session-local).

SIGINT and SIGTERM handlers are four lines you copy yourself

Both README examples close with the same pair of handlers:

js
process.once('SIGINT', () => bot.stop('SIGINT'))
process.once('SIGTERM', () => bot.stop('SIGTERM'))

The library installs neither one. bot.launch() is the call that starts the bot, and stopping is left to your entry file. A supervisor or container that sends SIGTERM on redeploy therefore reaches a process with no handler unless those lines are there. Register the handlers before you launch, and treat the shutdown path as part of your own code rather than as something the framework handles.

The newest tag is 4.16.3 while the v4 branch keeps taking commits

The repository lists three recent releases, all from February 2024: v4.16.3 on 2024-02-29, v4.16.2 on 2024-02-26 and v4.16.1 on 2024-02-25, and package.json still declares 4.16.3. The repository is not archived, its default branch is v4, and that branch was pushed on 2026-09-24, so the source has moved since the newest tag while npm hands you the 4.16.3 code. Release notes live in a release-notes directory at the top level.

The stated ceiling is Telegram Bot API 7.1 in the feature list. If you need an endpoint added after 7.1, the only handle named anywhere is the telegram object on the Context. Pin the version you test against, and read the changelog yourself before assuming a newer Bot API method is covered.

Editorial conclusion

Take Telegraf when you want typed Telegram Bot API handlers in Node.js and can live with the 4.16.3 published tag. Before committing, read the eight generated declaration shims, choose your own session and throttling middleware, and register the SIGINT and SIGTERM handlers in your entry file. It suits you poorly if you need Bot API endpoints past 7.1 without writing raw calls.

Frequently asked questions

What is Telegraf used for?

Telegraf is a library for building your own Telegram bots in JavaScript or TypeScript. Bots are Telegram accounts that handle messages automatically, and users reach them by sending command messages in private or group chats.

How do I install Telegraf?

Run npm install telegraf, or yarn add telegraf, or pnpm add telegraf. You also need a bot token first: BotFather hands you one in the form 123456789:AbCdefGhIJKlmNoPQRsTUVwxyZ.

How does Telegraf work?

A Telegraf instance represents your bot and is responsible for obtaining updates and passing them to your handlers. For each incoming update it creates a Context holding update, botInfo and telegram, plus shorthand methods and getters.

How to stop telegraf?

The examples register process.once('SIGINT', () => bot.stop('SIGINT')) and process.once('SIGTERM', () => bot.stop('SIGTERM')) in your own entry file. The README labels these lines as the way to enable graceful stop.

How do I use telegraf?

Create a Telegraf instance with your token, register handlers such as bot.command('oldschool') or Telegraf.reply('λ'), and call bot.launch(). For webhooks you pass a webhook object with a domain and a port to the same launch method.

Who owns Telegraf?

The code sits under the telegraf organisation on GitHub, the package is MIT licensed, and package.json lists The Telegraf Contributors as author. The example repository the README points at belongs to a different owner, feathers-studio.

Official sources

  1. License: MIT
  2. Project website
  3. README
  4. Releases
  5. telegraf/telegraf on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/telegraf-telegraf.svg)](https://hysenlabs.com/projects/telegraf-telegraf)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/telegraf-telegraf.svg)](https://hysenlabs.com/projects/telegraf-telegraf)

Was this useful?