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

@iam4x/teleproto

v1.227.2

Published

Telegram MTProto API client library written in TypeScript

Readme

npm License: MIT

Fork of teleproto, updated dependencies and fixed circular dependencies.

This README is just a fast quick start. Upstream discussion happens in the Telegram chat.

What is @iam4x/teleproto?

@iam4x/teleproto is a TypeScript client for Telegram's MTProto API — the same protocol Telegram's own apps speak. Through it, your code gets the full account surface: userbots, multi-account automation, file transfer, raw TL invocation when you need it. If you only need to push notifications from a bot, the official Bot API is simpler; teleproto exists for everything beyond that.

Installing @iam4x/teleproto

npm install @iam4x/teleproto

Pure JavaScript, no native build step — installs cleanly on Alpine, ARM, and serverless runtimes.

Connecting to Telegram

You need an api_id and api_hash from https://my.telegram.org. Then:

import { TelegramClient } from "@iam4x/teleproto";
import { StringSession } from "@iam4x/teleproto/sessions";
import { createInterface } from "node:readline/promises";

const rl = createInterface({ input: process.stdin, output: process.stdout });

const apiId = 0;     // from https://my.telegram.org
const apiHash = "";  // from https://my.telegram.org
const session = new StringSession("");

const client = new TelegramClient(session, apiId, apiHash, {
  connectionRetries: 5,
});

await client.start({
  phoneNumber: () => rl.question("Phone: "),
  password:    () => rl.question("2FA password: "),
  phoneCode:   () => rl.question("Code: "),
  onError: console.error,
});

console.log(await client.getMe());
console.log("Session string:", client.session.save());

rl.close();

The session string is your saved login. Drop it back into new StringSession(saved) next time and skip the auth flow entirely.

Sending and receiving

Send a message, listen for incoming ones:

import { NewMessage } from "@iam4x/teleproto/events";

await client.sendMessage("me", { message: "hello from teleproto" });

client.addEventHandler(
  (event) => console.log(event.message.message),
  new NewMessage({}),
);

Raw MTProto API

Every method in Telegram's TL schema is callable directly through Api.*. teleproto follows the schema layer-for-layer, so what Telegram adds is usually available here within days.

import { Api } from "@iam4x/teleproto";

const config = await client.invoke(new Api.help.GetConfig());

Versioning

teleproto uses a three-part version MAJOR.LAYER.PATCH:

  • MAJOR — bumped on breaking API changes in teleproto itself.
  • LAYER — the Telegram TL schema layer the release ships against (e.g. 1.225.x ships layer 225).
  • PATCH — fixes and non-breaking improvements within the same layer.

This stays compatible with npm's range syntax:

  • ^1.225.0 accepts new layers and patches — recommended default.
  • ~1.225.0 sticks to layer 225 only; useful if you depend on schema specifics that newer layers might change.
  • 1.225.1 is an exact pin.

Examples

Runnable scripts live in teleproto_examples/:

  • print_updates.ts — log every update the client receives
  • print_messages.ts — listen for new messages only
  • replier.ts — auto-reply pattern for bots and userbots
  • interactive_terminal.ts — REPL against a live client

Each is self-contained. Set your credentials at the top and run:

npx ts-node --transpile-only teleproto_examples/print_updates.ts

Code contributions

Please see CONTRIBUTING.md.

License

teleproto is distributed under the MIT License.