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

@tgsnake/fileid

v2.1.0

Published

core framework for tgsnake for generating file id

Readme

@tgsnake/fileid

Core framework for creating fileId for tgsnake.

This framework is ported or inspired from pyrogram, big thank for that framework.

Another framework it should be can using this framework, not only a tgsnake.

The advantages we offer

  • Stable
    As long as we use this, the framework works fine without any problems. If a problem is found we will fix it as soon as possible.

  • Fast
    This framework using simple algorithm to make it fast compared to other frameworks.

  • Zero Dependencies
    With zero dependencies it make this framework fast and You don't have to worry about the security of this framework.

  • Typescript Support
    This framework is build with typescript, so for typescript user no need to worry about types, because we already have it.

  • Url Safe
    We are using base64url than base64 for encoding the file id, which base64url more safe when you using for Url. see : https://stackoverflow.com/a/55389212/16600138

  • Work with another framework fileId generator
    This framework also supported file id of :

    • Telethon
    • Pyrogram
    • Bot Api
    • tg-file-id
    • Another framework should be we supported too.

    We just tester for decoding file id from that framework, nvm work for re-sending the documents, but you can try. should be work too..

Installation

Installing this framework with npm

  cd my-project
  npm install @tgsnake/fileid

Installing this framework with yarn

  cd my-project
  yarn add @tgsnake/fileid

Usage/Examples

const { FileId, FileType, ThumbnailSource, FileTypeUniqueId } = require('@tgsnake/fileid');
const raw = FileId.decodeFileId(
  'CAACAgUAAxkBAAICjWKI4c8Zg7eo6bSbtAV_bVcFa9DmAAJ3BgACuNvZV0cotKoi35kTHgQ'
);
console.log(fileId);

Documentation

Options

This options is using for generating unique file id or file id. Pass this options when you create a new class from FileId.

| field | type | required | description | | :------: | :-----: | :----: | :-----: | | version | number | true | The major version of bot api file id. Usually is 4. | | subVersion | number | true | The minor version of bot api file id. Usually same with tdlib version or 32. | | dcId | number | true | The data center id, where that file is stored. | | fileType | enum/number of FileType | true | The enum/number of FileType. recommend to use enum. | | id | bigint | true | The id of file. | | accessHash | bigint | true | The hash to access that file. | | fileReference | Buffer | optional | File reference of that file. | | url | string | optional | If the file has web location, fill this with url of that web location. | | volumeId | bigint | optional | If the file has volume id, fill this with it. or if file doesn't have a volume id, fill this with BigInt(0)``. This is required when you try to make file id of photo/thumbnail. | | localId| number | optional | If the file has local id, fill this with it. or if file doesn't have a local id, fill this with0. This is required when you try to make file id of photo/thumbnail. | | secret| bigint | optional | The secret key from file, if file doesn't have a secret key fill this withBigInt(0). This is required when you try to make ThumbnailSource.LEGACY| |chatId| bigint | optional | If you want to make a file id of photo profil, fill this with BigInt of chatId. | |chatAccessHash| bigint | optional | If you want to make a file id of photo profil, fill this with BigInt of accessHash that chat, orBigInt(0)it must be work when you doesn't have a accessHash of that chat. | |stickerSetId| bigint | optional | The id of that sticker set. | |stickerSetAccessHash| bigint | optional | The accessHash of that sticker set.BigInt(0)`` ot must be work when you doesn't have a accessHash of that sticker set. | | thumbnailSource | enum/number of ThumbnailSource | optional | The enum/number of ThumbnailSource. recommended to use enum. | | thumbnailFileType | enum/number of FileType | optional | The enum/number of FileType. recommend to use enum. | | thumbnailSize | string | optional | The size of that thumbnail. see : https://core.telegram.org/api/files#image-thumbnail-types | | fileTypeUniqueId | enum/number of FileTypeUniqueId | optional | Only for generating uniqueFileId. The enum/number of FileTypeUniqueId. recommended to use enum. |

Enums

FileType

enum FileType {
  THUMBNAIL = 0,
  CHAT_PHOTO = 1, // ProfilePhoto
  PHOTO = 2,
  VOICE = 3, // VoiceNote
  VIDEO = 4,
  DOCUMENT = 5,
  ENCRYPTED = 6,
  TEMP = 7,
  STICKER = 8,
  AUDIO = 9,
  ANIMATION = 10,
  ENCRYPTED_THUMBNAIL = 11,
  WALLPAPER = 12,
  VIDEO_NOTE = 13,
  SECURE_RAW = 14,
  SECURE = 15,
  BACKGROUND = 16,
  DOCUMENT_AS_FILE = 17,
}

Importing this enum :

const { FileType } = require('@tgsnake/fileid');

ThumbnailSource

enum ThumbnailSource {
  LEGACY = 0,
  THUMBNAIL = 1,
  CHAT_PHOTO_SMALL = 2, // DialogPhotoSmall
  CHAT_PHOTO_BIG = 3, // DialogPhotoBig
  STICKER_SET_THUMBNAIL = 4,
}

Importing this enum :

const { ThumbnailSource } = require('@tgsnake/fileid');

FileTypeUniqueId

enum FileTypeUniqueId {
  WEB = 0,
  PHOTO = 1,
  DOCUMENT = 2,
  SECURE = 3,
  ENCRYPTED = 4,
  TEMP = 5,
}

Importing this enum :

const { FileTypeUniqueId } = require('@tgsnake/fileid');

Generating file id.

for generating file id, you can use .encodeFileId method. And for decoding using .decodeFileIdmethod.

const { FileId, FileType, ThumbnailSource, FileTypeUniqueId } = require("@tgsnake/fileid")
const fileId = FileId.encodeFileId({
  version : 4,
  subVersion : 32,
  fileType : FileType.STICKER,
  id : ,// fill this with document id
  accessHash : , // fill this with document accessHash
  fileReference : , // fill this with document fileReference
  dcId : // fill this with document dcId
  // fill with another options.
})
console.log(fileId)

Generating file id and uniqueFileId

for generating only unique file id, you can use .encodeUniqueId method. And for decoding using decodeUniqueId method.

const { FileId, FileType, ThumbnailSource, FileTypeUniqueId } = require("@tgsnake/fileid")
const fileId = FileId.encode({
  version : 4,
  subVersion : 32,
  fileType : FileType.STICKER,
  fileTypeUniqueId : FileTypeUniqueId.DOCUMENT,
  id : ,// fill this with document id
  accessHash : , // fill this with document accessHash
  fileReference : , // fill this with document fileReference
  dcId : // fill this with document dcId
  // fill with another options.
})
console.log(fileId)

License

MIT


Build With ❤️ by tgsnake dev.