Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How can I send mediaGroup with uploaded files (no public url allowed, signed urls is not an option) #714

Answered by czernika
czernika asked this question in Q&A
Discussion options

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

You must be logged in to vote

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

Comment options

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();
You must be logged in to vote
0 replies
Answer selected by fabio-ivona
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /