diff --git a/CHANGELOG.md b/CHANGELOG.md index b84e763..6fb63c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ - New #60: Add `setStickerSetTitle` method. - New #61: Add `setStickerSetThumbnail` method. - New #62: Add `setCustomEmojiStickerSetThumbnail` method. +- New #63: Add `setChatStickerSet` and `deleteChatStickerSet` methods. - 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/DeleteChatStickerSet.php b/src/Method/DeleteChatStickerSet.php new file mode 100644 index 0000000..c5e1389 --- /dev/null +++ b/src/Method/DeleteChatStickerSet.php @@ -0,0 +1,43 @@ + $this->chatId, + ]; + } + + public function prepareResult(mixed $result): true + { + ValueHelper::assertTrueResult($result); + return $result; + } +} diff --git a/src/Method/SetChatStickerSet.php b/src/Method/SetChatStickerSet.php new file mode 100644 index 0000000..c393597 --- /dev/null +++ b/src/Method/SetChatStickerSet.php @@ -0,0 +1,45 @@ + $this->chatId, + 'sticker_set_name' => $this->stickerSetName, + ]; + } + + public function prepareResult(mixed $result): true + { + ValueHelper::assertTrueResult($result); + return $result; + } +} diff --git a/src/TelegramBotApi.php b/src/TelegramBotApi.php index 63fd811..041b70a 100644 --- a/src/TelegramBotApi.php +++ b/src/TelegramBotApi.php @@ -17,6 +17,7 @@ use Vjik\TelegramBot\Api\Method\CreateChatInviteLink; use Vjik\TelegramBot\Api\Method\DeclineChatJoinRequest; use Vjik\TelegramBot\Api\Method\DeleteChatPhoto; +use Vjik\TelegramBot\Api\Method\DeleteChatStickerSet; use Vjik\TelegramBot\Api\Method\DeleteMyCommands; use Vjik\TelegramBot\Api\Method\EditChatInviteLink; use Vjik\TelegramBot\Api\Method\ExportChatInviteLink; @@ -61,6 +62,7 @@ use Vjik\TelegramBot\Api\Method\SetChatMenuButton; use Vjik\TelegramBot\Api\Method\SetChatPermissions; use Vjik\TelegramBot\Api\Method\SetChatPhoto; +use Vjik\TelegramBot\Api\Method\SetChatStickerSet; use Vjik\TelegramBot\Api\Method\SetChatTitle; use Vjik\TelegramBot\Api\Method\SetMessageReaction; use Vjik\TelegramBot\Api\Method\SetMyCommands; @@ -364,6 +366,18 @@ public function deleteChatPhoto(int|string $chatId): FailResult|true ); } + /** + * @see https://core.telegram.org/bots/api#deletechatstickerset + * + * @psalm-suppress MixedInferredReturnType,MixedReturnStatement + */ + public function deleteChatStickerSet(int|string $chatId): FailResult|true + { + return $this->send( + new DeleteChatStickerSet($chatId) + ); + } + /** * @see https://core.telegram.org/bots/api#deletemycommands * @@ -1528,6 +1542,18 @@ public function setChatPhoto(int|string $chatId, InputFile $photo): FailResult|t ); } + /** + * @see https://core.telegram.org/bots/api#setchatstickerset + * + * @psalm-suppress MixedInferredReturnType,MixedReturnStatement + */ + public function setChatStickerSet(int|string $chatId, string $stickerSetName): FailResult|true + { + return $this->send( + new SetChatStickerSet($chatId, $stickerSetName) + ); + } + /** * @see https://core.telegram.org/bots/api#setchattitle * diff --git a/tests/Method/DeleteChatStickerSetTest.php b/tests/Method/DeleteChatStickerSetTest.php new file mode 100644 index 0000000..f3652ca --- /dev/null +++ b/tests/Method/DeleteChatStickerSetTest.php @@ -0,0 +1,35 @@ +assertSame(HttpMethod::POST, $method->getHttpMethod()); + $this->assertSame('deleteChatStickerSet', $method->getApiMethod()); + $this->assertSame( + [ + 'chat_id' => 1, + ], + $method->getData(), + ); + } + + public function testPrepareResult(): void + { + $method = new DeleteChatStickerSet(1); + + $preparedResult = $method->prepareResult(true); + + $this->assertTrue($preparedResult); + } +} diff --git a/tests/Method/SetChatStickerSetTest.php b/tests/Method/SetChatStickerSetTest.php new file mode 100644 index 0000000..5469419 --- /dev/null +++ b/tests/Method/SetChatStickerSetTest.php @@ -0,0 +1,36 @@ +assertSame(HttpMethod::POST, $method->getHttpMethod()); + $this->assertSame('setChatStickerSet', $method->getApiMethod()); + $this->assertSame( + [ + 'chat_id' => 1, + 'sticker_set_name' => 'animals_by_bot', + ], + $method->getData(), + ); + } + + public function testPrepareResult(): void + { + $method = new SetChatStickerSet(1, 'animals_by_bot'); + + $preparedResult = $method->prepareResult(true); + + $this->assertTrue($preparedResult); + } +} diff --git a/tests/TelegramBotApiTest.php b/tests/TelegramBotApiTest.php index ff28049..2dbb043 100644 --- a/tests/TelegramBotApiTest.php +++ b/tests/TelegramBotApiTest.php @@ -268,6 +268,18 @@ public function testDeleteChatPhoto(): void $this->assertTrue($result); } + public function testDeleteChatStickerSet(): void + { + $api = $this->createApi([ + 'ok' => true, + 'result' => true, + ]); + + $result = $api->deleteChatStickerSet(1); + + $this->assertTrue($result); + } + public function testDeleteMyCommands(): void { $api = $this->createApi([ @@ -1180,6 +1192,18 @@ public function testSetChatPhoto(): void $this->assertTrue($result); } + public function testSetChatStickerSet(): void + { + $api = $this->createApi([ + 'ok' => true, + 'result' => true, + ]); + + $result = $api->setChatStickerSet(1, 'animals_by_bot'); + + $this->assertTrue($result); + } + public function testSetChatTitle(): void { $api = $this->createApi([