Repository: defstudio/telegraph (php)

Issue:
Implement `dice` method
ref 

https://core.telegram.org/bots/api#senddice

Pull request:
implemented the sendDice method , doc and test(with relative snapshot)
close #189 implemented the sendDice method , doc and test(with relative snapshot)

Patch:
diff --git a/docs/content/en/features/attachments.md b/docs/content/en/features/attachments.md
index fb37c867..99cf821e 100644
--- a/docs/content/en/features/attachments.md
+++ b/docs/content/en/features/attachments.md
@@ -51,6 +51,20 @@ A location attachment can be sent through Telegraph `->location()` method:
 Telegraph::location(12.345, -54.321)->send();
 ```
 
+### Dice
+
+An animated emoji attachment that will display a random value can be sent through Telegraph `->dice()` method:
+
+```php
+Telegraph::dice()->send();
+```
+
+Different items can be used as "dice"
+
+```php
+Telegraph::dice(\DefStudio\Telegraph\Enums\Emojis::SLOT_MACHINE)->send();
+```
+
 ## Options
 
 When sending files, some options are available:
diff --git a/src/Concerns/SendsAttachments.php b/src/Concerns/SendsAttachments.php
index d3b0819c..aa9522ae 100644
--- a/src/Concerns/SendsAttachments.php
+++ b/src/Concerns/SendsAttachments.php
@@ -223,4 +223,18 @@ trait SendsAttachments
 
         return ceil($sizeInKBytes * 100) / 100;
     }
+
+    public function dice(string $emoji = null): Telegraph
+    {
+        $telegraph = clone $this;
+
+        $telegraph->endpoint = self::ENDPOINT_DICE;
+        $telegraph->data['chat_id'] = $telegraph->getChat()->chat_id;
+
+        if ($emoji !== null) {
+            $telegraph->data['emoji'] = $emoji;
+        }
+
+        return $telegraph;
+    }
 }
diff --git a/src/Enums/Emojis.php b/src/Enums/Emojis.php
new file mode 100644
index 00000000..52967942
--- /dev/null
+++ b/src/Enums/Emojis.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace DefStudio\Telegraph\Enums;
+
+class Emojis
+{
+    public const DICE = '🎲';
+    public const ARROW = '🎯';
+    public const BASKETBALL = '🏀';
+    public const FOOTBALL = '⚽';
+    public const BOWLING = '🎳';
+    public const SLOT_MACHINE = '🎰';
+}
diff --git a/src/Facades/Telegraph.php b/src/Facades/Telegraph.php
index d9100760..ef01cdd3 100644
--- a/src/Facades/Telegraph.php
+++ b/src/Facades/Telegraph.php
@@ -39,6 +39,7 @@ use Illuminate\Support\Facades\Facade;
  * @method static \DefStudio\Telegraph\Telegraph  photo(string $path, string $filename = null)
  * @method static \DefStudio\Telegraph\Telegraph  voice(string $path, string $filename = null)
  * @method static \DefStudio\Telegraph\Telegraph  location(float $latitude, float $longitude)
+ * @method static \DefStudio\Telegraph\Telegraph  dice()
  * @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/Telegraph.php b/src/Telegraph.php
index 72d6b887..078e6bf9 100755
--- a/src/Telegraph.php
+++ b/src/Telegraph.php
@@ -97,6 +97,7 @@ class Telegraph
     public const ENDPOINT_FORWARD_MESSAGE = 'forwardMessage';
     public const ENDPOINT_GET_USER_PROFILE_PHOTOS = 'getUserProfilePhotos';
     public const ENDPOINT_GET_CHAT_MENU_BUTTON = 'getChatMenuButton';
+    public const ENDPOINT_DICE = 'sendDice';
 
 
     /** @var array<string, mixed> */


Test patch:
diff --git a/tests/Unit/Concerns/SendsAttachmentsTest.php b/tests/Unit/Concerns/SendsAttachmentsTest.php
index a98eaa49..0053df35 100644
--- a/tests/Unit/Concerns/SendsAttachmentsTest.php
+++ b/tests/Unit/Concerns/SendsAttachmentsTest.php
@@ -2,6 +2,7 @@
 
 /** @noinspection PhpUnhandledExceptionInspection */
 
+use DefStudio\Telegraph\Enums\Emojis;
 use DefStudio\Telegraph\Exceptions\FileException;
 use DefStudio\Telegraph\Exceptions\TelegraphException;
 use DefStudio\Telegraph\Facades\Telegraph as TelegraphFacade;
@@ -14,6 +15,23 @@ it('can send a document', function () {
         ->toMatchTelegramSnapshot();
 });
 
+it('can send a dice', function () {
+    expect(fn (Telegraph $telegraph) => $telegraph->dice())
+        ->toMatchTelegramSnapshot();
+});
+
+it('can send a dice with different emojis', function (string $emoji) {
+    expect(fn (Telegraph $telegraph) => $telegraph->dice($emoji))
+        ->toMatchTelegramSnapshot();
+})->with([
+    'DICE' => Emojis::DICE,
+    'ARROW' => Emojis::ARROW,
+    'BASKETBALL' => Emojis::BASKETBALL,
+    'FOOTBALL' => Emojis::FOOTBALL,
+    'BOWLING' => Emojis::BOWLING,
+    'SLOT_MACHINE' => Emojis::SLOT_MACHINE,
+]);
+
 it('requires a chat to send a document', function () {
     TelegraphFacade::document(Storage::path('test.txt'));
 })->throws(TelegraphException::class, 'No TelegraphChat defined for this request');
diff --git a/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice__1.yml b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice__1.yml
new file mode 100644
index 00000000..423945c8
--- /dev/null
+++ b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice__1.yml
@@ -0,0 +1,4 @@
+url: 'https://api.telegram.org/bot3f3814e1-5836-3d77-904e-60f64b15df36/sendDice'
+payload:
+    chat_id: '-123456789'
+files: {  }
diff --git a/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_ARROW__1.yml b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_ARROW__1.yml
new file mode 100644
index 00000000..1c10bb5b
--- /dev/null
+++ b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_ARROW__1.yml
@@ -0,0 +1,5 @@
+url: 'https://api.telegram.org/bot3f3814e1-5836-3d77-904e-60f64b15df36/sendDice'
+payload:
+    chat_id: '-123456789'
+    emoji: 🎯
+files: {  }
diff --git a/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_BASKETBALL__1.yml b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_BASKETBALL__1.yml
new file mode 100644
index 00000000..b72a85a8
--- /dev/null
+++ b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_BASKETBALL__1.yml
@@ -0,0 +1,5 @@
+url: 'https://api.telegram.org/bot3f3814e1-5836-3d77-904e-60f64b15df36/sendDice'
+payload:
+    chat_id: '-123456789'
+    emoji: 🏀
+files: {  }
diff --git a/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_BOWLING__1.yml b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_BOWLING__1.yml
new file mode 100644
index 00000000..f7da9521
--- /dev/null
+++ b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_BOWLING__1.yml
@@ -0,0 +1,5 @@
+url: 'https://api.telegram.org/bot3f3814e1-5836-3d77-904e-60f64b15df36/sendDice'
+payload:
+    chat_id: '-123456789'
+    emoji: 🎳
+files: {  }
diff --git a/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_DICE__1.yml b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_DICE__1.yml
new file mode 100644
index 00000000..bc8b1e32
--- /dev/null
+++ b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_DICE__1.yml
@@ -0,0 +1,5 @@
+url: 'https://api.telegram.org/bot3f3814e1-5836-3d77-904e-60f64b15df36/sendDice'
+payload:
+    chat_id: '-123456789'
+    emoji: 🎲
+files: {  }
diff --git a/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_FOOTBALL__1.yml b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_FOOTBALL__1.yml
new file mode 100644
index 00000000..aedd00bf
--- /dev/null
+++ b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_FOOTBALL__1.yml
@@ -0,0 +1,5 @@
+url: 'https://api.telegram.org/bot3f3814e1-5836-3d77-904e-60f64b15df36/sendDice'
+payload:
+    chat_id: '-123456789'
+    emoji: ⚽
+files: {  }
diff --git a/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_SLOT_MACHINE__1.yml b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_SLOT_MACHINE__1.yml
new file mode 100644
index 00000000..5185bb5a
--- /dev/null
+++ b/tests/__snapshots__/SendsAttachmentsTest__it_can_send_a_dice_with_different_emojis_with_data_set_SLOT_MACHINE__1.yml
@@ -0,0 +1,5 @@
+url: 'https://api.telegram.org/bot3f3814e1-5836-3d77-904e-60f64b15df36/sendDice'
+payload:
+    chat_id: '-123456789'
+    emoji: 🎰
+files: {  }