Skip to content

Commit c2ec524

Browse files
committed
Other Changes pt. 3: Added MaybeInaccessibleMessage
1 parent 5de1935 commit c2ec524

File tree

5 files changed

+73
-11
lines changed

5 files changed

+73
-11
lines changed

src/Entities/CallbackQuery.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@
1111

1212
namespace Longman\TelegramBot\Entities;
1313

14+
use Longman\TelegramBot\Entities\Message\Factory as MaybeInaccessibleMessageFactory;
15+
use Longman\TelegramBot\Entities\Message\MaybeInaccessibleMessage;
1416
use Longman\TelegramBot\Request;
1517

1618
/**
1719
* Class CallbackQuery.
1820
*
1921
* @link https://core.telegram.org/bots/api#callbackquery
2022
*
21-
* @method string getId() Unique identifier for this query
22-
* @method User getFrom() Sender
23-
* @method Message getMessage() Optional. Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old
24-
* @method string getInlineMessageId() Optional. Identifier of the message sent via the bot in inline mode, that originated the query
25-
* @method string getChatInstance() Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.
26-
* @method string getData() Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field
27-
* @method string getGameShortName() Optional. Short name of a Game to be returned, serves as the unique identifier for the game
23+
* @method string getId() Unique identifier for this query
24+
* @method User getFrom() Sender
25+
* @method MaybeInaccessibleMessage getMessage() Optional. Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old
26+
* @method string getInlineMessageId() Optional. Identifier of the message sent via the bot in inline mode, that originated the query
27+
* @method string getChatInstance() Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.
28+
* @method string getData() Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field
29+
* @method string getGameShortName() Optional. Short name of a Game to be returned, serves as the unique identifier for the game
2830
*/
2931
class CallbackQuery extends Entity
3032
{
@@ -35,7 +37,7 @@ protected function subEntities(): array
3537
{
3638
return [
3739
'from' => User::class,
38-
'message' => Message::class,
40+
'message' => MaybeInaccessibleMessageFactory::class,
3941
];
4042
}
4143

src/Entities/Message.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Longman\TelegramBot\Entities;
1313

1414
use Longman\TelegramBot\Entities\Games\Game;
15+
use Longman\TelegramBot\Entities\Message\Factory as MaybeInaccessibleMessageFactory;
16+
use Longman\TelegramBot\Entities\Message\MaybeInaccessibleMessage;
1517
use Longman\TelegramBot\Entities\MessageOrigin\Factory as MessageOriginFactory;
1618
use Longman\TelegramBot\Entities\MessageOrigin\MessageOrigin;
1719
use Longman\TelegramBot\Entities\Payments\Invoice;
@@ -79,7 +81,7 @@
7981
* @method bool getChannelChatCreated() Optional. Service message: the channel has been created. This field can't be received in a message coming through updates, because bot can’t be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel.
8082
* @method int getMigrateToChatId() Optional. The group has been migrated to a supergroup with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
8183
* @method int getMigrateFromChatId() Optional. The supergroup has been migrated from a group with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
82-
* @method Message getPinnedMessage() Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.
84+
* @method MaybeInaccessibleMessage getPinnedMessage() Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.
8385
* @method Invoice getInvoice() Optional. Message is an invoice for a payment, information about the invoice.
8486
* @method SuccessfulPayment getSuccessfulPayment() Optional. Message is a service message about a successful payment, information about the payment.
8587
* @method UsersShared getUsersShared() Optional. Service message: users were shared with the bot
@@ -101,7 +103,7 @@
101103
* @method WebAppData getWebAppData() Optional. Service message: data sent by a Web App
102104
* @method InlineKeyboard getReplyMarkup() Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons.
103105
*/
104-
class Message extends Entity
106+
class Message extends Entity implements MaybeInaccessibleMessage
105107
{
106108
/**
107109
* {@inheritdoc}
@@ -139,7 +141,7 @@ protected function subEntities(): array
139141
'left_chat_member' => User::class,
140142
'new_chat_photo' => [PhotoSize::class],
141143
'message_auto_delete_timer_changed' => MessageAutoDeleteTimerChanged::class,
142-
'pinned_message' => __CLASS__,
144+
'pinned_message' => MaybeInaccessibleMessageFactory::class,
143145
'invoice' => Invoice::class,
144146
'successful_payment' => SuccessfulPayment::class,
145147
'users_shared' => UsersShared::class,

src/Entities/Message/Factory.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Longman\TelegramBot\Entities\Message;
4+
5+
use Longman\TelegramBot\Entities\Entity;
6+
use Longman\TelegramBot\Entities\Message;
7+
8+
class Factory extends \Longman\TelegramBot\Entities\Factory
9+
{
10+
11+
public static function make(array $data, string $bot_username): Entity
12+
{
13+
if ($data['date'] === 0) {
14+
$class = InaccessibleMessage::class;
15+
} else {
16+
$class = Message::class;
17+
}
18+
19+
return new $class($data, $bot_username);
20+
}
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Longman\TelegramBot\Entities\Message;
4+
5+
use Longman\TelegramBot\Entities\Chat;
6+
use Longman\TelegramBot\Entities\Entity;
7+
8+
/**
9+
* @method Chat getChat() Chat the message belonged to
10+
* @method int getMessageId() Unique message identifier inside the chat
11+
* @method int getDate() Always 0. The field can be used to differentiate regular and inaccessible messages.
12+
*/
13+
class InaccessibleMessage extends Entity implements MaybeInaccessibleMessage
14+
{
15+
protected function subEntities(): array
16+
{
17+
return [
18+
'chat' => Chat::class,
19+
];
20+
}
21+
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Longman\TelegramBot\Entities\Message;
4+
5+
use Longman\TelegramBot\Entities\Chat;
6+
7+
/**
8+
* @method Chat getChat() Chat the message belonged to
9+
* @method int getMessageId() Unique message identifier inside this chat
10+
* @method int getDate() The field can be used to differentiate regular and inaccessible messages.
11+
*/
12+
interface MaybeInaccessibleMessage
13+
{
14+
//
15+
}

0 commit comments

Comments
 (0)