You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://telegram.me/PHP_Telegram_Bot_Support)
Copy file name to clipboardExpand all lines: src/Entities/KeyboardButton.php
+23-12Lines changed: 23 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -16,18 +16,23 @@
16
16
/**
17
17
* Class KeyboardButton
18
18
*
19
+
* 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.
* @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
25
-
* @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
26
-
* @method bool getRequestLocation() Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only
27
+
* @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
28
+
* @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
29
+
* @method bool getRequestLocation() Optional. If True, the user's current location will be sent when the button is pressed. Available in private chats only
30
+
* @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
27
31
*
28
-
* @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
29
-
* @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
30
-
* @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
32
+
* @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
33
+
* @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
34
+
* @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
35
+
* @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
31
36
*/
32
37
class KeyboardButton extends Entity
33
38
{
@@ -63,8 +68,14 @@ protected function validate()
63
68
thrownewTelegramException('You must add some text to the button!');
64
69
}
65
70
66
-
if ($this->getRequestContact() && $this->getRequestLocation()) {
67
-
thrownewTelegramException('You must use only one of these fields: request_contact, request_location!');
71
+
// Make sure only 1 of the optional request fields is set.
72
+
$field_count = array_filter([
73
+
$this->getRequestContact(),
74
+
$this->getRequestLocation(),
75
+
$this->getRequestPoll(),
76
+
]);
77
+
if (count($field_count) > 1) {
78
+
thrownewTelegramException('You must use only one of these fields: request_contact, request_location, request_poll!');
68
79
}
69
80
}
70
81
@@ -74,8 +85,8 @@ protected function validate()
74
85
publicfunction__call($method, $args)
75
86
{
76
87
// Only 1 of these can be set, so clear the others when setting a new one.
77
-
if (in_array($method, ['setRequestContact', 'setRequestLocation'], true)) {
* @method string getType() Optional. If 'quiz' is passed, the user will be allowed to create only polls in the quiz mode. If 'regular' is passed, only regular polls will be allowed. Otherwise, the user will be allowed to create a poll of any type.
22
+
*
23
+
* @method $this setType(string $type) Optional. If 'quiz' is passed, the user will be allowed to create only polls in the quiz mode. If 'regular' is passed, only regular polls will be allowed. Otherwise, the user will be allowed to create a poll of any type.
* @method PollOption[] getOptions() List of poll options
24
+
* @method int getTotalVoterCount() Total number of users that voted in the poll
25
+
* @method bool getIsClosed() True, if the poll is closed
26
+
* @method bool getIsAnonymous() True, if the poll is anonymous
27
+
* @method string getType() Poll type, currently can be “regular” or “quiz”
28
+
* @method bool getAllowsMultipleAnswers() True, if the poll allows multiple answers
29
+
* @method int getCorrectOptionId() Optional. 0-based identifier of the correct answer option. Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) by the bot or to the private chat with the bot.
0 commit comments