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

@gyach/telegram-export-chat-to-json

v1.0.0

Published

Simple TypeScript CLI that logs into Telegram and exports chat history to JSON.

Readme

Telegram Chat Reader

Simple TypeScript CLI that signs in to Telegram with your credentials and exports a chat history to JSON. Telegram API access is handled via GramJS.

Installation

Global CLI

npm install -g @gyach/telegram-export-chat-to-json
tgexp --chat @example_chat

Project-local / NPX

npm install @gyach/telegram-export-chat-to-json --save-dev
npx tgexp --chat @example_chat

Both approaches expose the primary telegram-chat-reader command plus the shorter alias tgexp. When installed locally, run either via npx or add it to your npm scripts.

Configuration

  1. Create an application on my.telegram.org to obtain your api_id and api_hash.
  2. Create a .env file in the directory where you plan to run the CLI. You can copy the bundled example (e.g., cp node_modules/@gyach/telegram-export-chat-to-json/.env.example .env) or paste the snippet below:
    TELEGRAM_API_ID=123456
    TELEGRAM_API_HASH=yourhash
    Optional variables that reduce interactive prompts:
    • TELEGRAM_SESSION — persisted GramJS StringSession
    • TELEGRAM_PHONE_NUMBER — phone in international format
    • TELEGRAM_PASSWORD — Telegram 2FA password, if enabled

Usage

Run either tgexp or telegram-chat-reader from any directory that contains a configured .env file. The CLI requires at least one argument — the chat identifier (@username, numeric id, or a public link):

tgexp --chat @example_chat

Available flags:

| Flag | Description | |-----------------|---------------------------------------------------------------------------------------------------------------| | --out, -o | Custom export path. If omitted, the tool writes <chat>-YYYY-MM-DD_HH-MM-SS.json to the current directory. | | --limit, -l | Limit on the number of messages to fetch. |

On the first run the script may ask for your phone number, confirmation code, and 2FA password. After successful login it prints a new StringSession; save it into TELEGRAM_SESSION to skip future prompts.

Output

Each export produces a JSON document saved either at the provided --out destination or, by default, in the working directory with a chat-and-date-based filename. The structure looks like this:

{
  "metadata": {
    "chat": "@example_chat",
    "exportedAt": "2024-03-01T12:00:00.000Z",
    "totalMessages": 42
  },
  "messages": [
    {
      "id": 1,
      "date": "2024-02-01T10:00:00.000Z",
      "text": "Hello",
      "fromId": "user:123",
      "peerId": "chat:456",
      "outgoing": true,
      "replyToMessageId": null,
      "mediaType": null,
      "viaBotId": null,
      "fwdFrom": null
    }
  ]
}

Validation

Run a build to ensure TypeScript sources compile:

npm run build

After updating .env, execute a test export (e.g., tgexp --chat <id>) and confirm a JSON file appears in your current directory with the expected chat name and timestamp in its filename.

Local Development

If you are working with the repository sources:

npm install
npm run build
npm start -- --chat @example_chat

npm start relies on ts-node for a faster edit-run loop. The published CLI uses the compiled JavaScript in dist/.