Skip to content

Commit 4ba3ee9

Browse files
committed
Bot API 7.0 - Request for multiple users
1 parent d70ff98 commit 4ba3ee9

File tree

7 files changed

+53
-56
lines changed

7 files changed

+53
-56
lines changed

src/Entities/KeyboardButton.php

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,35 @@
1111

1212
namespace Longman\TelegramBot\Entities;
1313

14-
use Longman\TelegramBot\Exception\TelegramException;
15-
1614
/**
1715
* Class KeyboardButton
1816
*
1917
* This object represents one button of the reply keyboard. For simple text buttons String can be used instead of this object to specify text of the button. Optional fields request_contact, request_location, and request_poll are mutually exclusive.
2018
*
2119
* @link https://core.telegram.org/bots/api#keyboardbutton
2220
*
23-
* @property KeyboardButtonRequestUser $request_user
24-
* @property KeyboardButtonRequestChat $request_chat
25-
* @property bool $request_contact
26-
* @property bool $request_location
27-
* @property KeyboardButtonPollType $request_poll
28-
* @property WebAppInfo $web_app
21+
* @property KeyboardButtonRequestUsers $request_users
22+
* @property KeyboardButtonRequestChat $request_chat
23+
* @property bool $request_contact
24+
* @property bool $request_location
25+
* @property KeyboardButtonPollType $request_poll
26+
* @property WebAppInfo $web_app
2927
*
30-
* @method string getText() Text of the button. If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed
31-
* @method KeyboardButtonRequestUser getRequestUser() Optional. If specified, pressing the button will open a list of suitable users. Tapping on any user will send their identifier to the bot in a “user_shared” service message. Available in private chats only.
32-
* @method KeyboardButtonRequestChat getRequestChat() Optional. If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a “chat_shared” service message. Available in private chats only.
33-
* @method bool getRequestContact() Optional. If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only
34-
* @method bool getRequestLocation() Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only
35-
* @method KeyboardButtonPollType getRequestPoll() Optional. If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only
36-
* @method WebAppInfo getWebApp() Optional. If specified, the described Web App will be launched when the button is pressed. The Web App will be able to send a “web_app_data” service message. Available in private chats only.
28+
* @method string getText() Text of the button. If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed
29+
* @method KeyboardButtonRequestUsers getRequestUsers() Optional. If specified, pressing the button will open a list of suitable users. Identifiers of selected users will be sent to the bot in a “users_shared” service message. Available in private chats only.
30+
* @method KeyboardButtonRequestChat getRequestChat() Optional. If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a “chat_shared” service message. Available in private chats only.
31+
* @method bool getRequestContact() Optional. If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only
32+
* @method bool getRequestLocation() Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only
33+
* @method KeyboardButtonPollType getRequestPoll() Optional. If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only
34+
* @method WebAppInfo getWebApp() Optional. If specified, the described Web App will be launched when the button is pressed. The Web App will be able to send a “web_app_data” service message. Available in private chats only.
3735
*
38-
* @method $this setText(string $text) Text of the button. If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed
39-
* @method $this setRequestUser(KeyboardButtonRequestUser $request_user) Optional. If specified, pressing the button will open a list of suitable users. Tapping on any user will send their identifier to the bot in a “user_shared” service message. Available in private chats only.
40-
* @method $this setRequestChat(KeyboardButtonRequestChat $request_chat) Optional. If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a “chat_shared” service message. Available in private chats only.
41-
* @method $this setRequestContact(bool $request_contact) Optional. If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only
42-
* @method $this setRequestLocation(bool $request_location) Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only
43-
* @method $this setRequestPoll(KeyboardButtonPollType $request_poll) Optional. If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only
44-
* @method $this setWebApp(WebAppInfo $web_app) Optional. If specified, the described Web App will be launched when the button is pressed. The Web App will be able to send a “web_app_data” service message. Available in private chats only.
36+
* @method $this setText(string $text) Text of the button. If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed
37+
* @method $this setRequestUsers(KeyboardButtonRequestUsers $request_users) Optional. If specified, pressing the button will open a list of suitable users. Identifiers of selected users will be sent to the bot in a “users_shared” service message. Available in private chats only.
38+
* @method $this setRequestChat(KeyboardButtonRequestChat $request_chat) Optional. If specified, pressing the button will open a list of suitable chats. Tapping on a chat will send its identifier to the bot in a “chat_shared” service message. Available in private chats only.
39+
* @method $this setRequestContact(bool $request_contact) Optional. If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only
40+
* @method $this setRequestLocation(bool $request_location) Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only
41+
* @method $this setRequestPoll(KeyboardButtonPollType $request_poll) Optional. If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only
42+
* @method $this setWebApp(WebAppInfo $web_app) Optional. If specified, the described Web App will be launched when the button is pressed. The Web App will be able to send a “web_app_data” service message. Available in private chats only.
4543
*/
4644
class KeyboardButton extends Entity
4745
{
@@ -59,10 +57,10 @@ public function __construct($data)
5957
protected function subEntities(): array
6058
{
6159
return [
62-
'request_user' => KeyboardButtonRequestUser::class,
63-
'request_chat' => KeyboardButtonRequestChat::class,
64-
'request_poll' => KeyboardButtonPollType::class,
65-
'web_app' => WebAppInfo::class,
60+
'request_users' => KeyboardButtonRequestUsers::class,
61+
'request_chat' => KeyboardButtonRequestChat::class,
62+
'request_poll' => KeyboardButtonPollType::class,
63+
'web_app' => WebAppInfo::class,
6664
];
6765
}
6866

@@ -84,8 +82,8 @@ public static function couldBe(array $data): bool
8482
public function __call($method, $args)
8583
{
8684
// Only 1 of these can be set, so clear the others when setting a new one.
87-
if (in_array($method, ['setRequestUser', 'setRequestChat', 'setRequestContact', 'setRequestLocation', 'setRequestPoll', 'setWebApp'], true)) {
88-
unset($this->reqest_user, $this->request_chat, $this->request_contact, $this->request_location, $this->request_poll, $this->web_app);
85+
if (in_array($method, ['setRequestUsers', 'setRequestChat', 'setRequestContact', 'setRequestLocation', 'setRequestPoll', 'setWebApp'], true)) {
86+
unset($this->request_users, $this->request_chat, $this->request_contact, $this->request_location, $this->request_poll, $this->web_app);
8987
}
9088

9189
return parent::__call($method, $args);

src/Entities/KeyboardButtonRequestUser.php renamed to src/Entities/KeyboardButtonRequestUsers.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
namespace Longman\TelegramBot\Entities;
44

55
/**
6-
* Class KeyboardButtonRequestUser
6+
* This object defines the criteria used to request suitable users. The identifiers of the selected users will be shared with the bot when the corresponding button is pressed.
77
*
8-
* This entity defines the criteria used to request a suitable user. The identifier of the selected user will be shared with the bot when the corresponding button is pressed.
9-
*
10-
* @link https://core.telegram.org/bots/api#keyboardbuttonrequestuser
8+
* @link https://core.telegram.org/bots/api#keyboardbuttonrequestusers
119
*
1210
* @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
1311
* @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.
1412
* @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.
13+
* @method int getMaxQuantity() Optional. The maximum number of users to be selected; 1-10. Defaults to 1.
1514
*
1615
* @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
1716
* @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.
1817
* @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.
18+
* @method int setMaxQuantity(int $set_max_quantity) Optional. The maximum number of users to be selected; 1-10. Defaults to 1.
1919
*/
20-
class KeyboardButtonRequestUser extends Entity
20+
class KeyboardButtonRequestUsers extends Entity
2121
{
2222

2323
}

src/Entities/Message.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
* @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.
8686
* @method Invoice getInvoice() Optional. Message is an invoice for a payment, information about the invoice.
8787
* @method SuccessfulPayment getSuccessfulPayment() Optional. Message is a service message about a successful payment, information about the payment.
88-
* @method UserShared getUserShared() Optional. Service message: a user was shared with the bot
88+
* @method UsersShared getUsersShared() Optional. Service message: users were shared with the bot
8989
* @method ChatShared getChatShared() Optional. Service message: a chat was shared with the bot
9090
* @method string getConnectedWebsite() Optional. The domain name of the website on which the user has logged in.
9191
* @method WriteAccessAllowed getWriteAccessAllowed() Optional. Service message: the user allowed the bot added to the attachment menu to write messages
@@ -146,7 +146,7 @@ protected function subEntities(): array
146146
'pinned_message' => __CLASS__,
147147
'invoice' => Invoice::class,
148148
'successful_payment' => SuccessfulPayment::class,
149-
'user_shared' => UserShared::class,
149+
'users_shared' => UsersShared::class,
150150
'chat_shared' => ChatShared::class,
151151
'write_access_allowed' => WriteAccessAllowed::class,
152152
'passport_data' => PassportData::class,
@@ -292,7 +292,7 @@ public function getType(): string
292292
'pinned_message',
293293
'invoice',
294294
'successful_payment',
295-
'user_shared',
295+
'users_shared',
296296
'chat_shared',
297297
'write_access_allowed',
298298
'passport_data',

src/Entities/UserShared.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Entities/UsersShared.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Longman\TelegramBot\Entities;
4+
5+
/**
6+
* This object contains information about the users whose identifiers were shared with the bot using a KeyboardButtonRequestUsers button.
7+
*
8+
* @link https://core.telegram.org/bots/api#usersshared
9+
*
10+
* @method int getRequestId() Identifier of the request
11+
* @method int[] getUserIds() Identifier of the shared users.
12+
*/
13+
class UsersShared extends Entity
14+
{
15+
16+
}

structure.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ CREATE TABLE IF NOT EXISTS `message` (
162162
`pinned_message` TEXT NULL COMMENT 'Message object. Specified message was pinned',
163163
`invoice` TEXT NULL COMMENT 'Message is an invoice for a payment, information about the invoice',
164164
`successful_payment` TEXT NULL COMMENT 'Message is a service message about a successful payment, information about the payment',
165-
`user_shared` TEXT NULL COMMENT 'Optional. Service message: a user was shared with the bot',
165+
`users_shared` TEXT NULL COMMENT 'Optional. Service message: users were shared with the bot',
166166
`chat_shared` TEXT NULL COMMENT 'Optional. Service message: a chat was shared with the bot',
167167
`connected_website` TEXT NULL COMMENT 'The domain name of the website on which the user has logged in.',
168168
`write_access_allowed` TEXT DEFAULT NULL COMMENT 'Service message: the user allowed the bot added to the attachment menu to write messages',

utils/db-schema-update/0.82.0-unreleased.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ CREATE TABLE IF NOT EXISTS `message_reaction_count` (
3333

3434
ALTER TABLE `message`
3535
ADD COLUMN `external_reply` TEXT NULL DEFAULT NULL COMMENT 'Optional. Information about the message that is being replied to, which may come from another chat or forum topic' AFTER `reply_to_message`,
36-
ADD COLUMN `link_preview_options` TEXT NULL DEFAULT NULL COMMENT 'Optional. Options used for link preview generation for the message, if it is a text message and link preview options were changed' AFTER `via_bot`;
36+
ADD COLUMN `link_preview_options` TEXT NULL DEFAULT NULL COMMENT 'Optional. Options used for link preview generation for the message, if it is a text message and link preview options were changed' AFTER `via_bot`,
37+
RENAME COLUMN `user_shared` TO `users_shared`;
3738

3839
ALTER TABLE `telegram_update`
3940
ADD COLUMN `message_reaction_id` bigint UNSIGNED DEFAULT NULL COMMENT 'A reaction to a message was changed by a user' AFTER `edited_channel_post_id`,

0 commit comments

Comments
 (0)