diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e8472e5..739458d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file ## 3.0.0 - YYYY-MM-DD +- Add `\TelegramBot\Api\BotApi::replaceStickerInSet` api method - Add Added the parameter `business_connection_id` to `\TelegramBot\Api\BotApi` send methods - Add `\TelegramBot\Api\BotApi::getBusinessConnection` api method - Add `\TelegramBot\Api\Types\Update::$deletedBusinessMessages` field diff --git a/src/BotApi.php b/src/BotApi.php index 53a1ce07..3174e953 100644 --- a/src/BotApi.php +++ b/src/BotApi.php @@ -2,6 +2,7 @@ namespace TelegramBot\Api; +use TelegramBot\Api\Types\InputSticker; use TelegramBot\Api\Http\CurlHttpClient; use TelegramBot\Api\Types\UserChatBoosts; use TelegramBot\Api\Types\ReplyParameters; @@ -3248,6 +3249,33 @@ public function getBusinessConnection($businessConnectionId) ])); } + /** + * Use this method to replace an existing sticker in a sticker set with a new one. + * The method is equivalent to calling deleteStickerFromSet, then addStickerToSet, then setStickerPositionInSet. + * Returns True on success. + * + * @param int $userId User identifier of the sticker set owner + * @param string $name Sticker set name + * @param string $oldSticker File identifier of the replaced sticker + * @param InputSticker $sticker A JSON-serialized object with information about the added sticker. + * If exactly the same sticker had already been added to the set, then the set remains unchanged. + * + * @return bool + * @throws Exception + * + * @since Bot API 7.2 + * @auther bernard-ng + */ + public function replaceStickerInSet($userId, $name, $oldSticker, $sticker) + { + return $this->call('replaceStickerInSet', [ + 'user_id' => $userId, + 'name' => $name, + 'old_sticker' => $oldSticker, + 'sticker' => $sticker + ]); + } + /** * Set an option for a cURL transfer * diff --git a/src/Types/InputSticker.php b/src/Types/InputSticker.php new file mode 100644 index 00000000..d46b3fcb --- /dev/null +++ b/src/Types/InputSticker.php @@ -0,0 +1,164 @@ + + */ +class InputSticker extends BaseType implements TypeInterface +{ + /** + * {@inheritdoc} + * + * @var array + */ + protected static $requiredParams = ['sticker', 'format', 'emoji_list']; + + /** + * {@inheritdoc} + * + * @var array + */ + protected static $map = [ + 'sticker' => true, + 'format' => true, + 'emoji_list' => true, + 'mask_position' => MaskPosition::class, + 'keywords' => true, + ]; + + /** + * The added sticker. + * Pass a file_id as a String to send a file that already exists on the Telegram servers, + * pass an HTTP URL as a String for Telegram to get a file from the Internet, + * upload a new one using multipart/form-data, or pass “attach://” to upload a new one using multipart/form-data under name. + * Animated and video stickers can't be uploaded via HTTP URL. + * + * @var string + * @see https://core.telegram.org/bots/api#sending-files + */ + protected string $sticker; + + /** + * Format of the added sticker, must be one of “static” + * for a .WEBP or .PNG image, “animated” for a .TGS animation, “video” for a WEBM video + * + * @var string + */ + protected string $format; + + /** + * List of 1-20 emoji associated with the sticker + * + * @var string[] + */ + protected array $emojiList; + + /** + * Optional. Position where the mask should be placed on faces. For “mask” stickers only. + * + * @var MaskPosition|null + */ + protected $maskPosition; + + /** + * Optional. List of 0-20 search keywords for the sticker with total length of up to 64 characters. + * For “regular” and “custom_emoji” stickers only. + * + * @var string[] + */ + protected $keywords; + + /** + * @return string + */ + public function getSticker() + { + return $this->sticker; + } + + /** + * @param string $sticker + * @return void + */ + public function setSticker(string $sticker) + { + $this->sticker = $sticker; + } + + /** + * @return string + */ + public function getFormat() + { + return $this->format; + } + + /** + * @param string $format + * @return void + */ + public function setFormat(string $format) + { + $this->format = $format; + } + + /** + * @return string[] + */ + public function getEmojiList() + { + return $this->emojiList; + } + + /** + * @param string[] $emojiList + * @return void + */ + public function setEmojiList(array $emojiList) + { + $this->emojiList = $emojiList; + } + + /** + * @return MaskPosition|null + */ + public function getMaskPosition() + { + return $this->maskPosition; + } + + /** + * @param MaskPosition|null $maskPosition + * @return void + */ + public function setMaskPosition($maskPosition) + { + $this->maskPosition = $maskPosition; + } + + /** + * @return string[] + */ + public function getKeywords() + { + return $this->keywords; + } + + /** + * @param string[] $keywords + * @return void + */ + public function setKeywords(array $keywords) + { + $this->keywords = $keywords; + } +} diff --git a/tests/Types/BusinessConnectionTest.php b/tests/Types/BusinessConnectionTest.php index f45dae8b..9caa52a8 100644 --- a/tests/Types/BusinessConnectionTest.php +++ b/tests/Types/BusinessConnectionTest.php @@ -1,7 +1,5 @@ 'file', + 'format' => 'static', + 'emoji_list' => ['😀'] + ]; + } + + public static function getFullResponse() + { + return [ + 'sticker' => 'file', + 'format' => 'static', + 'emoji_list' => ['😀'], + 'mask_position' => MaskPositionTest::getMinResponse(), + 'keywords' => ['keywords'] + ]; + } + + protected function assertMinItem($item) + { + $this->assertEquals('file', $item->getSticker()); + $this->assertEquals('static', $item->getFormat()); + $this->assertEquals(['😀'], $item->getEmojiList()); + } + + protected function assertFullItem($item) + { + $this->assertEquals('file', $item->getSticker()); + $this->assertEquals('static', $item->getFormat()); + $this->assertEquals(['😀'], $item->getEmojiList()); + $this->assertEquals(MaskPositionTest::createMinInstance(), $item->getMaskPosition()); + $this->assertEquals(['keywords'], $item->getKeywords()); + } +}