-
-
Notifications
You must be signed in to change notification settings - Fork 142
-
inputMediaPhoto allows you to attach media files using attach:// keyword. How can I send multiple photos from local storage (not publicly accessible, not S3). Basically, I need to provide path to file in order for telegram to upload it (same way as photo does) but for multiple instances
$max = 10; $photos = $galleryPhotos->when($galleryPhotos->count() > $max, function ($collection) use ($max) { return $collection->random($max); })->map(function ($photo) { return [ 'type' => 'photo', 'media' => 'attach://' . $photo->hash, ]; }); $this->chat->mediaGroup($photos->toArray())->???->send();
I guess I need to pass every photo hash into data (using withData?) array with uploaded file content, but I couldn't figure it out, how to chain methods properly. I need to access file property of telegraph class and I see no way how can I achieve this
Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions
Was able to achieve this by overriding proivder
// AppServiceProvider public function register(): void { $this->app->bind('telegraph', fn () => new CustomTelegraph); }
// CustomTelegraph <?php declare(strict_types=1); namespace App\Services\Telegram; use DefStudio\Telegraph\DTO\Attachment; use DefStudio\Telegraph\Telegraph; class CustomTelegraph extends Telegraph { public function withFile(string $key, string $path) { $telegraph = clone $this; $this->files->put($key, new Attachment($path)); return $telegraph; } }
// handler $max = 10; $photos = $galleryPhotos->when($galleryPhotos->count() > $max, function ($collection) use...
Replies: 1 comment
-
Was able to achieve this by overriding proivder
// AppServiceProvider public function register(): void { $this->app->bind('telegraph', fn () => new CustomTelegraph); }
// CustomTelegraph <?php declare(strict_types=1); namespace App\Services\Telegram; use DefStudio\Telegraph\DTO\Attachment; use DefStudio\Telegraph\Telegraph; class CustomTelegraph extends Telegraph { public function withFile(string $key, string $path) { $telegraph = clone $this; $this->files->put($key, new Attachment($path)); return $telegraph; } }
// handler $max = 10; $photos = $galleryPhotos->when($galleryPhotos->count() > $max, function ($collection) use ($max) { return $collection->random($max); }); $request = $this->chat->mediaGroup($photos->map(function ($photo) { return [ 'type' => 'photo', 'media' => 'attach://'.$photo->hash, ]; })->toArray()); foreach ($photos as $photo) { $request->withFile($photo->hash, Storage::path($photo->physicalPath())); } $request->send();
Beta Was this translation helpful? Give feedback.