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

Bot API 7.0 #1459

Merged
merged 19 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Other Changes pt. 3: Added MaybeInaccessibleMessage
  • Loading branch information
TiiFuchs committed May 13, 2024
commit c2ec524912751724b8f293521e57f29b670d59f0
18 changes: 10 additions & 8 deletions src/Entities/CallbackQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@

namespace Longman\TelegramBot\Entities;

use Longman\TelegramBot\Entities\Message\Factory as MaybeInaccessibleMessageFactory;
use Longman\TelegramBot\Entities\Message\MaybeInaccessibleMessage;
use Longman\TelegramBot\Request;

/**
* Class CallbackQuery.
*
* @link https://core.telegram.org/bots/api#callbackquery
*
* @method string getId() Unique identifier for this query
* @method User getFrom() Sender
* @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
* @method string getInlineMessageId() Optional. Identifier of the message sent via the bot in inline mode, that originated the query
* @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.
* @method string getData() Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field
* @method string getGameShortName() Optional. Short name of a Game to be returned, serves as the unique identifier for the game
* @method string getId() Unique identifier for this query
* @method User getFrom() Sender
* @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
* @method string getInlineMessageId() Optional. Identifier of the message sent via the bot in inline mode, that originated the query
* @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.
* @method string getData() Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field
* @method string getGameShortName() Optional. Short name of a Game to be returned, serves as the unique identifier for the game
*/
class CallbackQuery extends Entity
{
Expand All @@ -35,7 +37,7 @@ protected function subEntities(): array
{
return [
'from' => User::class,
'message' => Message::class,
'message' => MaybeInaccessibleMessageFactory::class,
];
}

Expand Down
8 changes: 5 additions & 3 deletions src/Entities/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Longman\TelegramBot\Entities;

use Longman\TelegramBot\Entities\Games\Game;
use Longman\TelegramBot\Entities\Message\Factory as MaybeInaccessibleMessageFactory;
use Longman\TelegramBot\Entities\Message\MaybeInaccessibleMessage;
use Longman\TelegramBot\Entities\MessageOrigin\Factory as MessageOriginFactory;
use Longman\TelegramBot\Entities\MessageOrigin\MessageOrigin;
use Longman\TelegramBot\Entities\Payments\Invoice;
Expand Down Expand Up @@ -79,7 +81,7 @@
* @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.
* @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.
* @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.
* @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.
* @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.
* @method Invoice getInvoice() Optional. Message is an invoice for a payment, information about the invoice.
* @method SuccessfulPayment getSuccessfulPayment() Optional. Message is a service message about a successful payment, information about the payment.
* @method UsersShared getUsersShared() Optional. Service message: users were shared with the bot
Expand All @@ -101,7 +103,7 @@
* @method WebAppData getWebAppData() Optional. Service message: data sent by a Web App
* @method InlineKeyboard getReplyMarkup() Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons.
*/
class Message extends Entity
class Message extends Entity implements MaybeInaccessibleMessage
{
/**
* {@inheritdoc}
Expand Down Expand Up @@ -139,7 +141,7 @@ protected function subEntities(): array
'left_chat_member' => User::class,
'new_chat_photo' => [PhotoSize::class],
'message_auto_delete_timer_changed' => MessageAutoDeleteTimerChanged::class,
'pinned_message' => __CLASS__,
'pinned_message' => MaybeInaccessibleMessageFactory::class,
'invoice' => Invoice::class,
'successful_payment' => SuccessfulPayment::class,
'users_shared' => UsersShared::class,
Expand Down
21 changes: 21 additions & 0 deletions src/Entities/Message/Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Longman\TelegramBot\Entities\Message;

use Longman\TelegramBot\Entities\Entity;
use Longman\TelegramBot\Entities\Message;

class Factory extends \Longman\TelegramBot\Entities\Factory
{

public static function make(array $data, string $bot_username): Entity
{
if ($data['date'] === 0) {
$class = InaccessibleMessage::class;
} else {
$class = Message::class;
}

return new $class($data, $bot_username);
}
}
22 changes: 22 additions & 0 deletions src/Entities/Message/InaccessibleMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Longman\TelegramBot\Entities\Message;

use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\Entity;

/**
* @method Chat getChat() Chat the message belonged to
* @method int getMessageId() Unique message identifier inside the chat
* @method int getDate() Always 0. The field can be used to differentiate regular and inaccessible messages.
*/
class InaccessibleMessage extends Entity implements MaybeInaccessibleMessage
{
protected function subEntities(): array
{
return [
'chat' => Chat::class,
];
}

}
15 changes: 15 additions & 0 deletions src/Entities/Message/MaybeInaccessibleMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Longman\TelegramBot\Entities\Message;

use Longman\TelegramBot\Entities\Chat;

/**
* @method Chat getChat() Chat the message belonged to
* @method int getMessageId() Unique message identifier inside this chat
* @method int getDate() The field can be used to differentiate regular and inaccessible messages.
*/
interface MaybeInaccessibleMessage
{
//
}