Repository: defstudio/telegraph (php)

Issue:
How to send/edit mediaGroup message?
Hello.
Can you tell me how to send media group files using a package? 
https://core.telegram.org/bots/api#sendmediagroup

Pull request description:
#498 implement sendMediaGroup method
close #498 implement sendMediaGroup method

Patch:
diff --git a/docs/12.features/7.attachments.md b/docs/12.features/7.attachments.md
index e99bd7f9..d43ae93c 100644
--- a/docs/12.features/7.attachments.md
+++ b/docs/12.features/7.attachments.md
@@ -213,3 +213,20 @@ Telegraph::document(Storage::path('brochure.pdf'))
     ->thumbnail(Storage::path('brochure_thumbnail.jpg'))
     ->send();
 ```
+
+### Media Group
+
+Group of photos, videos, documents or audios as an album can be sent through Telegraph `->mediaGroup()` method:
+
+```php
+Telegraph::mediaGroup([
+        [
+            'type' => 'photo',
+            'media' => 'https://my-repository/photo1.jpg',
+        ],
+        [
+            'type' => 'photo',
+            'media' => 'https://my-repository/photo2.jpg',
+        ]              
+])->send();
+```
diff --git a/docs/12.features/8.telegram-api-calls.md b/docs/12.features/8.telegram-api-calls.md
index f14c0bac..f533b6a5 100644
--- a/docs/12.features/8.telegram-api-calls.md
+++ b/docs/12.features/8.telegram-api-calls.md
@@ -220,6 +220,23 @@ sends a photo
 Telegraph::photo($pathToPhotoFile)->send();
 ```
 
+### Media Group
+
+sends a group of photos, videos, documents or audios as an album
+
+```php
+Telegraph::mediaGroup([
+        [
+            'type' => 'photo',
+            'media' => 'https://my-repository/photo1.jpg',
+        ],
+        [
+            'type' => 'photo',
+            'media' => 'https://my-repository/photo2.jpg',
+        ]              
+])->send();
+```
+
 ## registerBotCommands
 
 register commands in Telegram Bot in order to display them to the user when the "/" key is pressed
diff --git a/docs/13.models/2.telegraph-chat.md b/docs/13.models/2.telegraph-chat.md
index 2d18a56e..81175b85 100644
--- a/docs/13.models/2.telegraph-chat.md
+++ b/docs/13.models/2.telegraph-chat.md
@@ -600,3 +600,20 @@ $telegraphChat->setMenuButton()->default()->send(); //restore default
 $telegraphChat->setMenuButton()->commands()->send(); //show bot commands in menu button 
 $telegraphChat->setMenuButton()->webApp("Web App", "https://my-web.app")->send(); //show start web app button 
 ```
+
+### `Media Group`
+
+Group of photos, videos, documents or audios as an album can be sent through Telegraph `->mediaGroup()` method:
+
+```php
+$telegraphChat->mediaGroup([
+        [
+            'type' => 'photo',
+            'media' => 'https://my-repository/photo1.jpg',
+        ],
+        [
+            'type' => 'photo',
+            'media' => 'https://my-repository/photo2.jpg',
+        ]              
+])->send();
+```
diff --git a/src/Concerns/SendsAttachments.php b/src/Concerns/SendsAttachments.php
index 34fc23e2..df67925d 100644
--- a/src/Concerns/SendsAttachments.php
+++ b/src/Concerns/SendsAttachments.php
@@ -181,7 +181,7 @@ trait SendsAttachments
         $telegraph = clone $this;
 
         if (File::exists($path)) {
-            /* @phpstan-ignore-next-line  */
+            /* @phpstan-ignore-next-line */
             $maxSizeKb = floatval(config('telegraph.attachments.thumbnail.max_size_kb', 200));
 
             if (($size = $telegraph->fileSizeInKb($path)) > $maxSizeKb) {
@@ -236,6 +236,22 @@ trait SendsAttachments
         return $telegraph;
     }
 
+    /**
+     * @param array<int|string, array<mixed>> $mediaInputs
+     */
+    public function mediaGroup(array $mediaInputs): self
+    {
+        $telegraph = clone $this;
+
+        $telegraph->endpoint = self::ENDPOINT_SEND_MEDIA_GROUP;
+
+        $telegraph->data['chat_id'] = $telegraph->getChatId();
+
+        $telegraph->data['media'] = $mediaInputs;
+
+        return $telegraph;
+    }
+
     private function imageHeight(string $path): int
     {
         return $this->imageDimensions($path)[1];
@@ -374,7 +390,7 @@ trait SendsAttachments
     protected function attachAudio(self $telegraph, string $path, ?string $filename): void
     {
         if (File::exists($path)) {
-            /* @phpstan-ignore-next-line  */
+            /* @phpstan-ignore-next-line */
             $maxSizeMb = floatval(config('telegraph.attachments.audio.max_size_mb', 50));
 
             if (($size = $telegraph->fileSizeInMb($path)) > $maxSizeMb) {
@@ -398,7 +414,7 @@ trait SendsAttachments
     protected function attachDocument(self $telegraph, string $path, ?string $filename): void
     {
         if (File::exists($path)) {
-            /* @phpstan-ignore-next-line  */
+            /* @phpstan-ignore-next-line */
             $maxSizeMb = floatval(config('telegraph.attachments.document.max_size_mb', 50));
 
             if (($size = $telegraph->fileSizeInMb($path)) > $maxSizeMb) {
diff --git a/src/Facades/Telegraph.php b/src/Facades/Telegraph.php
index 7c043185..7cfede50 100644
--- a/src/Facades/Telegraph.php
+++ b/src/Facades/Telegraph.php
@@ -49,6 +49,7 @@ use Illuminate\Support\Facades\Facade;
  * @method static \DefStudio\Telegraph\Telegraph  video(string $path, string $filename = null)
  * @method static \DefStudio\Telegraph\Telegraph  audio(string $path, string $filename = null)
  * @method static \DefStudio\Telegraph\Telegraph  dice()
+ * @method static \DefStudio\Telegraph\Telegraph  mediaGroup(string $path, array $media)
  * @method static \DefStudio\Telegraph\Telegraph  botUpdates()
  * @method static \DefStudio\Telegraph\Telegraph  botInfo()
  * @method static \DefStudio\Telegraph\Telegraph  setBaseUrl(string|null $url)
diff --git a/src/Models/TelegraphChat.php b/src/Models/TelegraphChat.php
index f5836c79..8afd38fc 100644
--- a/src/Models/TelegraphChat.php
+++ b/src/Models/TelegraphChat.php
@@ -223,6 +223,14 @@ class TelegraphChat extends Model implements Storable
         return TelegraphFacade::chat($this)->photo($path, $filename);
     }
 
+    /**
+     * @param array<int|string, array<mixed>> $media
+     */
+    public function mediaGroup(array $media): Telegraph
+    {
+        return TelegraphFacade::chat($this)->mediaGroup($media);
+    }
+
     public function animation(string $path, string $filename = null): Telegraph
     {
         return TelegraphFacade::chat($this)->animation($path, $filename);
diff --git a/src/Telegraph.php b/src/Telegraph.php
index 244ff099..aea48cae 100755
--- a/src/Telegraph.php
+++ b/src/Telegraph.php
@@ -71,6 +71,7 @@ class Telegraph
     public const ENDPOINT_SEND_LOCATION = 'sendLocation';
     public const ENDPOINT_SEND_ANIMATION = 'sendAnimation';
     public const ENDPOINT_SEND_VOICE = 'sendVoice';
+    public const ENDPOINT_SEND_MEDIA_GROUP = 'sendMediaGroup';
     public const ENDPOINT_SEND_CHAT_ACTION = 'sendChatAction';
     public const ENDPOINT_SEND_DOCUMENT = 'sendDocument';
     public const ENDPOINT_SEND_PHOTO = 'sendPhoto';


Test patch:
diff --git a/tests/Unit/Models/TelegraphChatTest.php b/tests/Unit/Models/TelegraphChatTest.php
index c825ff38..a5298b68 100644
--- a/tests/Unit/Models/TelegraphChatTest.php
+++ b/tests/Unit/Models/TelegraphChatTest.php
@@ -749,3 +749,32 @@ it('can edit Telegraph data after sending a media ', function () {
         'caption' => 'test',
     ]);
 });
+
+it('can send a mediaGroup from remote url', function () {
+    Telegraph::fake();
+    $chat = make_chat();
+
+    $chat->mediaGroup([
+        [
+            'type' => 'photo',
+            'media' => 'https://test.dev/photo.jpg',
+        ],
+        [
+            'type' => 'photo',
+            'media' => 'https://test.dev/photo.jpg',
+        ],
+    ])->send();
+
+    Telegraph::assertSentData(\DefStudio\Telegraph\Telegraph::ENDPOINT_SEND_MEDIA_GROUP, [
+        'media' => [
+            [
+                'type' => 'photo',
+                'media' => 'https://test.dev/photo.jpg',
+            ],
+            [
+                'type' => 'photo',
+                'media' => 'https://test.dev/photo.jpg',
+            ],
+        ],
+    ]);
+});