Skip to content

Commit d9d4fe5

Browse files
committed
feat: #465 add Chat Boost as defined in api 7.0
1 parent 742afb8 commit d9d4fe5

File tree

9 files changed

+266
-2
lines changed

9 files changed

+266
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ All Notable changes to `PHP Telegram Bot Api` will be documented in this file
2222
- Add `\TelegramBot\Api\BotApi::deleteMessages` api method
2323
- Add `\TelegramBot\Api\BotApi::copyMessages` api method
2424
- Add `\TelegramBot\Api\BotApi::forwardMessages` api method
25+
- Add `\TelegramBot\Api\BotApi::getUserChatBoosts` api method
2526

2627
### Deprecated
2728
- Deprecate `reply_to_message_id` and `allow_sending_without_reply` parameters to `\TelegramBot\Api\BotApi` methods. Use `reply_parameters` instead.

src/BaseType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function validate($data)
4040
}
4141

4242
$missingParams = implode(', ', array_diff(static::$requiredParams, array_keys($data)));
43-
throw new InvalidArgumentException(sprintf('Validation failed. Missing required parameters: %s', $missingParams));
43+
throw new InvalidArgumentException(sprintf('%s Validation failed. Missing required parameters: %s', static::class, $missingParams));
4444
}
4545

4646
/**

src/BotApi.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace TelegramBot\Api;
44

55
use TelegramBot\Api\Http\CurlHttpClient;
6+
use TelegramBot\Api\Types\UserChatBoosts;
67
use TelegramBot\Api\Types\ReplyParameters;
78
use TelegramBot\Api\Http\HttpClientInterface;
89
use TelegramBot\Api\Types\ArrayOfBotCommand;
@@ -3160,6 +3161,26 @@ public function copyMessages(
31603161
]);
31613162
}
31623163

3164+
/**
3165+
* Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat.
3166+
* Returns a UserChatBoosts object.
3167+
*
3168+
* @param string|int $chatId Unique identifier for the chat or username of the channel (in the format @channelusername)
3169+
* @param int $userId Unique identifier of the target user
3170+
*
3171+
* @return UserChatBoosts
3172+
* @throws Exception
3173+
*
3174+
* @author bernard-ng <[email protected]>
3175+
*/
3176+
public function getUserChatBoosts($chatId, $userId)
3177+
{
3178+
return UserChatBoosts::fromResponse($this->call('getUserChatBoosts', [
3179+
'chat_id' => $chatId,
3180+
'user_id' => $userId
3181+
]));
3182+
}
3183+
31633184
/**
31643185
* Set an option for a cURL transfer
31653186
*

src/Types/Update.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class Update extends BaseType implements TypeInterface
4747
'chat_member' => ChatMemberUpdated::class,
4848
'chat_join_request' => ChatJoinRequest::class,
4949
'message_reaction' => MessageReactionUpdated::class,
50-
'message_reaction_count' => MessageReactionCountUpdated::class
50+
'message_reaction_count' => MessageReactionCountUpdated::class,
51+
'chat_boost' => ChatBoostUpdated::class,
52+
'chat_boost_removed' => ChatBoostRemoved::class,
5153
];
5254

5355
/**
@@ -180,6 +182,22 @@ class Update extends BaseType implements TypeInterface
180182
*/
181183
protected $messageReactionCount;
182184

185+
/**
186+
* Optional. A chat boost was added or changed.
187+
* The bot must be an administrator in the chat to receive these updates.
188+
*
189+
* @var ChatBoostUpdated|null
190+
*/
191+
protected $chatBoost;
192+
193+
/**
194+
* Optional. A boost was removed from a chat.
195+
* The bot must be an administrator in the chat to receive these updates.
196+
*
197+
* @var ChatBoostRemoved|null
198+
*/
199+
protected $removedChatBoost;
200+
183201
/**
184202
* @return int
185203
*/
@@ -488,4 +506,38 @@ public function setMessageReactionCount(?MessageReactionCountUpdated $messageRea
488506
{
489507
$this->messageReactionCount = $messageReactionCount;
490508
}
509+
510+
/**
511+
* @return ChatBoostUpdated|null
512+
*/
513+
public function getChatBoost()
514+
{
515+
return $this->chatBoost;
516+
}
517+
518+
/**
519+
* @param ChatBoostUpdated|null $chatBoost
520+
* @return void
521+
*/
522+
public function setChatBoost($chatBoost)
523+
{
524+
$this->chatBoost = $chatBoost;
525+
}
526+
527+
/**
528+
* @return ChatBoostRemoved|null
529+
*/
530+
public function getChatBoostRemoved()
531+
{
532+
return $this->removedChatBoost;
533+
}
534+
535+
/**
536+
* @param ChatBoostRemoved|null $removedChatBoost
537+
* @return void
538+
*/
539+
public function setChatBoostRemoved($removedChatBoost)
540+
{
541+
$this->removedChatBoost = $removedChatBoost;
542+
}
491543
}

tests/Types/ChatBoostRemovedTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace TelegramBot\Api\Test\Types;
4+
5+
use TelegramBot\Api\Test\AbstractTypeTest;
6+
use TelegramBot\Api\Types\ChatBoostRemoved;
7+
8+
class ChatBoostRemovedTest extends AbstractTypeTest
9+
{
10+
protected static function getType()
11+
{
12+
return ChatBoostRemoved::class;
13+
}
14+
15+
public static function getMinResponse()
16+
{
17+
return [
18+
'chat' => ChatTest::getMinResponse(),
19+
'boost_id' => 1,
20+
'remove_date' => 1682343643,
21+
'source' => ChatBoostSourceTest::getMinResponse()
22+
];
23+
}
24+
25+
public static function getFullResponse()
26+
{
27+
return [
28+
'chat' => ChatTest::getMinResponse(),
29+
'boost_id' => 1,
30+
'remove_date' => 1682343643,
31+
'source' => ChatBoostSourceTest::getMinResponse()
32+
];
33+
}
34+
35+
protected function assertMinItem($item)
36+
{
37+
$this->assertEquals(ChatTest::createMinInstance(), $item->getChat());
38+
$this->assertEquals(1, $item->getBoostId());
39+
$this->assertEquals(1682343643, $item->getRemoveDate());
40+
$this->assertEquals(ChatBoostSourceTest::createMinInstance(), $item->getSource());
41+
}
42+
43+
protected function assertFullItem($item)
44+
{
45+
$this->assertEquals(ChatTest::createMinInstance(), $item->getChat());
46+
$this->assertEquals(1, $item->getBoostId());
47+
$this->assertEquals(1682343643, $item->getRemoveDate());
48+
$this->assertEquals(ChatBoostSourceTest::createMinInstance(), $item->getSource());
49+
}
50+
}

tests/Types/ChatBoostSourceTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace TelegramBot\Api\Test\Types;
4+
5+
use TelegramBot\Api\Test\AbstractTypeTest;
6+
use TelegramBot\Api\Types\ChatBoostSource;
7+
8+
class ChatBoostSourceTest extends AbstractTypeTest
9+
{
10+
protected static function getType()
11+
{
12+
return ChatBoostSource::class;
13+
}
14+
15+
public static function getMinResponse()
16+
{
17+
return [
18+
'source' => 'premium',
19+
'user' => UserTest::getMinResponse(),
20+
];
21+
}
22+
23+
public static function getFullResponse()
24+
{
25+
return [
26+
'source' => 'premium',
27+
'user' => UserTest::getMinResponse(),
28+
];
29+
}
30+
31+
protected function assertMinItem($item)
32+
{
33+
$this->assertEquals('premium', $item->getSource());
34+
$this->assertEquals(UserTest::createMinInstance(), $item->getUser());
35+
}
36+
37+
protected function assertFullItem($item)
38+
{
39+
$this->assertEquals('premium', $item->getSource());
40+
$this->assertEquals(UserTest::createMinInstance(), $item->getUser());
41+
}
42+
}

tests/Types/ChatBoostTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace TelegramBot\Api\Test\Types;
4+
5+
use TelegramBot\Api\Types\ChatBoost;
6+
use TelegramBot\Api\Test\AbstractTypeTest;
7+
8+
class ChatBoostTest extends AbstractTypeTest
9+
{
10+
protected static function getType()
11+
{
12+
return ChatBoost::class;
13+
}
14+
15+
public static function getMinResponse()
16+
{
17+
return [
18+
'boost_id' => 1,
19+
'add_date' => 1682343643,
20+
'expiration_date' => 1725042370,
21+
'source' => ChatBoostSourceTest::getMinResponse()
22+
];
23+
}
24+
25+
public static function getFullResponse()
26+
{
27+
return [
28+
'boost_id' => 1,
29+
'add_date' => 1682343643,
30+
'expiration_date' => 1725042370,
31+
'source' => ChatBoostSourceTest::getMinResponse()
32+
];
33+
}
34+
35+
protected function assertMinItem($item)
36+
{
37+
$this->assertEquals(1, $item->getBoostId());
38+
$this->assertEquals(1682343643, $item->getAddDate());
39+
$this->assertEquals(1725042370, $item->getExpirationDate());
40+
$this->assertEquals(ChatBoostSourceTest::createMinInstance(), $item->getSource());
41+
}
42+
43+
protected function assertFullItem($item)
44+
{
45+
$this->assertEquals(1, $item->getBoostId());
46+
$this->assertEquals(1682343643, $item->getAddDate());
47+
$this->assertEquals(1725042370, $item->getExpirationDate());
48+
$this->assertEquals(ChatBoostSourceTest::createMinInstance(), $item->getSource());
49+
}
50+
}

tests/Types/ChatBoostUpdatedTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace TelegramBot\Api\Test\Types;
4+
5+
use TelegramBot\Api\Test\AbstractTypeTest;
6+
use TelegramBot\Api\Types\ChatBoostUpdated;
7+
8+
class ChatBoostUpdatedTest extends AbstractTypeTest
9+
{
10+
protected static function getType()
11+
{
12+
return ChatBoostUpdated::class;
13+
}
14+
15+
public static function getMinResponse()
16+
{
17+
return [
18+
'chat' => ChatTest::getMinResponse(),
19+
'boost' => ChatBoostTest::getMinResponse(),
20+
];
21+
}
22+
23+
public static function getFullResponse()
24+
{
25+
return [
26+
'chat' => ChatTest::getMinResponse(),
27+
'boost' => ChatBoostTest::getMinResponse(),
28+
];
29+
}
30+
31+
protected function assertMinItem($item)
32+
{
33+
$this->assertEquals(ChatTest::createMinInstance(), $item->getChat());
34+
$this->assertEquals(ChatBoostTest::createMinInstance(), $item->getBoost());
35+
}
36+
37+
protected function assertFullItem($item)
38+
{
39+
$this->assertEquals(ChatTest::createMinInstance(), $item->getChat());
40+
$this->assertEquals(ChatBoostTest::createMinInstance(), $item->getBoost());
41+
}
42+
}

tests/Types/UpdateTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public static function getFullResponse()
4141
'chat_join_request' => ChatJoinRequestTest::getMinResponse(),
4242
'message_reaction' => MessageReactionUpdatedTest::getMinResponse(),
4343
'message_reaction_count' => MessageReactionCountUpdatedTest::getMinResponse(),
44+
'chat_boost' => ChatBoostUpdatedTest::getMinResponse(),
45+
'chat_boost_removed' => ChatBoostRemovedTest::getMinResponse(),
4446
];
4547
}
4648

@@ -67,6 +69,8 @@ protected function assertMinItem($item)
6769
$this->assertNull($item->getChatJoinRequest());
6870
$this->assertNull($item->getMessageReaction());
6971
$this->assertNull($item->getMessageReactionCount());
72+
$this->assertNull($item->getChatBoost());
73+
$this->assertNull($item->getChatBoostRemoved());
7074
}
7175

7276
/**
@@ -90,5 +94,7 @@ protected function assertFullItem($item)
9094
$this->assertEquals(ChatJoinRequestTest::createMinInstance(), $item->getChatJoinRequest());
9195
$this->assertEquals(MessageReactionUpdatedTest::createMinInstance(), $item->getMessageReaction());
9296
$this->assertEquals(MessageReactionCountUpdatedTest::createMinInstance(), $item->getMessageReactionCount());
97+
$this->assertEquals(ChatBoostUpdatedTest::createMinInstance(), $item->getChatBoost());
98+
$this->assertEquals(ChatBoostRemovedTest::createMinInstance(), $item->getChatBoostRemoved());
9399
}
94100
}

0 commit comments

Comments
 (0)