From 324fac9c64223f33bcfbd183e9480c89a2e466f7 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 6 Jul 2025 23:12:42 +0000 Subject: [PATCH] Add support for Telegram Bot API 7.4 This commit implements the features introduced in the Telegram Bot API 7.4 update (May 28, 2024). Features added: - Telegram Stars & Paid Media: - New entities: LinkPreviewOptions, PaidMediaInfo, PaidMedia (and its derivatives: PaidMediaPreview, PaidMediaPhoto, PaidMediaVideo), StarTransaction, StarTransactions. - Modified entities (WebAppInfo, Message, Update) to include new optional properties related to stars, paid media, and web app launches. - New request methods: sendPaidMedia, getStarTransactions. - Link Preview & UI Updates: - Modified sendMessage and editMessageText to use LinkPreviewOptions, deprecating disable_web_page_preview. - New request method: setChatMenuButton. - Updated library version to 1.0.5. --- src/Entities/LinkPreviewOptions.php | 2 +- src/Entities/Message.php | 11 ++++ src/Entities/PaidMedia/PaidMedia.php | 38 ++++++++++++ src/Entities/PaidMedia/PaidMediaPhoto.php | 28 +++++++++ src/Entities/PaidMedia/PaidMediaPreview.php | 30 ++++++++++ src/Entities/PaidMedia/PaidMediaVideo.php | 29 +++++++++ src/Entities/PaidMediaInfo.php | 28 +++++++++ src/Entities/StarTransaction.php | 35 +++++++++++ src/Entities/StarTransactions.php | 24 ++++++++ src/Entities/Update.php | 3 + src/Entities/WebAppInfo.php | 3 + src/Request.php | 66 +++++++++++++++++++-- src/Telegram.php | 2 +- 13 files changed, 293 insertions(+), 6 deletions(-) create mode 100644 src/Entities/PaidMedia/PaidMedia.php create mode 100644 src/Entities/PaidMedia/PaidMediaPhoto.php create mode 100644 src/Entities/PaidMedia/PaidMediaPreview.php create mode 100644 src/Entities/PaidMedia/PaidMediaVideo.php create mode 100644 src/Entities/PaidMediaInfo.php create mode 100644 src/Entities/StarTransaction.php create mode 100644 src/Entities/StarTransactions.php diff --git a/src/Entities/LinkPreviewOptions.php b/src/Entities/LinkPreviewOptions.php index 7838e86b..66446335 100644 --- a/src/Entities/LinkPreviewOptions.php +++ b/src/Entities/LinkPreviewOptions.php @@ -20,7 +20,7 @@ * @method string getUrl() Optional. URL to use for the link preview. If empty, then the first URL found in the message text will be used * @method bool getPreferSmallMedia() Optional. True, if the media in the link preview is supposed to be shrunk; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview * @method bool getPreferLargeMedia() Optional. True, if the media in the link preview is supposed to be enlarged; ignored if the URL isn't explicitly specified or media size change isn't supported for the preview - * @method bool getShowAboveText() Optional. True, if the link preview must be shown above the message text; otherwise, the link preview will be shown below the message text * + * @method bool getShowAboveText() Optional. True, if the link preview must be shown above the message text; otherwise, the link preview will be shown below the message text */ class LinkPreviewOptions extends Entity { diff --git a/src/Entities/Message.php b/src/Entities/Message.php index 480260f9..28867151 100644 --- a/src/Entities/Message.php +++ b/src/Entities/Message.php @@ -117,6 +117,14 @@ * @method User getSenderBusinessBot() Optional. The bot that actually sent the message on behalf of the business account. Available only for outgoing messages sent on behalf of the business account. * @method bool getIsFromOffline() Optional. True, if the message was sent by an offline user. Applicable to messages sent by the bot on behalf of a user to a fellow user in a private chat. * @method ChatBackground getChatBackgroundSet() Optional. Service message: chat background set + * + * @method PaidMediaInfo getPaidMedia() Optional. Message is a paid media purchase, information about the paid media + * @method StarTransaction getTransaction() Optional. Message is a service message about a successful payment, information about the payment. + * @method WebAppInfo getWebApp() Optional. Service message: a Web App was launched for the user + * + * @method $this setPaidMedia(PaidMediaInfo $paidMedia) Optional. Message is a paid media purchase, information about the paid media + * @method $this setTransaction(StarTransaction $transaction) Optional. Message is a service message about a successful payment, information about the payment. + * @method $this setWebApp(WebAppInfo $webApp) Optional. Service message: a Web App was launched for the user */ class Message extends Entity implements MaybeInaccessibleMessage { @@ -183,6 +191,9 @@ protected function subEntities(): array 'web_app_data' => WebAppData::class, 'reply_markup' => InlineKeyboard::class, 'chat_background_set' => ChatBackground::class, + 'paid_media' => PaidMediaInfo::class, + 'transaction' => StarTransaction::class, + 'web_app' => WebAppInfo::class, ]; } diff --git a/src/Entities/PaidMedia/PaidMedia.php b/src/Entities/PaidMedia/PaidMedia.php new file mode 100644 index 00000000..5f84d8c0 --- /dev/null +++ b/src/Entities/PaidMedia/PaidMedia.php @@ -0,0 +1,38 @@ + [PhotoSize::class], + ]; + } +} diff --git a/src/Entities/PaidMedia/PaidMediaPreview.php b/src/Entities/PaidMedia/PaidMediaPreview.php new file mode 100644 index 00000000..e37d29b2 --- /dev/null +++ b/src/Entities/PaidMedia/PaidMediaPreview.php @@ -0,0 +1,30 @@ + Video::class, + ]; + } +} diff --git a/src/Entities/PaidMediaInfo.php b/src/Entities/PaidMediaInfo.php new file mode 100644 index 00000000..1107e4d6 --- /dev/null +++ b/src/Entities/PaidMediaInfo.php @@ -0,0 +1,28 @@ + [PaidMedia::class], + ]; + } +} diff --git a/src/Entities/StarTransaction.php b/src/Entities/StarTransaction.php new file mode 100644 index 00000000..3ad860d9 --- /dev/null +++ b/src/Entities/StarTransaction.php @@ -0,0 +1,35 @@ + User::class, + 'receiver' => User::class, + ]; + } +} diff --git a/src/Entities/StarTransactions.php b/src/Entities/StarTransactions.php new file mode 100644 index 00000000..4b3c3972 --- /dev/null +++ b/src/Entities/StarTransactions.php @@ -0,0 +1,24 @@ + [StarTransaction::class], + ]; + } +} diff --git a/src/Entities/Update.php b/src/Entities/Update.php index cc47a90e..025fd042 100644 --- a/src/Entities/Update.php +++ b/src/Entities/Update.php @@ -42,6 +42,7 @@ * @method Message getBusinessMessage() Optional. New message from a connected business account * @method Message getEditedBusinessMessage() Optional. New version of a message from a connected business account * @method BusinessMessagesDeleted getDeletedBusinessMessages() Optional. Messages were deleted from a connected business account + * @method StarTransaction getTransaction() Optional. New incoming transaction; for bots only */ class Update extends Entity { @@ -67,6 +68,7 @@ class Update extends Entity public const TYPE_BUSINESS_MESSAGE = 'business_message'; public const TYPE_EDITED_BUSINESS_MESSAGE = 'edited_business_message'; public const TYPE_DELETED_BUSINESS_MESSAGES = 'deleted_business_messages'; + public const TYPE_TRANSACTION = 'transaction'; /** * {@inheritdoc} @@ -96,6 +98,7 @@ protected function subEntities(): array self::TYPE_BUSINESS_MESSAGE => Message::class, self::TYPE_EDITED_BUSINESS_MESSAGE => Message::class, self::TYPE_DELETED_BUSINESS_MESSAGES => BusinessMessagesDeleted::class, + self::TYPE_TRANSACTION => StarTransaction::class, ]; } diff --git a/src/Entities/WebAppInfo.php b/src/Entities/WebAppInfo.php index 92277431..b577c932 100644 --- a/src/Entities/WebAppInfo.php +++ b/src/Entities/WebAppInfo.php @@ -12,6 +12,9 @@ * @method string getUrl() An HTTPS URL of a Web App to be opened with additional data as specified in Initializing Web Apps * * @method $this setUrl(string $url) An HTTPS URL of a Web App to be opened with additional data as specified in Initializing Web Apps + * + * @method bool getAllowWritingToPm() Optional. If true, a Web App can be opened from a link pressed in a bot's message always in full size, even if the Web App is not designed to support full size layout. Ignored for inline keyboard buttons. + * @method $this setAllowWritingToPm(bool $allowWritingToPm) Optional. If true, a Web App can be opened from a link pressed in a bot's message always in full size, even if the Web App is not designed to support full size layout. Ignored for inline keyboard buttons. */ class WebAppInfo extends Entity { diff --git a/src/Request.php b/src/Request.php index 10a228d2..d03fb0d3 100644 --- a/src/Request.php +++ b/src/Request.php @@ -115,7 +115,7 @@ * @method static ServerResponse getChatMenuButton(array $data) Use this method to get the current value of the bot's menu button in a private chat, or the default menu button. Returns MenuButton on success. * @method static ServerResponse setMyDefaultAdministratorRights(array $data) Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels. These rights will be suggested to users, but they are are free to modify the list before adding the bot. Returns True on success. * @method static ServerResponse getMyDefaultAdministratorRights(array $data) Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success. - * @method static ServerResponse editMessageText(array $data) Use this method to edit text and game messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. + * @method static ServerResponse editMessageText(array $data) Use this method to edit text and game messages. On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. * @method static ServerResponse editMessageCaption(array $data) Use this method to edit captions of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. * @method static ServerResponse editMessageMedia(array $data) Use this method to edit audio, document, photo, or video messages. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned. * @method static ServerResponse editMessageReplyMarkup(array $data) Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned. @@ -329,6 +329,8 @@ class Request 'setGameScore', 'getGameHighScores', 'getBusinessConnection', + 'sendPaidMedia', + 'getStarTransactions', ]; /** @@ -815,11 +817,25 @@ private static function ensureValidAction(string $action): void * * @link https://core.telegram.org/bots/api#sendmessage * - * @todo Splitting formatted text may break the message. - * - * @param array $data + * @param array $data { + * @var int|string $chat_id + * @var string $text + * @var string $parse_mode + * @var Entities\MessageEntity[] $entities + * @var Entities\LinkPreviewOptions $link_preview_options Optional. Link preview generation options for the message + * @var bool $disable_notification + * @var bool $protect_content + * @var int $reply_to_message_id + * @var bool $allow_sending_without_reply + * @var Entities\InlineKeyboard|Entities\ReplyKeyboard|Entities\ReplyKeyboardRemove|Entities\ForceReply $reply_markup + * @var string $business_connection_id Optional. Unique identifier of the business connection on behalf of which the message will be sent + * @var int $message_thread_id Optional. Unique identifier for the target message thread (topic) of the forum; for forum supergroups only + * @var bool $disable_web_page_preview Optional. Disables link previews for links in this message (deprecated, use link_preview_options instead) + * } * @param array|null $extras * + * @todo Splitting formatted text may break the message. + * * @return ServerResponse * @throws TelegramException */ @@ -1007,4 +1023,46 @@ public static function kickChatMember(array $data = []): ServerResponse { return static::banChatMember($data); } + + /** + * Use this method to send paid media. On success, the sent Message is returned. + * + * @link https://core.telegram.org/bots/api#sendpaidmedia + * + * @param array $data + * @return ServerResponse + * @throws TelegramException + */ + public static function sendPaidMedia(array $data): ServerResponse + { + return static::send('sendPaidMedia', $data); + } + + /** + * Returns the bot's Telegram Star transactions in chronological order. + * + * @link https://core.telegram.org/bots/api#getstartransactions + * + * @param array $data + * @return ServerResponse + * @throws TelegramException + */ + public static function getStarTransactions(array $data): ServerResponse + { + return static::send('getStarTransactions', $data); + } + + /** + * Use this method to change the bot's menu button in a private chat, or the default menu button. + * + * @link https://core.telegram.org/bots/api#setchatmenubutton + * + * @param array $data + * @return ServerResponse + * @throws TelegramException + */ + public static function setChatMenuButton(array $data): ServerResponse + { + return static::send('setChatMenuButton', $data); + } } diff --git a/src/Telegram.php b/src/Telegram.php index 7769dc3d..f23b8092 100644 --- a/src/Telegram.php +++ b/src/Telegram.php @@ -37,7 +37,7 @@ class Telegram * * @var string */ - protected $version = '1.0.4'; + protected $version = '1.0.5'; /** @var PredisClient|null */ private $redis_connection;