Passed
Push — master ( 04e5f2...58629d )
by Leonardo
01:35
created

pushKeyboardButtonWithRequestLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LeoCarmo\TelegramBot\Model\Buttons;
4
5
class KeyboardButton extends Button
6
{
7
8
    /**
9
     * @var array
10
     */
11
    protected $reply_markup;
12
13
    /**
14
     * This object represents a custom keyboard with reply options
15
     *
16
     * @url https://core.telegram.org/bots/api#keyboardbutton
17
     * @param bool $resize_keyboard Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons)
18
     * @param bool $one_time_keyboard Requests clients to hide the keyboard as soon as it's been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat – the user can press a special button in the input field to see the custom keyboard again.
19
     * @param bool $selective Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message
20
     */
21
    public function __construct(
22
        bool $resize_keyboard = false,
23
        bool $one_time_keyboard = true,
24
        bool $selective = false
25
    )
26
    {
27
        $this->reply_markup = [
28
            'resize_keyboard' => $resize_keyboard,
29
            'one_time_keyboard' => $one_time_keyboard,
30
            'selective' => $selective,
31
        ];
32
    }
33
34
    /**
35
     * 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
36
     *
37
     * @param string $text
38
     * @return $this
39
     */
40
    public function pushKeyboardButton(string $text)
41
    {
42
        $this->reply_markup['keyboard'][][] = [
43
            'text' => $text
44
        ];
45
        return $this;
46
    }
47
48
    /**
49
     * 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
50
     * The user's phone number will be sent as a contact when the button is pressed. Available in private chats only
51
     *
52
     * @param string $text
53
     * @return $this
54
     */
55
    public function pushKeyboardButtonWithRequestContact(string $text)
56
    {
57
        $this->reply_markup['keyboard'][][] = [
58
            'text' => $text,
59
            'request_contact' => true
60
        ];
61
        return $this;
62
    }
63
64
    /**
65
     * 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
66
     * The user's current location will be sent when the button is pressed. Available in private chats only
67
     *
68
     * @param string $text
69
     * @return $this
70
     */
71
    public function pushKeyboardButtonWithRequestLocation(string $text)
72
    {
73
        $this->reply_markup['keyboard'][][] = [
74
            'text' => $text,
75
            'request_location' => true
76
        ];
77
        return $this;
78
    }
79
80
}