Skip to content

Commit

Permalink
Telegram Bot API 7.10 support (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik authored Sep 6, 2024
1 parent fe19c94 commit f2a4228
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 41 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Telegram Bot API for PHP Change Log

## 0.4.3 September 06, 2024

- New #118: Add `PaidMediaPurchased` type.
- New #118: Add `purchasedPaidMedia` field to `Update` type.
- New #118: Add `paidMediaPayload` field to `TransactionPartnerUser` type.
- New #118: Add `payload` parameter to `SendPaidMedia` method.
- New #118: Add `prizeStarCount ` field to `GiveawayCreated`, `Giveaway`, `GiveawayWinners` and
`ChatBoostSourceGiveaway` types.
- New #118: Add `isStarGiveaway` field to `GiveawayCompleted` type.
- New #118: Bump `php-http/multipart-stream-builder` dependency to `^1.4.2` version.

## 0.4.2 August 22, 2024

- New #117: Add `createChatSubscriptionInviteLink` and `editChatSubscriptionInviteLink` methods.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

The package provides a simple and convenient way to interact with the Telegram Bot API.

✔️ Telegram Bot API 7.9 (August 14, 2024) is **full supported**.
✔️ Telegram Bot API 7.10 (September 6, 2024) is **full supported**.

## Requirements

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"minimum-stability": "stable",
"require": {
"php": "^8.2",
"php-http/multipart-stream-builder": "^1.3",
"php-http/multipart-stream-builder": "^1.4.2",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.1",
"psr/http-message": "^1.1|^2.0"
Expand Down
2 changes: 2 additions & 0 deletions src/Method/SendPaidMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __construct(
private ?ReplyParameters $replyParameters = null,
private InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup = null,
private ?string $businessConnectionId = null,
private ?string $payload = null,
) {}

public function getHttpMethod(): HttpMethod
Expand Down Expand Up @@ -66,6 +67,7 @@ static function (InputPaidMedia $inputMedia) use ($fileCollector): array {
'chat_id' => $this->chatId,
'star_count' => $this->starCount,
'media' => $media,
'payload' => $this->payload,
'caption' => $this->caption,
'parse_mode' => $this->parseMode,
'caption_entities' => $this->captionEntities === null ? null : array_map(
Expand Down
2 changes: 2 additions & 0 deletions src/TelegramBotApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -1911,6 +1911,7 @@ public function sendPaidMedia(
?ReplyParameters $replyParameters = null,
InlineKeyboardMarkup|ReplyKeyboardMarkup|ReplyKeyboardRemove|ForceReply|null $replyMarkup = null,
?string $businessConnectionId = null,
?string $payload = null,
): FailResult|Message {
return $this->send(
new SendPaidMedia(
Expand All @@ -1926,6 +1927,7 @@ public function sendPaidMedia(
$replyParameters,
$replyMarkup,
$businessConnectionId,
$payload,
),
);
}
Expand Down
1 change: 1 addition & 0 deletions src/Type/ChatBoostSourceGiveaway.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function __construct(
public int $giveawayMessageId,
public ?User $user = null,
public ?true $isUnclaimed = null,
public ?int $prizeStarCount = null,
) {}

public function getSource(): string
Expand Down
1 change: 1 addition & 0 deletions src/Type/Giveaway.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ public function __construct(
#[ArrayMap(StringValue::class)]
public ?array $countryCodes = null,
public ?int $premiumSubscriptionMonthCount = null,
public ?int $prizeStarCount = null,
) {}
}
1 change: 1 addition & 0 deletions src/Type/GiveawayCompleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public function __construct(
public int $winnerCount,
public ?int $unclaimedPrizeCount = null,
public ?Message $giveawayMessage = null,
public ?true $isStarGiveaway = null,
) {}
}
7 changes: 6 additions & 1 deletion src/Type/GiveawayCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
/**
* @see https://core.telegram.org/bots/api#giveawaycreated
*/
final readonly class GiveawayCreated {}
final readonly class GiveawayCreated
{
public function __construct(
public ?int $prizeStarCount = null,
) {}
}
1 change: 1 addition & 0 deletions src/Type/GiveawayWinners.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ public function __construct(
public ?true $onlyNewMembers = null,
public ?true $wasRefunded = null,
public ?string $prizeDescription = null,
public ?int $prizeStarCount = null,
) {}
}
18 changes: 18 additions & 0 deletions src/Type/Payment/PaidMediaPurchased.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Vjik\TelegramBot\Api\Type\Payment;

use Vjik\TelegramBot\Api\Type\User;

/**
* @see https://core.telegram.org/bots/api#paidmediapurchased
*/
final readonly class PaidMediaPurchased
{
public function __construct(
public User $from,
public string $paidMediaPayload,
) {}
}
1 change: 1 addition & 0 deletions src/Type/Payment/TransactionPartnerUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct(
public ?string $invoicePayload = null,
#[ArrayMap(PaidMediaValue::class)]
public ?array $paidMedia = null,
public ?string $paidMediaPayload = null,
) {}

public function getType(): string
Expand Down
2 changes: 2 additions & 0 deletions src/Type/Update/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Vjik\TelegramBot\Api\Type\Message;
use Vjik\TelegramBot\Api\Type\MessageReactionCountUpdated;
use Vjik\TelegramBot\Api\Type\MessageReactionUpdated;
use Vjik\TelegramBot\Api\Type\Payment\PaidMediaPurchased;
use Vjik\TelegramBot\Api\Type\Payment\PreCheckoutQuery;
use Vjik\TelegramBot\Api\Type\Payment\ShippingQuery;
use Vjik\TelegramBot\Api\Type\Poll;
Expand Down Expand Up @@ -59,6 +60,7 @@ public function __construct(
public readonly ?ChatJoinRequest $chatJoinRequest = null,
public readonly ?ChatBoostUpdated $chatBoost = null,
public readonly ?ChatBoostRemoved $removedChatBoost = null,
public readonly ?PaidMediaPurchased $purchasedPaidMedia = null,
) {}

/**
Expand Down
5 changes: 1 addition & 4 deletions tests/Client/PsrTelegramClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function testPostWithDataAndFiles(): void
/** @var Request $request */
$requestHeaders = $request->getHeaders();
$this->assertSame(['Content-Length', 'Content-Type'], array_keys($requestHeaders));
$this->assertSame($requestHeaders['Content-Length'], ['390']);
$this->assertSame($requestHeaders['Content-Length'], ['332']);
$this->assertSame([0], array_keys($requestHeaders['Content-Type']));
$this->assertSame(
1,
Expand All @@ -155,17 +155,14 @@ public function testPostWithDataAndFiles(): void
<<<TEXT
--$matches[1]
Content-Disposition: form-data; name="chat_id"
Content-Length: 3
123
--$matches[1]
Content-Disposition: form-data; name="caption"
Content-Length: 5
hello
--$matches[1]
Content-Disposition: form-data; name="photo"; filename="face.png"
Content-Length: 14
Content-Type: image/png
test-file-body
Expand Down
2 changes: 2 additions & 0 deletions tests/Method/SendPaidMediaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function testFull(): void
$replyParameters,
$replyMarkup,
'bcid1',
'test-payload',
);

$this->assertSame(
Expand All @@ -67,6 +68,7 @@ public function testFull(): void
'media' => 'attach://file0',
],
],
'payload' => 'test-payload',
'caption' => 'The caption',
'parse_mode' => 'HTML',
'caption_entities' => [$entity->toRequestArray()],
Expand Down
25 changes: 16 additions & 9 deletions tests/Type/ChatBoostSourceGiveawayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,33 @@ public function testBase(): void
$this->assertSame(12, $source->giveawayMessageId);
$this->assertNull($source->user);
$this->assertNull($source->isUnclaimed);
$this->assertNull($source->prizeStarCount);
}

public function testFromTelegramResult(): void
{
$source = (new ObjectFactory())->create([
'source' => 'giveaway',
'giveaway_message_id' => 12,
'user' => [
'id' => 7,
'is_bot' => false,
'first_name' => 'Sergei',
$source = (new ObjectFactory())->create(
[
'source' => 'giveaway',
'giveaway_message_id' => 12,
'user' => [
'id' => 7,
'is_bot' => false,
'first_name' => 'Sergei',
],
'prize_star_count' => 19,
'is_unclaimed' => true,
],
'is_unclaimed' => true,
], null, ChatBoostSourceGiveaway::class);
null,
ChatBoostSourceGiveaway::class,
);

$this->assertSame(12, $source->giveawayMessageId);

$this->assertInstanceOf(User::class, $source->user);
$this->assertSame(7, $source->user->id);

$this->assertTrue($source->isUnclaimed);
$this->assertSame(19, $source->prizeStarCount);
}
}
26 changes: 16 additions & 10 deletions tests/Type/GiveawayCompletedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,29 @@ public function testBase(): void

public function testFromTelegramResult(): void
{
$giveawayCompleted = (new ObjectFactory())->create([
'winner_count' => 3,
'unclaimed_prize_count' => 2,
'giveaway_message' => [
'message_id' => 123,
'date' => 1717501903,
'chat' => [
'id' => 23,
'type' => 'private',
$giveawayCompleted = (new ObjectFactory())->create(
[
'winner_count' => 3,
'unclaimed_prize_count' => 2,
'giveaway_message' => [
'message_id' => 123,
'date' => 1717501903,
'chat' => [
'id' => 23,
'type' => 'private',
],
],
'is_star_giveaway' => true,
],
], null, GiveawayCompleted::class);
null,
GiveawayCompleted::class,
);

$this->assertSame(3, $giveawayCompleted->winnerCount);
$this->assertSame(2, $giveawayCompleted->unclaimedPrizeCount);

$this->assertInstanceOf(Message::class, $giveawayCompleted->giveawayMessage);
$this->assertSame(123, $giveawayCompleted->giveawayMessage->messageId);
$this->assertTrue($giveawayCompleted->isStarGiveaway);
}
}
16 changes: 12 additions & 4 deletions tests/Type/GiveawayCreatedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ final class GiveawayCreatedTest extends TestCase
{
public function testBase(): void
{
new GiveawayCreated();
$this->expectNotToPerformAssertions();
$object = new GiveawayCreated();

$this->assertNull($object->prizeStarCount);
}

public function testFromTelegramResult(): void
{
(new ObjectFactory())->create([], null, GiveawayCreated::class);
$this->expectNotToPerformAssertions();
$object = (new ObjectFactory())->create(
[
'prize_star_count' => 23,
],
null,
GiveawayCreated::class,
);

$this->assertSame(23, $object->prizeStarCount);
}
}
29 changes: 18 additions & 11 deletions tests/Type/GiveawayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,28 @@ public function testBase(): void
$this->assertNull($giveaway->prizeDescription);
$this->assertNull($giveaway->countryCodes);
$this->assertNull($giveaway->premiumSubscriptionMonthCount);
$this->assertNull($giveaway->prizeStarCount);
}

public function testFromTelegramResult(): void
{
$giveaway = (new ObjectFactory())->create([
'chats' => [
['id' => 1, 'type' => 'private'],
$giveaway = (new ObjectFactory())->create(
[
'chats' => [
['id' => 1, 'type' => 'private'],
],
'winners_selection_date' => 1234567890,
'winner_count' => 3,
'only_new_members' => true,
'has_public_winners' => true,
'prize_description' => 'prize',
'country_codes' => ['RU'],
'prize_star_count' => 19,
'premium_subscription_month_count' => 7,
],
'winners_selection_date' => 1234567890,
'winner_count' => 3,
'only_new_members' => true,
'has_public_winners' => true,
'prize_description' => 'prize',
'country_codes' => ['RU'],
'premium_subscription_month_count' => 7,
], null, Giveaway::class);
null,
Giveaway::class,
);

$this->assertCount(1, $giveaway->chats);
$this->assertInstanceOf(Chat::class, $giveaway->chats[0]);
Expand All @@ -55,5 +61,6 @@ public function testFromTelegramResult(): void
$this->assertSame('prize', $giveaway->prizeDescription);
$this->assertSame(['RU'], $giveaway->countryCodes);
$this->assertSame(7, $giveaway->premiumSubscriptionMonthCount);
$this->assertSame(19, $giveaway->prizeStarCount);
}
}
3 changes: 3 additions & 0 deletions tests/Type/GiveawayWinnersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function testBase(): void
$this->assertNull($giveawayWinners->onlyNewMembers);
$this->assertNull($giveawayWinners->wasRefunded);
$this->assertNull($giveawayWinners->prizeDescription);
$this->assertNull($giveawayWinners->prizeStarCount);
}

public function testFromTelegramResult(): void
Expand All @@ -42,6 +43,7 @@ public function testFromTelegramResult(): void
'winner_count' => 5,
'winners' => [['id' => 33, 'is_bot' => false, 'first_name' => 'Sergei']],
'additional_chat_count' => 12,
'prize_star_count' => 99,
'premium_subscription_month_count' => 7,
'unclaimed_prize_count' => 3,
'only_new_members' => true,
Expand All @@ -63,5 +65,6 @@ public function testFromTelegramResult(): void
$this->assertTrue($giveawayWinners->onlyNewMembers);
$this->assertTrue($giveawayWinners->wasRefunded);
$this->assertSame('Desc', $giveawayWinners->prizeDescription);
$this->assertSame(99, $giveawayWinners->prizeStarCount);
}
}
Loading

0 comments on commit f2a4228

Please sign in to comment.