From 676e452dd283d310501c5079cb67f86f940725ad Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 4 Jul 2025 23:11:32 +0000 Subject: [PATCH] feat: Implement Telegram Bot API 7.2 features --- src/Entities/Birthdate.php | 28 +++++++ src/Entities/BusinessConnection.php | 30 +++++++ src/Entities/BusinessIntro.php | 36 ++++++++ src/Entities/BusinessLocation.php | 35 ++++++++ src/Entities/BusinessMessagesDeleted.php | 36 ++++++++ src/Entities/BusinessOpeningHours.php | 35 ++++++++ src/Entities/BusinessOpeningHoursInterval.php | 27 ++++++ src/Entities/Chat.php | 20 +++-- src/Entities/ChatShared.php | 17 +++- src/Entities/InputSticker.php | 1 + src/Entities/KeyboardButtonRequestChat.php | 6 ++ src/Entities/KeyboardButtonRequestUsers.php | 22 +++-- src/Entities/Message.php | 3 + src/Entities/SharedUser.php | 38 +++++++++ src/Entities/StickerSet.php | 2 - src/Entities/Update.php | 84 +++++++++++-------- src/Entities/User.php | 1 + src/Entities/UsersShared.php | 14 +++- src/Request.php | 16 +++- 19 files changed, 391 insertions(+), 60 deletions(-) create mode 100644 src/Entities/Birthdate.php create mode 100644 src/Entities/BusinessConnection.php create mode 100644 src/Entities/BusinessIntro.php create mode 100644 src/Entities/BusinessLocation.php create mode 100644 src/Entities/BusinessMessagesDeleted.php create mode 100644 src/Entities/BusinessOpeningHours.php create mode 100644 src/Entities/BusinessOpeningHoursInterval.php create mode 100644 src/Entities/SharedUser.php diff --git a/src/Entities/Birthdate.php b/src/Entities/Birthdate.php new file mode 100644 index 00000000..4992897c --- /dev/null +++ b/src/Entities/Birthdate.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Longman\TelegramBot\Entities; + +/** + * Class Birthdate + * + * Represents a birthdate of a user. + * + * @link https://core.telegram.org/bots/api#birthdate + * + * @method int getDay() Day of the month; 1-31 + * @method int getMonth() Month of the year; 1-12 + * @method int getYear() Optional. Year of birth; 1900-2100 + */ +class Birthdate extends Entity +{ + +} diff --git a/src/Entities/BusinessConnection.php b/src/Entities/BusinessConnection.php new file mode 100644 index 00000000..a14f596a --- /dev/null +++ b/src/Entities/BusinessConnection.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Longman\TelegramBot\Entities; + +/** + * Class BusinessConnection + * + * Describes the connection of the bot with a business account. + * + * @link https://core.telegram.org/bots/api#businessconnection + * + * @method string getId() Unique identifier of the business connection + * @method int getUserChatId() Business account user that created the business connection + * @method int getDate() Date the connection was established in Unix time + * @method bool getCanReply() True, if the bot can act on behalf of the business account in chats that were active in the last 24 hours + * @method bool getIsEnabled() True, if the business connection is active + */ +class BusinessConnection extends Entity +{ + +} diff --git a/src/Entities/BusinessIntro.php b/src/Entities/BusinessIntro.php new file mode 100644 index 00000000..55f804e9 --- /dev/null +++ b/src/Entities/BusinessIntro.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Longman\TelegramBot\Entities; + +/** + * Class BusinessIntro + * + * Describes the introductory message of a business account. + * + * @link https://core.telegram.org/bots/api#businessintro + * + * @method string getTitle() Optional. Title text of the business intro + * @method string getMessage() Optional. Message text of the business intro + * @method Sticker getSticker() Optional. Sticker of the business intro + */ +class BusinessIntro extends Entity +{ + /** + * {@inheritdoc} + */ + protected function subEntities(): array + { + return [ + 'sticker' => Sticker::class, + ]; + } +} diff --git a/src/Entities/BusinessLocation.php b/src/Entities/BusinessLocation.php new file mode 100644 index 00000000..ee327618 --- /dev/null +++ b/src/Entities/BusinessLocation.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Longman\TelegramBot\Entities; + +/** + * Class BusinessLocation + * + * Contains information about the location of a business. + * + * @link https://core.telegram.org/bots/api#businesslocation + * + * @method string getAddress() Address of the business + * @method Location getLocation() Optional. Location of the business + */ +class BusinessLocation extends Entity +{ + /** + * {@inheritdoc} + */ + protected function subEntities(): array + { + return [ + 'location' => Location::class, + ]; + } +} diff --git a/src/Entities/BusinessMessagesDeleted.php b/src/Entities/BusinessMessagesDeleted.php new file mode 100644 index 00000000..45f9ed5e --- /dev/null +++ b/src/Entities/BusinessMessagesDeleted.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Longman\TelegramBot\Entities; + +/** + * Class BusinessMessagesDeleted + * + * This object is received when messages are deleted from a business account. + * + * @link https://core.telegram.org/bots/api#businessmessagesdeleted + * + * @method string getBusinessConnectionId() Unique identifier of the business connection + * @method Chat getChat() Information about a chat in the business account. The bot may not have access to the chat or the corresponding user. + * @method int[] getMessageIds() A list of identifiers of deleted messages in the chat of the business account + */ +class BusinessMessagesDeleted extends Entity +{ + /** + * {@inheritdoc} + */ + protected function subEntities(): array + { + return [ + 'chat' => Chat::class, + ]; + } +} diff --git a/src/Entities/BusinessOpeningHours.php b/src/Entities/BusinessOpeningHours.php new file mode 100644 index 00000000..9c21838c --- /dev/null +++ b/src/Entities/BusinessOpeningHours.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Longman\TelegramBot\Entities; + +/** + * Class BusinessOpeningHours + * + * Describes the opening hours of a business. + * + * @link https://core.telegram.org/bots/api#businessopeninghours + * + * @method string getTimeZoneName() Unique name of the time zone for which the opening hours are defined + * @method BusinessOpeningHoursInterval[] getOpeningHours() List of time intervals describing business opening hours + */ +class BusinessOpeningHours extends Entity +{ + /** + * {@inheritdoc} + */ + protected function subEntities(): array + { + return [ + 'opening_hours' => [BusinessOpeningHoursInterval::class], + ]; + } +} diff --git a/src/Entities/BusinessOpeningHoursInterval.php b/src/Entities/BusinessOpeningHoursInterval.php new file mode 100644 index 00000000..000c6940 --- /dev/null +++ b/src/Entities/BusinessOpeningHoursInterval.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Longman\TelegramBot\Entities; + +/** + * Class BusinessOpeningHoursInterval + * + * Describes an interval of time during which a business is open. + * + * @link https://core.telegram.org/bots/api#businessopeninghoursinterval + * + * @method int getOpeningMinute() The minute's sequence number in a week, starting on Monday, marking the start of the time interval during which the business is open; 0 - 7 * 24 * 60 + * @method int getClosingMinute() The minute's sequence number in a week, starting on Monday, marking the end of the time interval during which the business is open; 0 - 8 * 24 * 60 + */ +class BusinessOpeningHoursInterval extends Entity +{ + +} diff --git a/src/Entities/Chat.php b/src/Entities/Chat.php index 284e58b4..23bbba74 100644 --- a/src/Entities/Chat.php +++ b/src/Entities/Chat.php @@ -58,6 +58,11 @@ * @method string getCustomEmojiStickerSetName() Optional. For supergroups, the name of the group's custom emoji sticker set. Custom emoji from this set can be used by all users and bots in the group. * @method int getLinkedChatId() Optional. Unique identifier for the linked chat. Returned only in getChat. * @method ChatLocation getLocation() Optional. For supergroups, the location to which the supergroup is connected. Returned only in getChat. + * @method BusinessIntro getBusinessIntro() Optional. For private chats with business accounts, the intro of the business. Returned only in getChat. + * @method BusinessLocation getBusinessLocation() Optional. For private chats with business accounts, the location of the business. Returned only in getChat. + * @method BusinessOpeningHours getBusinessOpeningHours() Optional. For private chats with business accounts, the opening hours of the business. Returned only in getChat. + * @method Chat getPersonalChat() Optional. For private chats, the personal channel of the user. Returned only in getChat. + * @method Birthdate getBirthdate() Optional. For private chats with ordinary users, the user's birthdate. Returned only in getChat. */ class Chat extends Entity { @@ -67,11 +72,16 @@ class Chat extends Entity protected function subEntities(): array { return [ - 'photo' => ChatPhoto::class, - 'available_reactions' => [ReactionTypeFactory::class], - 'pinned_message' => Message::class, - 'permissions' => ChatPermissions::class, - 'location' => ChatLocation::class, + 'photo' => ChatPhoto::class, + 'available_reactions' => [ReactionTypeFactory::class], + 'pinned_message' => Message::class, + 'permissions' => ChatPermissions::class, + 'location' => ChatLocation::class, + 'business_intro' => BusinessIntro::class, + 'business_location' => BusinessLocation::class, + 'business_opening_hours' => BusinessOpeningHours::class, + 'personal_chat' => Chat::class, + 'birthdate' => Birthdate::class, ]; } diff --git a/src/Entities/ChatShared.php b/src/Entities/ChatShared.php index 5987d36d..0b23864c 100644 --- a/src/Entities/ChatShared.php +++ b/src/Entities/ChatShared.php @@ -9,10 +9,21 @@ * * @link https://core.telegram.org/bots/api#chatshared * - * @method int getRequestId() Identifier of the request - * @method int getChatId() Identifier of the shared chat. + * @method int getRequestId() Identifier of the request + * @method int getChatId() Identifier of the shared chat. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so a 64-bit integer or double-precision float type are safe for storing this identifier. The bot may not have access to the chat and could be unable to use this identifier, unless the chat is already known to the bot by some other means. + * @method string getTitle() Optional. Title of the chat, if the title was requested by the bot + * @method string getUsername() Optional. Username of the chat, if the username was requested by the bot + * @method PhotoSize[] getPhoto() Optional. Available sizes of the chat photo, if the photo was requested by the bot */ class ChatShared extends Entity { - + /** + * {@inheritdoc} + */ + protected function subEntities(): array + { + return [ + 'photo' => [PhotoSize::class], + ]; + } } diff --git a/src/Entities/InputSticker.php b/src/Entities/InputSticker.php index 2fa40e01..3c23e1a7 100644 --- a/src/Entities/InputSticker.php +++ b/src/Entities/InputSticker.php @@ -13,6 +13,7 @@ * @method string[] getEmojiList() List of 1-20 emoji associated with the sticker * @method MaskPosition getMaskPosition() Optional. Position where the mask should be placed on faces. For “mask” stickers only. * @method string[] getKeywords() Optional. List of 0-20 search keywords for the sticker with total length of up to 64 characters. For “regular” and “custom_emoji” stickers only. + * @method string getFormat() Format of the sticker, must be one of “static”, “animated”, “video” */ class InputSticker extends Entity { diff --git a/src/Entities/KeyboardButtonRequestChat.php b/src/Entities/KeyboardButtonRequestChat.php index 02cdf29f..28362bcb 100644 --- a/src/Entities/KeyboardButtonRequestChat.php +++ b/src/Entities/KeyboardButtonRequestChat.php @@ -17,6 +17,9 @@ * @method ChatAdministratorRights getUserAdministratorRights() Optional. A JSON-serialized object listing the required administrator rights of the user in the chat. The rights must be a superset of bot_administrator_rights. If not specified, no additional restrictions are applied. * @method ChatAdministratorRights getBotAdministratorRights() Optional. A JSON-serialized object listing the required administrator rights of the bot in the chat. The rights must be a subset of user_administrator_rights. If not specified, no additional restrictions are applied. * @method bool getBotIsMember() Optional. Pass True to request a chat with the bot as a member. Otherwise, no additional restrictions are applied. + * @method bool getRequestTitle() Optional. Pass True to request the chat's title + * @method bool getRequestUsername() Optional. Pass True to request the chat's username + * @method bool getRequestPhoto() Optional. Pass True to request the chat's photo * * @method $this setRequestId(int $request_id) Signed 32-bit identifier of the request, which will be received back in the ChatShared object. Must be unique within the message * @method $this setChatIsChannel(bool $chat_is_channel) Pass True to request a channel chat, pass False to request a group or a supergroup chat. @@ -26,6 +29,9 @@ * @method $this setUserAdministratorRights(ChatAdministratorRights $user_administrator_rights) Optional. A JSON-serialized object listing the required administrator rights of the user in the chat. The rights must be a superset of bot_administrator_rights. If not specified, no additional restrictions are applied. * @method $this setBotAdministratorRights(ChatAdministratorRights $bot_administrator_rights) Optional. A JSON-serialized object listing the required administrator rights of the bot in the chat. The rights must be a subset of user_administrator_rights. If not specified, no additional restrictions are applied. * @method $this setBotIsMember(bool $bot_is_member) Optional. Pass True to request a chat with the bot as a member. Otherwise, no additional restrictions are applied. + * @method $this setRequestTitle(bool $request_title) Optional. Pass True to request the chat's title + * @method $this setRequestUsername(bool $request_username) Optional. Pass True to request the chat's username + * @method $this setRequestPhoto(bool $request_photo) Optional. Pass True to request the chat's photo */ class KeyboardButtonRequestChat extends Entity { diff --git a/src/Entities/KeyboardButtonRequestUsers.php b/src/Entities/KeyboardButtonRequestUsers.php index 945bafa9..4347710e 100644 --- a/src/Entities/KeyboardButtonRequestUsers.php +++ b/src/Entities/KeyboardButtonRequestUsers.php @@ -7,15 +7,21 @@ * * @link https://core.telegram.org/bots/api#keyboardbuttonrequestusers * - * @method int getRequestId() Signed 32-bit identifier of the request, which will be received back in the UserShared object. Must be unique within the message - * @method bool getUserIsBot() Optional. Pass True to request a bot, pass False to request a regular user. If not specified, no additional restrictions are applied. - * @method bool getUserIsPremium() Optional. Pass True to request a premium user, pass False to request a non-premium user. If not specified, no additional restrictions are applied. - * @method int getMaxQuantity() Optional. The maximum number of users to be selected; 1-10. Defaults to 1. + * @method int getRequestId() Signed 32-bit identifier of the request, which will be received back in the UserShared object. Must be unique within the message + * @method bool getUserIsBot() Optional. Pass True to request a bot, pass False to request a regular user. If not specified, no additional restrictions are applied. + * @method bool getUserIsPremium() Optional. Pass True to request a premium user, pass False to request a non-premium user. If not specified, no additional restrictions are applied. + * @method int getMaxQuantity() Optional. The maximum number of users to be selected; 1-10. Defaults to 1. + * @method bool getRequestName() Optional. Pass True to request the users' first and last names + * @method bool getRequestUsername() Optional. Pass True to request the users' usernames + * @method bool getRequestPhoto() Optional. Pass True to request the users' photos * - * @method $this setRequestId(int $request_id) Signed 32-bit identifier of the request, which will be received back in the UserShared object. Must be unique within the message - * @method $this setUserIsBot(bool $user_is_bot) Optional. Pass True to request a bot, pass False to request a regular user. If not specified, no additional restrictions are applied. - * @method $this setUserIsPremium(bool $user_is_premium) Optional. Pass True to request a premium user, pass False to request a non-premium user. If not specified, no additional restrictions are applied. - * @method int setMaxQuantity(int $set_max_quantity) Optional. The maximum number of users to be selected; 1-10. Defaults to 1. + * @method $this setRequestId(int $request_id) Signed 32-bit identifier of the request, which will be received back in the UserShared object. Must be unique within the message + * @method $this setUserIsBot(bool $user_is_bot) Optional. Pass True to request a bot, pass False to request a regular user. If not specified, no additional restrictions are applied. + * @method $this setUserIsPremium(bool $user_is_premium) Optional. Pass True to request a premium user, pass False to request a non-premium user. If not specified, no additional restrictions are applied. + * @method $this setMaxQuantity(int $set_max_quantity) Optional. The maximum number of users to be selected; 1-10. Defaults to 1. + * @method $this setRequestName(bool $request_name) Optional. Pass True to request the users' first and last names + * @method $this setRequestUsername(bool $request_username) Optional. Pass True to request the users' usernames + * @method $this setRequestPhoto(bool $request_photo) Optional. Pass True to request the users' photos */ class KeyboardButtonRequestUsers extends Entity { diff --git a/src/Entities/Message.php b/src/Entities/Message.php index f8baa984..e254f8a1 100644 --- a/src/Entities/Message.php +++ b/src/Entities/Message.php @@ -113,6 +113,9 @@ * @method VideoChatParticipantsInvited getVideoChatParticipantsInvited() Optional. Service message: new participants invited to a voice chat * @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. + * @method string getBusinessConnectionId() Optional. Unique identifier of the business connection from which the message was received. If non-empty, the message is business_message. + * @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. */ class Message extends Entity implements MaybeInaccessibleMessage { diff --git a/src/Entities/SharedUser.php b/src/Entities/SharedUser.php new file mode 100644 index 00000000..bc6be1ae --- /dev/null +++ b/src/Entities/SharedUser.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Longman\TelegramBot\Entities; + +/** + * Class SharedUser + * + * This object contains information about a user that was shared with the bot using a KeyboardButtonRequestUsers button. + * + * @link https://core.telegram.org/bots/api#shareduser + * + * @method int getUserId() Identifier of the shared user. This number may have more than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it. But it has at most 52 significant bits, so 64-bit integers or double-precision float types are safe for storing this identifier. The bot may not have access to the user and could be unable to use this identifier, unless the user is already known to the bot by some other means. + * @method string getFirstName() Optional. First name of the user, if the name was requested by the bot + * @method string getLastName() Optional. Last name of the user, if the name was requested by the bot + * @method string getUsername() Optional. Username of the user, if the username was requested by the bot + * @method PhotoSize[] getPhoto() Optional. Available sizes of the user photo, if the photo was requested by the bot + */ +class SharedUser extends Entity +{ + /** + * {@inheritdoc} + */ + protected function subEntities(): array + { + return [ + 'photo' => [PhotoSize::class], + ]; + } +} diff --git a/src/Entities/StickerSet.php b/src/Entities/StickerSet.php index 8bb35ec4..477e4bc3 100644 --- a/src/Entities/StickerSet.php +++ b/src/Entities/StickerSet.php @@ -19,8 +19,6 @@ * @method string getName() Sticker set name * @method string getTitle() Sticker set title * @method string getStickerType() Type of stickers in the set, currently one of “regular”, “mask”, “custom_emoji” - * @method bool getIsAnimated() True, if the sticker set contains animated stickers - * @method bool getIsVideo() True, if the sticker set contains video stickers * @method Sticker[] getStickers() List of all set stickers * @method PhotoSize getThumbnail() Optional. Sticker set thumbnail in the .WEBP or .TGS format */ diff --git a/src/Entities/Update.php b/src/Entities/Update.php index 716b1830..cc47a90e 100644 --- a/src/Entities/Update.php +++ b/src/Entities/Update.php @@ -38,27 +38,35 @@ * @method ChatJoinRequest getChatJoinRequest() Optional. A request to join the chat has been sent. The bot must have the can_invite_users administrator right in the chat to receive these updates. * @method ChatBoostUpdated getChatBoost() Optional. A chat boost was added or changed. The bot must be an administrator in the chat to receive these updates. * @method ChatBoostRemoved getRemovedChatBoost() Optional. A boost was removed from a chat. The bot must be an administrator in the chat to receive these updates. + * @method BusinessConnection getBusinessConnection() Optional. The bot was connected to or disconnected from a business account, or a user edited an existing connection with the bot + * @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 */ class Update extends Entity { - public const TYPE_MESSAGE = 'message'; - public const TYPE_EDITED_MESSAGE = 'edited_message'; - public const TYPE_CHANNEL_POST = 'channel_post'; - public const TYPE_EDITED_CHANNEL_POST = 'edited_channel_post'; - public const TYPE_MESSAGE_REACTION = 'message_reaction'; - public const TYPE_MESSAGE_REACTION_COUNT = 'message_reaction_count'; - public const TYPE_INLINE_QUERY = 'inline_query'; - public const TYPE_CHOSEN_INLINE_RESULT = 'chosen_inline_result'; - public const TYPE_CALLBACK_QUERY = 'callback_query'; - public const TYPE_SHIPPING_QUERY = 'shipping_query'; - public const TYPE_PRE_CHECKOUT_QUERY = 'pre_checkout_query'; - public const TYPE_POLL = 'poll'; - public const TYPE_POLL_ANSWER = 'poll_answer'; - public const TYPE_MY_CHAT_MEMBER = 'my_chat_member'; - public const TYPE_CHAT_MEMBER = 'chat_member'; - public const TYPE_CHAT_JOIN_REQUEST = 'chat_join_request'; - public const TYPE_CHAT_BOOST = 'chat_boost'; - public const TYPE_REMOVED_CHAT_BOOST = 'removed_chat_boost'; + public const TYPE_MESSAGE = 'message'; + public const TYPE_EDITED_MESSAGE = 'edited_message'; + public const TYPE_CHANNEL_POST = 'channel_post'; + public const TYPE_EDITED_CHANNEL_POST = 'edited_channel_post'; + public const TYPE_MESSAGE_REACTION = 'message_reaction'; + public const TYPE_MESSAGE_REACTION_COUNT = 'message_reaction_count'; + public const TYPE_INLINE_QUERY = 'inline_query'; + public const TYPE_CHOSEN_INLINE_RESULT = 'chosen_inline_result'; + public const TYPE_CALLBACK_QUERY = 'callback_query'; + public const TYPE_SHIPPING_QUERY = 'shipping_query'; + public const TYPE_PRE_CHECKOUT_QUERY = 'pre_checkout_query'; + public const TYPE_POLL = 'poll'; + public const TYPE_POLL_ANSWER = 'poll_answer'; + public const TYPE_MY_CHAT_MEMBER = 'my_chat_member'; + public const TYPE_CHAT_MEMBER = 'chat_member'; + public const TYPE_CHAT_JOIN_REQUEST = 'chat_join_request'; + public const TYPE_CHAT_BOOST = 'chat_boost'; + public const TYPE_REMOVED_CHAT_BOOST = 'removed_chat_boost'; + public const TYPE_BUSINESS_CONNECTION = 'business_connection'; + 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'; /** * {@inheritdoc} @@ -66,24 +74,28 @@ class Update extends Entity protected function subEntities(): array { return [ - self::TYPE_MESSAGE => Message::class, - self::TYPE_EDITED_MESSAGE => EditedMessage::class, - self::TYPE_CHANNEL_POST => ChannelPost::class, - self::TYPE_EDITED_CHANNEL_POST => EditedChannelPost::class, - self::TYPE_MESSAGE_REACTION => MessageReactionUpdated::class, - self::TYPE_MESSAGE_REACTION_COUNT => MessageReactionCountUpdated::class, - self::TYPE_INLINE_QUERY => InlineQuery::class, - self::TYPE_CHOSEN_INLINE_RESULT => ChosenInlineResult::class, - self::TYPE_CALLBACK_QUERY => CallbackQuery::class, - self::TYPE_SHIPPING_QUERY => ShippingQuery::class, - self::TYPE_PRE_CHECKOUT_QUERY => PreCheckoutQuery::class, - self::TYPE_POLL => Poll::class, - self::TYPE_POLL_ANSWER => PollAnswer::class, - self::TYPE_MY_CHAT_MEMBER => ChatMemberUpdated::class, - self::TYPE_CHAT_MEMBER => ChatMemberUpdated::class, - self::TYPE_CHAT_JOIN_REQUEST => ChatJoinRequest::class, - self::TYPE_CHAT_BOOST => ChatBoostUpdated::class, - self::TYPE_REMOVED_CHAT_BOOST => ChatBoostRemoved::class, + self::TYPE_MESSAGE => Message::class, + self::TYPE_EDITED_MESSAGE => EditedMessage::class, + self::TYPE_CHANNEL_POST => ChannelPost::class, + self::TYPE_EDITED_CHANNEL_POST => EditedChannelPost::class, + self::TYPE_MESSAGE_REACTION => MessageReactionUpdated::class, + self::TYPE_MESSAGE_REACTION_COUNT => MessageReactionCountUpdated::class, + self::TYPE_INLINE_QUERY => InlineQuery::class, + self::TYPE_CHOSEN_INLINE_RESULT => ChosenInlineResult::class, + self::TYPE_CALLBACK_QUERY => CallbackQuery::class, + self::TYPE_SHIPPING_QUERY => ShippingQuery::class, + self::TYPE_PRE_CHECKOUT_QUERY => PreCheckoutQuery::class, + self::TYPE_POLL => Poll::class, + self::TYPE_POLL_ANSWER => PollAnswer::class, + self::TYPE_MY_CHAT_MEMBER => ChatMemberUpdated::class, + self::TYPE_CHAT_MEMBER => ChatMemberUpdated::class, + self::TYPE_CHAT_JOIN_REQUEST => ChatJoinRequest::class, + self::TYPE_CHAT_BOOST => ChatBoostUpdated::class, + self::TYPE_REMOVED_CHAT_BOOST => ChatBoostRemoved::class, + self::TYPE_BUSINESS_CONNECTION => BusinessConnection::class, + self::TYPE_BUSINESS_MESSAGE => Message::class, + self::TYPE_EDITED_BUSINESS_MESSAGE => Message::class, + self::TYPE_DELETED_BUSINESS_MESSAGES => BusinessMessagesDeleted::class, ]; } diff --git a/src/Entities/User.php b/src/Entities/User.php index bc412b01..aaa2ea4b 100644 --- a/src/Entities/User.php +++ b/src/Entities/User.php @@ -27,6 +27,7 @@ * @method bool getCanJoinGroups() Optional. True, if the bot can be invited to groups. Returned only in getMe. * @method bool getCanReadAllGroupMessages() Optional. True, if privacy mode is disabled for the bot. Returned only in getMe. * @method bool getSupportsInlineQueries() Optional. True, if the bot supports inline queries. Returned only in getMe. + * @method bool getCanConnectToBusiness() Optional. True, if the bot can be connected to a Telegram Business account to receive its messages. Returned only in getMe. */ class User extends Entity { diff --git a/src/Entities/UsersShared.php b/src/Entities/UsersShared.php index ab32c2c9..1640311f 100644 --- a/src/Entities/UsersShared.php +++ b/src/Entities/UsersShared.php @@ -7,10 +7,18 @@ * * @link https://core.telegram.org/bots/api#usersshared * - * @method int getRequestId() Identifier of the request - * @method int[] getUserIds() Identifier of the shared users. + * @method int getRequestId() Identifier of the request + * @method SharedUser[] getUsers() Information about users shared with the bot. */ class UsersShared extends Entity { - + /** + * {@inheritdoc} + */ + protected function subEntities(): array + { + return [ + 'users' => [SharedUser::class], + ]; + } } diff --git a/src/Request.php b/src/Request.php index 10fafd1e..1989d477 100644 --- a/src/Request.php +++ b/src/Request.php @@ -125,8 +125,9 @@ * @method static ServerResponse getStickerSet(array $data) Use this method to get a sticker set. On success, a StickerSet object is returned. * @method static ServerResponse getCustomEmojiStickers(array $data) Use this method to get information about custom emoji stickers by their identifiers. Returns an Array of Sticker objects. * @method static ServerResponse uploadStickerFile(array $data) Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times). Returns the uploaded File on success. - * @method static ServerResponse createNewStickerSet(array $data) Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set. Returns True on success. + * @method static ServerResponse createNewStickerSet(array $data) Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. You must use exactly one of the fields png_sticker, tgs_sticker, or webm_sticker. Returns True on success. * @method static ServerResponse addStickerToSet(array $data) Use this method to add a new sticker to a set created by the bot. Returns True on success. + * @method static ServerResponse replaceStickerInSet(array $data) Use this method to replace a sticker in a set created by the bot with a new one. The sticker must be in WEBP, TGS, or WEBM format. Returns True on success. * @method static ServerResponse setStickerPositionInSet(array $data) Use this method to move a sticker in a set created by the bot to a specific position. Returns True on success. * @method static ServerResponse deleteStickerFromSet(array $data) Use this method to delete a sticker from a set created by the bot. Returns True on success. * @method static ServerResponse setStickerEmojiList(array $data) Use this method to change the list of emoji assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success. @@ -308,6 +309,7 @@ class Request 'uploadStickerFile', 'createNewStickerSet', 'addStickerToSet', + 'replaceStickerInSet', 'setStickerPositionInSet', 'deleteStickerFromSet', 'setStickerEmojiList', @@ -326,6 +328,7 @@ class Request 'sendGame', 'setGameScore', 'getGameHighScores', + 'getBusinessConnection', ]; /** @@ -833,10 +836,17 @@ public static function sendMessage(array $data, ?array &$extras = []): ServerRes $responses = []; + // business_connection_id should be in all split messages + $business_connection_id = $data['business_connection_id'] ?? null; + do { // Chop off and send the first message. - $data['text'] = mb_substr($text, 0, $max_length, $encoding); - $responses[] = self::send('sendMessage', $data); + $current_data = $data; // Create a copy to avoid modifying the original $data array in loop + $current_data['text'] = mb_substr($text, 0, $max_length, $encoding); + if ($business_connection_id !== null) { + $current_data['business_connection_id'] = $business_connection_id; + } + $responses[] = self::send('sendMessage', $current_data); // Prepare the next message. $text = mb_substr($text, $max_length, null, $encoding);