shamimstack/tgsdk
Composer 安装命令:
composer require shamimstack/tgsdk
包简介
Laravel filesystem driver backed by Telegram channels with Python upload worker, chunking, channel rotation, and CDN streaming support.
README 文档
README
A Laravel 12 package that implements a custom filesystem driver backed by Telegram channels. Files are uploaded asynchronously through a Python worker (Pyrogram) via a Redis queue, and served back through a streaming proxy with optional CDN support.
Repository: https://github.com/shamimlaravel/tgsdk.git
Features
- Laravel Storage API — Use
Storage::disk('telegram')->put(),get(),url(),exists(),delete(),size(),mimeType()seamlessly. - Telegram-backed storage — Files are stored as messages in Telegram channels via MTProto (Pyrogram).
- Async upload pipeline — Laravel enqueues uploads to Redis; a Python worker handles the actual Telegram upload.
- Unlimited file size — Intelligent chunking splits files beyond Telegram's 2 GB / 4 GB limits into ordered parts.
- Channel rotation — Distributes uploads across multiple Telegram channels (round-robin, least-used, capacity-aware).
- Multi-account session pooling — Multiple Pyrogram sessions for parallel uploads and throughput multiplication.
- Streaming proxy — Download files through a Laravel controller that streams directly from Telegram.
- Optional CDN — Prepend a CDN base URL to download links for edge caching.
- Signed URLs — Optional signed download URLs with configurable expiration.
- Chunk compression — Optional gzip compression per chunk (skips already-compressed formats).
- Chunk encryption — Optional AES-256-GCM encryption per chunk with unique IVs.
- Integrity verification — SHA-256 checksums for both whole files and individual chunks.
- Resumable uploads — Failed chunks are re-enqueued without re-uploading completed ones.
Requirements
- PHP 8.4+
- Laravel 12
- Redis
- Python 3.11+ (for the upload worker)
Installation
1. Install the Laravel package
composer require shamimstack/tgsdk
2. Publish configuration and migrations
php artisan vendor:publish --tag=telegram-storage-config php artisan vendor:publish --tag=telegram-storage-migrations php artisan migrate
3. Add the disk to config/filesystems.php
'disks' => [ // ... 'telegram' => [ 'driver' => 'telegram', ], ],
4. Set environment variables
# Telegram API credentials TELEGRAM_API_ID=your_api_id TELEGRAM_API_HASH=your_api_hash TELEGRAM_BOT_TOKEN=your_bot_token TELEGRAM_SESSION_NAME=telegram_storage # Redis TELEGRAM_STORAGE_REDIS_CONNECTION=default TELEGRAM_STORAGE_REDIS_QUEUE=telegram_upload_queue # Worker callback TELEGRAM_STORAGE_CALLBACK_URL=https://your-app.com/telegram-storage/callback TELEGRAM_STORAGE_CALLBACK_SECRET=your_hmac_secret # Channels (configure in config/telegram-storage.php)
5. Set up the Python worker
cd python-worker cp .env.example .env # Edit .env with your credentials pip install -r requirements.txt python worker.py
Or use Docker:
cd python-worker docker build -t telegram-worker . docker run --env-file .env telegram-worker
Usage
Basic file operations
use Illuminate\Support\Facades\Storage; // Upload a file Storage::disk('telegram')->put('documents/report.pdf', $fileContents); // Upload from a stream Storage::disk('telegram')->putStream('videos/clip.mp4', fopen('/path/to/file', 'r')); // Check if file exists $exists = Storage::disk('telegram')->exists('documents/report.pdf'); // Get file contents (downloads from Telegram) $contents = Storage::disk('telegram')->get('documents/report.pdf'); // Get a public/signed download URL $url = Storage::disk('telegram')->url('documents/report.pdf'); // Get file metadata $size = Storage::disk('telegram')->size('documents/report.pdf'); $mime = Storage::disk('telegram')->mimeType('documents/report.pdf'); // Delete a file Storage::disk('telegram')->delete('documents/report.pdf');
Event listeners
use Shamimstack\Tgsdk\Events\TelegramUploadCompleted; use Shamimstack\Tgsdk\Events\TelegramUploadFailed;
// In EventServiceProvider or via Event::listen() Event::listen(TelegramUploadCompleted::class, function ($event) { Log::info("File uploaded: {$event->path}", ['file_id' => $event->fileId]); });
Event::listen(TelegramUploadFailed::class, function ($event) { Log::error("Upload failed: {$event->path}", ['error' => $event->error]); });
### Available events
| Event | Triggered When |
|---|---|
| `TelegramUploadQueued` | File upload job dispatched to Redis |
| `TelegramUploadCompleted` | Upload confirmed successful |
| `TelegramUploadFailed` | Upload failed after all retries |
| `TelegramChunkCompleted` | Individual chunk upload confirmed |
| `TelegramChunkFailed` | Individual chunk upload failed |
| `TelegramUploadStalled` | Upload detected as stalled |
| `TelegramFileDeleted` | File record deleted |
## Configuration
Key configuration options in `config/telegram-storage.php`:
| Option | Default | Description |
|---|---|---|
| `channels` | `[]` | List of Telegram channel IDs for storage |
| `rotation_strategy` | `round-robin` | Channel selection: `round-robin`, `least-used`, `capacity-aware` |
| `chunk_threshold` | `1950000000` | File size (bytes) above which chunking activates |
| `chunk_size` | `1950000000` | Size of each chunk |
| `chunk_compression` | `false` | Enable gzip compression per chunk |
| `chunk_encryption` | `false` | Enable AES-256-GCM encryption per chunk |
| `download.signed_urls` | `false` | Enable signed download URLs |
| `download.url_ttl` | `3600` | Signed URL TTL in seconds |
| `cdn.enabled` | `false` | Enable CDN URL prefix |
## Architecture
Laravel App Python Worker ┌─────────────────┐ ┌──────────────────┐ │ Storage::put() │ │ worker.py │ │ │ │ │ │ │ │ ▼ │ Redis │ ▼ │ │ TelegramStorage ├──────────►│ SessionPool │ │ Adapter │ Queue │ │ │ │ │ │ │ ▼ │ │ ▼ │ │ uploader.py │ │ Metadata DB │◄──────────│ │ │ │ │ Callback │ ▼ │ └─────────────────┘ │ Telegram API │ └──────────────────┘
## Testing
```bash
composer test
License
MIT
shamimstack/tgsdk 适用场景与选型建议
shamimstack/tgsdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「filesystem」 「storage」 「cdn」 「streaming」 「laravel」 「Flysystem」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shamimstack/tgsdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shamimstack/tgsdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shamimstack/tgsdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A SDK for working with B2 cloud storage.
A PHP class providing static methods for reading, writing, copying, moving, and deleting files and directories, MIME type detection, image size detection, and file permission management
Small library to access Microsoft Windows Azure Blob Storage with a Service or a StreamWrapper.
The flysystem adapter for yandex disk rest api.
A sleek PHP wrapper around rclone with Laravel-style fluent API syntax
phpABLE file-system library
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 39
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-08