Skip to content

Commit

Permalink
Other Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bernard-ng committed Oct 12, 2024
1 parent 6d0d893 commit cfde76a
Show file tree
Hide file tree
Showing 5 changed files with 243 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/BotApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <bernard@devscast.tech>
*/
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
*
Expand Down
164 changes: 164 additions & 0 deletions src/Types/InputSticker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php

declare(strict_types=1);

namespace TelegramBot\Api\Types;

use TelegramBot\Api\BaseType;
use TelegramBot\Api\TypeInterface;

/**
* Class InputSticker.
* This object describes a sticker to be added to a sticker set.
*
* @author bernard-ng <bernard@devscast.tech>
*/
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://<file_attach_name>” to upload a new one using multipart/form-data under <file_attach_name> 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;
}
}
2 changes: 0 additions & 2 deletions tests/Types/BusinessConnectionTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

namespace TelegramBot\Api\Test\Types;

use TelegramBot\Api\Test\AbstractTypeTest;
Expand Down
50 changes: 50 additions & 0 deletions tests/Types/InputStickerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace TelegramBot\Api\Test\Types;

use TelegramBot\Api\Types\InputSticker;
use TelegramBot\Api\Test\AbstractTypeTest;

class InputStickerTest extends AbstractTypeTest
{
protected static function getType()
{
return InputSticker::class;
}

public static function getMinResponse()
{
return [
'sticker' => '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());
}
}

0 comments on commit cfde76a

Please sign in to comment.