{"id":16511152,"url":"https://github.com/danog/tg-file-decoder","last_synced_at":"2025-04-09T13:11:07.533Z","repository":{"id":44535012,"uuid":"237681702","full_name":"danog/tg-file-decoder","owner":"danog","description":"Decode Telegram bot API file IDs","archived":false,"fork":false,"pushed_at":"2024-04-19T21:32:48.000Z","size":149,"stargazers_count":63,"open_issues_count":0,"forks_count":8,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-10-12T15:58:49.457Z","etag":null,"topics":["bot-api","decoder","files","photos","telegram","telegram-bot-api"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"danog"}},"created_at":"2020-02-01T21:40:13.000Z","updated_at":"2024-10-08T15:37:21.000Z","dependencies_parsed_at":"2023-11-30T18:28:27.354Z","dependency_job_id":"b03ea034-3e79-49b6-a64a-03fb4f4c41f8","html_url":"https://github.com/danog/tg-file-decoder","commit_stats":{"total_commits":44,"total_committers":2,"mean_commits":22.0,"dds":"0.022727272727272707","last_synced_commit":"fd9827e7af8f3b47dc6db4b1c12bfeb6654dde4f"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danog%2Ftg-file-decoder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danog%2Ftg-file-decoder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danog%2Ftg-file-decoder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danog%2Ftg-file-decoder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danog","download_url":"https://codeload.github.com/danog/tg-file-decoder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248045245,"owners_count":21038554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot-api","decoder","files","photos","telegram","telegram-bot-api"],"created_at":"2024-10-11T15:59:08.945Z","updated_at":"2025-04-09T13:11:07.497Z","avatar_url":"https://github.com/danog.png","language":"PHP","readme":"# tg-file-decoder\n\n![build](https://github.com/danog/tg-file-decoder/workflows/build/badge.svg)\n[![Psalm coverage](https://shepherd.dev/github/danog/tg-file-decoder/coverage.svg)](https://shepherd.dev/github/danog/tg-file-decoder)\n[![Psalm level 1](https://shepherd.dev/github/danog/tg-file-decoder/level.svg)](https://shepherd.dev/github/danog/tg-file-decoder)\n\nDecode and encode [Telegram bot API file IDs](https://core.telegram.org)!  \n\nThis library was initially created for [MadelineProto](https://docs.madelineproto.xyz), an async PHP client API for the telegram MTProto protocol.\n\n## Install\n\n```bash\ncomposer require danog/tg-file-decoder\n```\n\n## Examples:\n\n### Decoding bot API file IDs\n\n```php\nuse danog\\Decoder\\FileId;\nuse danog\\Decoder\\UniqueFileId;\n\n$fileId = FileId::fromBotAPI('CAACAgQAAxkDAAJEsl44nl3yxPZ8biI8uhaA7rbQceOSAAKtAQACsTisUXvMEbVnTuQkGAQ');\n\n$version = $fileId-\u003eversion; // bot API file ID version, usually 4\n$subVersion = $fileId-\u003esubVersion; // bot API file ID subversion, equivalent to a specific tdlib version\n\n$dcId = $fileId-\u003edcId; // On which datacenter is this file stored\n\n$type = $fileId-\u003etype; // File type\n\n$id = $fileId-\u003eid;\n$accessHash = $fileId-\u003eaccessHash;\n\n$fileReference = $fileId-\u003efileReference; // File reference, https://core.telegram.org/api/file_reference\n$url = $fileId-\u003eurl; // URL, file IDs with encoded webLocation\n\n// You can also use hasFileReference and hasUrl\n$fileIdReencoded = $fileId-\u003egetBotAPI(); // CAACAgQAAxkDAAJEsl44nl3yxPZ8biI8uhaA7rbQceOSAAKtAQACsTisUXvMEbVnTuQkGAQ\n$fileIdReencoded = (string) $fileId;     // CAACAgQAAxkDAAJEsl44nl3yxPZ8biI8uhaA7rbQceOSAAKtAQACsTisUXvMEbVnTuQkGAQ\n\n// For photos, thumbnails if ($fileId-\u003egetType() \u003c= FileIdType::PHOTO-\u003evalue)\n$volumeId = $fileId-\u003evolumeId;\n$localId = $fileId-\u003elocalId;\n\n$photoSizeSource = $fileId-\u003ephotoSizeSource; // PhotoSizeSource object\n$photoSizeSource-\u003edialogId;\n$photoSizeSource-\u003estickerSetId;\n\n// And more, depending on photosize source\n```\n\nThe bot API subversion, present since file IDs v4, is equivalent to the [version of tdlib](https://github.com/tdlib/td/blob/master/td/telegram/Version.h#L13) used server-side in the bot API.\n\nFor file types, see [file types](#bot-api-file-id-types).\nFor photosize source, see [here](#photosize-source).\n\n### Decoding bot API unique file IDs\n\n```php\n$uniqueFileId = UniqueFileId::fromUniqueBotAPI('AgADrQEAArE4rFE');\n\n$type = $fileId-\u003etype; // Unique file type\n\n$id = $uniqueFileId-\u003eid;\n$url = $uniqueFileId-\u003eurl; // URL, for unique file IDs with encoded webLocation\n\n// For photos\n$volumeId = $uniqueFileId-\u003evolumeId;\n$localId = $uniqueFileId-\u003elocalId;\n```\n\nFor unique file types, see [unique types](#bot-api-unique-file-id-types).\n\n### Extracting unique file IDs from full file IDs\n\n```php\n$full = 'CAACAgQAAxkDAAJEsl44nl3yxPZ8biI8uhaA7rbQceOSAAKtAQACsTisUXvMEbVnTuQkGAQ';\n$unique = 'AgADrQEAArE4rFE';\n\n$fileId = FileId::fromBotAPI($full);\n$uniqueFileId = UniqueFileId::fromUniqueBotAPI($unique);\n$uniqueFileIdExtracted1 = UniqueFileId::fromBotAPI($full);\n\n$uniqueFileIdExtracted2 = $fileId-\u003egetUniqueBotAPI();\n\nvar_dump(((string) $uniqueFileId) === ((string) $uniqueFileIdExtracted1)); // true, always AgADrQEAArE4rFE!\nvar_dump(((string) $uniqueFileId) === ((string) $uniqueFileIdExtracted2)); // true, always AgADrQEAArE4rFE!\n```\n\n### Photosize source\n\n```php\n$fileId = FileId::fromString('CAACAgQAAxkDAAJEsl44nl3yxPZ8biI8uhaA7rbQceOSAAKtAQACsTisUXvMEbVnTuQkGAQ');\n\n$photoSizeSource = $fileId-\u003ephotoSizeSource; // PhotoSizeSource object\n\n$sourceType = $photoSizeSource-\u003etype;\n\n// If $sourceType === PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL|PHOTOSIZE_SOURCE_DIALOGPHOTO_SMALL or \n// If $photoSizeSource instanceof PhotoSizeSourceDialogPhoto\n$dialogId = $photoSizeSource-\u003edialogId;\n$dialogId = $photoSizeSource-\u003esticketSetId;\n```\n\nThe `PhotoSizeSource` abstract base class indicates the source of a specific photosize from a chat photo, photo, stickerset thumbnail, file thumbnail.\n\nClick [here \u0026raquo;](https://github.com/danog/tg-file-decoder/blob/master/docs/index.md) to view the full list of `PhotoSizeSource` types.  \n\n### Building custom file IDs\n\n```php\n$fileId = new FileId(\n    type: FileIdType::STICKER,\n    id: $id,\n    accessHash: $accessHash,\n    // and so on...\n);\n\n$encoded = (string) $fileId; // CAACAgQAAxkDAAJEsl44nl3yxPZ8biI8uhaA7rbQceOSAAKtAQACsTisUXvMEbVnTuQkGAQ, or something\n```\n\n### Bot API file ID types\n\nThe file type is a PHP enum indicating the type of file, [danog\\Decoder\\FileIdType](https://github.com/danog/tg-file-decoder/blob/master/docs/danog/Decoder/FileIdType.md).  \n\nClick [here \u0026raquo;](https://github.com/danog/tg-file-decoder/blob/master/docs/danog/Decoder/FileIdType.md) to view the full list of file ID types.  \n\nThe enum also offers a `FileIdType::from` method that can be used to obtain the correct case, from a string version of the file type, typically the one used in bot API file objects.  \n\n### Bot API unique file ID types\n\nThe unique file type is a PHP enum uniquely indicating the unique file, [danog\\Decoder\\UniqueFileIdType](https://github.com/danog/tg-file-decoder/blob/master/docs/danog/Decoder/UniqueFileIdType.md).  \n\nClick [here \u0026raquo;](https://github.com/danog/tg-file-decoder/blob/master/docs/danog/Decoder/UniqueFileIdType.md) to view the full list of file ID types.  \n\n\n## Full API documentation\n\nClick [here \u0026raquo;](https://github.com/danog/tg-file-decoder/blob/master/docs/index.md) to view the full API documentation.  ","funding_links":["https://github.com/sponsors/danog"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanog%2Ftg-file-decoder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanog%2Ftg-file-decoder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanog%2Ftg-file-decoder/lists"}