core framework for tgsnake for generating file id
npm install @tgsnake/fileidbase64url than base64 for encoding the file id, which base64url more safe when you using for Url. see : https://stackoverflow.com/a/55389212/16600138
bash
cd my-project
npm install @tgsnake/fileid
`
Installing this framework with yarn
`bash
cd my-project
yarn add @tgsnake/fileid
`
Usage/Examples
`javascript
const { FileId, FileType, ThumbnailSource, FileTypeUniqueId } = require('@tgsnake/fileid');
const raw = FileId.decodeFileId(
'CAACAgUAAxkBAAICjWKI4c8Zg7eo6bSbtAV_bVcFa9DmAAJ3BgACuNvZV0cotKoi35kTHgQ'
);
console.log(fileId);
`
Documentation
$3
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 with 0. 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 with BigInt(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, or BigInt(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. |
$3
#### FileType
`ts
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 :
`javascript
const { FileType } = require('@tgsnake/fileid');
`
#### ThumbnailSource
`ts
enum ThumbnailSource {
LEGACY = 0,
THUMBNAIL = 1,
CHAT_PHOTO_SMALL = 2, // DialogPhotoSmall
CHAT_PHOTO_BIG = 3, // DialogPhotoBig
STICKER_SET_THUMBNAIL = 4,
}
`
Importing this enum :
`javascript
const { ThumbnailSource } = require('@tgsnake/fileid');
`
#### FileTypeUniqueId
`ts
enum FileTypeUniqueId {
WEB = 0,
PHOTO = 1,
DOCUMENT = 2,
SECURE = 3,
ENCRYPTED = 4,
TEMP = 5,
}
`
Importing this enum :
`javascript
const { FileTypeUniqueId } = require('@tgsnake/fileid');
`
$3
for generating file id, you can use .encodeFileId method. And for decoding using .decodeFileIdmethod.
`javascript
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)
`
$3
for generating only unique file id, you can use .encodeUniqueId method. And for decoding using decodeUniqueId method.
`javascript
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)
``