-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #465 add full reactions support as defined in api 7.0
- Loading branch information
1 parent
3b44cb2
commit 8b75285
Showing
9 changed files
with
258 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
use TelegramBot\Api\Http\CurlHttpClient; | ||
use TelegramBot\Api\Http\HttpClientInterface; | ||
use TelegramBot\Api\Types\ArrayOfBotCommand; | ||
use TelegramBot\Api\Types\ArrayOfReactionType; | ||
use TelegramBot\Api\Types\ArrayOfChatMemberEntity; | ||
use TelegramBot\Api\Types\ArrayOfMessageEntity; | ||
use TelegramBot\Api\Types\ArrayOfMessages; | ||
|
@@ -2771,6 +2772,31 @@ public function setProxy($proxyString = '', $socks5 = false) | |
return $this; | ||
} | ||
|
||
/** | ||
* Use this method to change the chosen reactions on a message. | ||
* Service messages can't be reacted to. | ||
* Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. | ||
* | ||
* @param string|int $chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) | ||
* @param int $messageId Identifier of the target message. | ||
* @param ArrayOfReactionType $reaction A list of reaction types to set on the message. | ||
* @param bool $isBig Pass `true` to set the reaction with a big animation | ||
* | ||
* @return bool | ||
* @throws Exception | ||
* | ||
* @author bernard-ng <[email protected]> | ||
*/ | ||
public function setMessageReaction($chatId, $messageId, $reaction, $isBig = false) | ||
{ | ||
return $this->call('setMessageReaction', [ | ||
'chat_id' => $chatId, | ||
'message_id' => $messageId, | ||
'reaction' => $reaction, | ||
'is_big' => $isBig | ||
]); | ||
} | ||
|
||
/** | ||
* Set an option for a cURL transfer | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace TelegramBot\Api\Test\Types; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use TelegramBot\Api\Types\ReactionTypeEmoji; | ||
use TelegramBot\Api\Types\ArrayOfReactionType; | ||
use TelegramBot\Api\Types\ReactionTypeCustomEmoji; | ||
|
||
class ArrayOfReactionTypeTest extends TestCase | ||
{ | ||
public function testFromResponse() | ||
{ | ||
$items = ArrayOfReactionType::fromResponse([ | ||
[ | ||
'emoji' => '👍', | ||
'type' => 'emoji' | ||
], | ||
[ | ||
'custom_emoji_id' => 'custom_emoji_123', | ||
'type' => 'custom_emoji' | ||
] | ||
]); | ||
|
||
$expected = [ | ||
ReactionTypeEmoji::fromResponse([ | ||
'emoji' => '👍', | ||
'type' => 'emoji' | ||
]), | ||
ReactionTypeCustomEmoji::fromResponse([ | ||
'custom_emoji_id' => 'custom_emoji_123', | ||
'type' => 'custom_emoji' | ||
]) | ||
]; | ||
|
||
foreach ($items as $key => $item) { | ||
$this->assertEquals($expected[$key], $item); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace TelegramBot\Api\Test\Types; | ||
|
||
use TelegramBot\Api\Test\AbstractTypeTest; | ||
use TelegramBot\Api\Types\MessageReactionCountUpdated; | ||
|
||
class MessageReactionCountUpdatedTest extends AbstractTypeTest | ||
{ | ||
protected static function getType() | ||
{ | ||
return MessageReactionCountUpdated::class; | ||
} | ||
|
||
public static function getMinResponse() | ||
{ | ||
return [ | ||
'chat' => ChatTest::getMinResponse(), | ||
'message_id' => 1, | ||
'date' => 1682343644, | ||
'reactions' => [ | ||
ReactionTypeEmojiTest::getMinResponse() | ||
] | ||
]; | ||
} | ||
|
||
public static function getFullResponse() | ||
{ | ||
return [ | ||
'chat' => ChatTest::getFullResponse(), | ||
'message_id' => 1, | ||
'date' => 1682343644, | ||
'reactions' => [ | ||
ReactionTypeEmojiTest::getFullResponse() | ||
] | ||
]; | ||
} | ||
|
||
|
||
protected function assertMinItem($item) | ||
{ | ||
$this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); | ||
$this->assertEquals(1, $item->getMessageId()); | ||
$this->assertEquals(1682343644, $item->getDate()); | ||
$this->assertEquals([ReactionTypeEmojiTest::createMinInstance()], $item->getReactions()); | ||
} | ||
|
||
protected function assertFullItem($item) | ||
{ | ||
$this->assertEquals(ChatTest::createFullInstance(), $item->getChat()); | ||
$this->assertEquals(1, $item->getMessageId()); | ||
$this->assertEquals(1682343644, $item->getDate()); | ||
$this->assertEquals([ReactionTypeEmojiTest::createFullInstance()], $item->getReactions()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace TelegramBot\Api\Test\Types; | ||
|
||
use TelegramBot\Api\Test\AbstractTypeTest; | ||
use TelegramBot\Api\Types\MessageReactionUpdated; | ||
|
||
class MessageReactionUpdatedTest extends AbstractTypeTest | ||
{ | ||
protected static function getType() | ||
{ | ||
return MessageReactionUpdated::class; | ||
} | ||
|
||
public static function getMinResponse() | ||
{ | ||
return [ | ||
'chat' => ChatTest::getMinResponse(), | ||
'message_id' => 1, | ||
'date' => 1682343644, | ||
'old_reaction' => [ | ||
ReactionTypeEmojiTest::getMinResponse() | ||
], | ||
'new_reaction' => [ | ||
ReactionTypeCustomEmojiTest::getMinResponse() | ||
] | ||
]; | ||
} | ||
|
||
public static function getFullResponse() | ||
{ | ||
return [ | ||
'chat' => ChatTest::getMinResponse(), | ||
'message_id' => 1, | ||
'user' => UserTest::getMinResponse(), | ||
'actor_chat' => ChatTest::getMinResponse(), | ||
'date' => 1682343644, | ||
'old_reaction' => [ | ||
ReactionTypeEmojiTest::getMinResponse() | ||
], | ||
'new_reaction' => [ | ||
ReactionTypeCustomEmojiTest::getMinResponse() | ||
] | ||
]; | ||
} | ||
|
||
protected function assertMinItem($item) | ||
{ | ||
$this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); | ||
$this->assertEquals(1, $item->getMessageId()); | ||
$this->assertEquals(1682343644, $item->getDate()); | ||
$this->assertEquals([ReactionTypeEmojiTest::createMinInstance()], $item->getOldReaction()); | ||
$this->assertEquals([ReactionTypeCustomEmojiTest::createMinInstance()],$item->getNewReaction()); | ||
|
||
$this->assertNull($item->getUser()); | ||
$this->assertNull($item->getActorChat()); | ||
} | ||
|
||
protected function assertFullItem($item) | ||
{ | ||
$this->assertEquals(ChatTest::createMinInstance(), $item->getChat()); | ||
$this->assertEquals(1, $item->getMessageId()); | ||
$this->assertEquals(UserTest::createMinInstance(), $item->getUser()); | ||
$this->assertEquals(ChatTest::createMinInstance(), $item->getActorChat()); | ||
$this->assertEquals([ReactionTypeEmojiTest::createMinInstance()], $item->getOldReaction()); | ||
$this->assertEquals([ReactionTypeCustomEmojiTest::createMinInstance()],$item->getNewReaction()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters