Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setCustomEmojiStickerSetThumbnail method #62

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
methods.
- New #60: Add `setStickerSetTitle` method.
- New #61: Add `setStickerSetThumbnail` method.
- New #62: Add `setCustomEmojiStickerSetThumbnail` 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`.
Expand Down
48 changes: 48 additions & 0 deletions src/Method/Sticker/SetCustomEmojiStickerSetThumbnail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Method\Sticker;

use Vjik\TelegramBot\Api\ParseResult\ValueHelper;
use Vjik\TelegramBot\Api\Request\HttpMethod;
use Vjik\TelegramBot\Api\Request\TelegramRequestWithResultPreparingInterface;

/**
* @see https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail
*/
final readonly class SetCustomEmojiStickerSetThumbnail implements TelegramRequestWithResultPreparingInterface
{
public function __construct(
private string $name,
private ?string $customEmojiId = null,
) {
}

public function getHttpMethod(): HttpMethod
{
return HttpMethod::POST;
}

public function getApiMethod(): string
{
return 'setCustomEmojiStickerSetThumbnail';
}

public function getData(): array
{
return array_filter(
[
'name' => $this->name,
'custom_emoji_id' => $this->customEmojiId,
],
static fn(mixed $value): bool => $value !== null,
);
}

public function prepareResult(mixed $result): true
{
ValueHelper::assertTrueResult($result);
return $result;
}
}
11 changes: 11 additions & 0 deletions src/TelegramBotApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
use Vjik\TelegramBot\Api\Method\Sticker\GetStickerSet;
use Vjik\TelegramBot\Api\Method\Sticker\ReplaceStickerInSet;
use Vjik\TelegramBot\Api\Method\Sticker\SendSticker;
use Vjik\TelegramBot\Api\Method\Sticker\SetCustomEmojiStickerSetThumbnail;
use Vjik\TelegramBot\Api\Method\Sticker\SetStickerEmojiList;
use Vjik\TelegramBot\Api\Method\Sticker\SetStickerKeywords;
use Vjik\TelegramBot\Api\Method\Sticker\SetStickerMaskPosition;
Expand Down Expand Up @@ -1604,6 +1605,16 @@ public function setMyShortDescription(
return $this->send(new SetMyShortDescription($shortDescription, $languageCode));
}

/**
* @see https://core.telegram.org/bots/api#setcustomemojistickersetthumbnail
*
* @psalm-suppress MixedInferredReturnType,MixedReturnStatement
*/
public function setCustomEmojiStickerSetThumbnail(string $name, ?string $customEmojiId = null): FailResult|true
{
return $this->send(new SetCustomEmojiStickerSetThumbnail($name, $customEmojiId));
}

/**
* @see https://core.telegram.org/bots/api#setstickeremojilist
*
Expand Down
50 changes: 50 additions & 0 deletions tests/Method/Sticker/SetCustomEmojiStickerSetThumbnailTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Tests\Method\Sticker;

use PHPUnit\Framework\TestCase;
use Vjik\TelegramBot\Api\Method\Sticker\SetCustomEmojiStickerSetThumbnail;
use Vjik\TelegramBot\Api\Request\HttpMethod;

final class SetCustomEmojiStickerSetThumbnailTest extends TestCase
{
public function testBase(): void
{
$method = new SetCustomEmojiStickerSetThumbnail('animals_by_my_bot');

$this->assertSame(HttpMethod::POST, $method->getHttpMethod());
$this->assertSame('setCustomEmojiStickerSetThumbnail', $method->getApiMethod());
$this->assertSame(
[
'name' => 'animals_by_my_bot',
],
$method->getData(),
);
}

public function testFull(): void
{
$method = new SetCustomEmojiStickerSetThumbnail('animals_by_my_bot', 'ceid');

$this->assertSame(HttpMethod::POST, $method->getHttpMethod());
$this->assertSame('setCustomEmojiStickerSetThumbnail', $method->getApiMethod());
$this->assertSame(
[
'name' => 'animals_by_my_bot',
'custom_emoji_id' => 'ceid',
],
$method->getData(),
);
}

public function testPrepareResult(): void
{
$method = new SetCustomEmojiStickerSetThumbnail('animals_by_my_bot');

$preparedResult = $method->prepareResult(true);

$this->assertTrue($preparedResult);
}
}
12 changes: 12 additions & 0 deletions tests/TelegramBotApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,18 @@ public function testSetMyShortDescription(): void
$this->assertTrue($result);
}

public function testSetCustomEmojiStickerSetThumbnail(): void
{
$api = $this->createApi([
'ok' => true,
'result' => true,
]);

$result = $api->setCustomEmojiStickerSetThumbnail('animals_by_my_bor');

$this->assertTrue($result);
}

public function testSetStickerEmojiList(): void
{
$api = $this->createApi([
Expand Down
Loading