diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e0613a..ab42a58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ - New #58: Add `setStickerPositionInSet`, `setStickerEmojiList`, `setStickerKeywords` and `setStickerMaskPosition` methods. - New #60: Add `setStickerSetTitle` method. +- New #61: Add `setStickerSetThumbnail` method. - Chg #24: Move update methods to `Vjik\TelegramBot\Api\Method\Update` namespace, and update types to `Vjik\TelegramBot\Api\Type\Update` namespace. - Chg #30: Remove `TelegramRequestWithFilesInterface`. diff --git a/src/Method/Sticker/SetStickerSetThumbnail.php b/src/Method/Sticker/SetStickerSetThumbnail.php new file mode 100644 index 0000000..e86135d --- /dev/null +++ b/src/Method/Sticker/SetStickerSetThumbnail.php @@ -0,0 +1,53 @@ + $this->name, + 'user_id' => $this->userId, + 'thumbnail' => $this->thumbnail, + 'format' => $this->format, + ], + static fn(mixed $value): bool => $value !== null, + ); + } + + public function prepareResult(mixed $result): true + { + ValueHelper::assertTrueResult($result); + return $result; + } +} diff --git a/src/TelegramBotApi.php b/src/TelegramBotApi.php index 564b09a..36049c2 100644 --- a/src/TelegramBotApi.php +++ b/src/TelegramBotApi.php @@ -79,6 +79,7 @@ use Vjik\TelegramBot\Api\Method\Sticker\SetStickerKeywords; use Vjik\TelegramBot\Api\Method\Sticker\SetStickerMaskPosition; use Vjik\TelegramBot\Api\Method\Sticker\SetStickerPositionInSet; +use Vjik\TelegramBot\Api\Method\Sticker\SetStickerSetThumbnail; use Vjik\TelegramBot\Api\Method\Sticker\SetStickerSetTitle; use Vjik\TelegramBot\Api\Method\Sticker\UploadStickerFile; use Vjik\TelegramBot\Api\Method\UnbanChatMember; @@ -1647,6 +1648,27 @@ public function setStickerPositionInSet(string $sticker, int $position): FailRes return $this->send(new SetStickerPositionInSet($sticker, $position)); } + /** + * @see https://core.telegram.org/bots/api#setstickersetthumbnail + * + * @psalm-suppress MixedInferredReturnType,MixedReturnStatement + */ + public function setStickerSetThumbnail( + string $name, + int $userId, + string $format, + InputFile|string|null $thumbnail = null, + ): FailResult|true { + return $this->send( + new SetStickerSetThumbnail( + $name, + $userId, + $format, + $thumbnail + ) + ); + } + /** * @see https://core.telegram.org/bots/api#setstickersettitle * diff --git a/tests/Method/Sticker/SetStickerSetThumbnailTest.php b/tests/Method/Sticker/SetStickerSetThumbnailTest.php new file mode 100644 index 0000000..ef7832e --- /dev/null +++ b/tests/Method/Sticker/SetStickerSetThumbnailTest.php @@ -0,0 +1,57 @@ +assertSame(HttpMethod::POST, $method->getHttpMethod()); + $this->assertSame('setStickerSetThumbnail', $method->getApiMethod()); + $this->assertSame( + [ + 'name' => 'animals_by_my_bot', + 'user_id' => 123, + 'format' => 'static', + ], + $method->getData(), + ); + } + + public function testFull(): void + { + $file = new InputFile((new StreamFactory())->createStream()); + $method = new SetStickerSetThumbnail('animals_by_my_bot', 123, 'static', $file); + + $this->assertSame(HttpMethod::POST, $method->getHttpMethod()); + $this->assertSame('setStickerSetThumbnail', $method->getApiMethod()); + $this->assertSame( + [ + 'name' => 'animals_by_my_bot', + 'user_id' => 123, + 'thumbnail' => $file, + 'format' => 'static', + ], + $method->getData(), + ); + } + + public function testPrepareResult(): void + { + $method = new SetStickerSetThumbnail('animals_by_my_bot', 123, 'static'); + + $preparedResult = $method->prepareResult(true); + + $this->assertTrue($preparedResult); + } +} diff --git a/tests/TelegramBotApiTest.php b/tests/TelegramBotApiTest.php index 675399f..a5ac43a 100644 --- a/tests/TelegramBotApiTest.php +++ b/tests/TelegramBotApiTest.php @@ -1302,6 +1302,18 @@ public function testSetStickerPositionInSet(): void $this->assertTrue($result); } + public function testSetStickerSetThumbnail(): void + { + $api = $this->createApi([ + 'ok' => true, + 'result' => true, + ]); + + $result = $api->setStickerSetThumbnail('animals_by_boy', 123, 'static'); + + $this->assertTrue($result); + } + public function testSetStickerSetTitle(): void { $api = $this->createApi([