|
1
|
|
|
<?php |
|
2
|
|
|
namespace Telegram\Bot\Keyboard; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Class Keyboard |
|
6
|
|
|
* |
|
7
|
|
|
* <code> |
|
8
|
|
|
* // For Standard Keyboard |
|
9
|
|
|
* $params = [ |
|
10
|
|
|
* 'keyboard' => '', |
|
11
|
|
|
* 'resize_keyboard' => '', |
|
12
|
|
|
* 'one_time_keyboard' => '', |
|
13
|
|
|
* 'selective' => '', |
|
14
|
|
|
* ]; |
|
15
|
|
|
* </code> |
|
16
|
|
|
* |
|
17
|
|
|
* OR |
|
18
|
|
|
* |
|
19
|
|
|
* <code> |
|
20
|
|
|
* // For Inline Keyboard |
|
21
|
|
|
* $params = [ |
|
22
|
|
|
* 'inline_keyboard' => '', |
|
23
|
|
|
* ]; |
|
24
|
|
|
* </code> |
|
25
|
|
|
* |
|
26
|
|
|
* @method $this setResizeKeyboard($boolean) Optional. Requests clients to resize the keyboard vertically for optimal fit. |
|
27
|
|
|
* @method $this setOneTimeKeyboard($boolean) Optional. Requests clients to hide the keyboard as soon as it's been used. |
|
28
|
|
|
* @method $this setSelective($boolean) Optional. Use this parameter if you want to show the keyboard to specific users only. |
|
29
|
|
|
*/ |
|
30
|
|
|
class Keyboard extends Base |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* Make an Inline Keyboard |
|
34
|
|
|
* |
|
35
|
|
|
* @var bool |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $inline = false; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Make this keyboard inline, So it appears right next to the message it belongs to. |
|
41
|
|
|
* |
|
42
|
|
|
* @link https://core.telegram.org/bots/api#inlinekeyboardmarkup |
|
43
|
|
|
* |
|
44
|
|
|
* @return $this |
|
45
|
|
|
*/ |
|
46
|
|
|
public function inline() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->inline = true; |
|
49
|
|
|
|
|
50
|
|
|
return $this; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Determine if it's an inline keyboard. |
|
55
|
|
|
* |
|
56
|
|
|
* @return bool |
|
57
|
|
|
*/ |
|
58
|
|
|
public function isInlineKeyboard() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->inline; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Create a new row in keyboard to add buttons. |
|
65
|
|
|
* |
|
66
|
|
|
* @return $this |
|
67
|
|
|
*/ |
|
68
|
|
|
public function row() |
|
69
|
|
|
{ |
|
70
|
|
|
$property = 'keyboard'; |
|
71
|
|
|
if ($this->isInlineKeyboard()) { |
|
72
|
|
|
$property = 'inline_keyboard'; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$this->items[$property][] = func_get_args(); |
|
76
|
|
|
|
|
77
|
|
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Represents one button of the Reply keyboard. |
|
82
|
|
|
* |
|
83
|
|
|
* For simple text buttons String can be used instead of an array. |
|
84
|
|
|
* You can also utilise the fluent API to build the params payload. |
|
85
|
|
|
* |
|
86
|
|
|
* <code> |
|
87
|
|
|
* $params = 'string' |
|
88
|
|
|
* |
|
89
|
|
|
* OR |
|
90
|
|
|
* |
|
91
|
|
|
* $params = [ |
|
92
|
|
|
* 'text' => '', |
|
93
|
|
|
* 'request_contact' => '', |
|
94
|
|
|
* 'request_location' => '', |
|
95
|
|
|
* ]; |
|
96
|
|
|
* </code> |
|
97
|
|
|
* |
|
98
|
|
|
* @link https://core.telegram.org/bots/api#keyboardbutton |
|
99
|
|
|
* |
|
100
|
|
|
* @param string|array $params |
|
101
|
|
|
* |
|
102
|
|
|
* @var string $params ['text'] |
|
103
|
|
|
* @var bool $params ['request_contact'] |
|
104
|
|
|
* @var bool $params ['request_location'] |
|
105
|
|
|
* |
|
106
|
|
|
* @return mixed |
|
107
|
|
|
*/ |
|
108
|
|
|
public static function button($params = []) |
|
109
|
|
|
{ |
|
110
|
|
|
if (is_string($params)) { |
|
111
|
|
|
return $params; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return Button::make($params); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Represents one button of an inline keyboard. |
|
119
|
|
|
* |
|
120
|
|
|
* You must use exactly one of the optional fields. |
|
121
|
|
|
* You can also utilise the fluent API to build the params payload. |
|
122
|
|
|
* |
|
123
|
|
|
* <code> |
|
124
|
|
|
* $params = [ |
|
125
|
|
|
* 'text' => '', |
|
126
|
|
|
* 'url' => '', |
|
127
|
|
|
* 'callback_data' => '', |
|
128
|
|
|
* 'switch_inline_query' => '', |
|
129
|
|
|
* ]; |
|
130
|
|
|
* </code> |
|
131
|
|
|
* |
|
132
|
|
|
* @link https://core.telegram.org/bots/api#inlinekeyboardbutton |
|
133
|
|
|
* |
|
134
|
|
|
* @param string|array $params |
|
135
|
|
|
* |
|
136
|
|
|
* @var string $params ['text'] |
|
137
|
|
|
* @var string $params ['url'] |
|
138
|
|
|
* @var string $params ['callback_data'] |
|
139
|
|
|
* @var string $params ['switch_inline_query'] |
|
140
|
|
|
* |
|
141
|
|
|
* @return string |
|
142
|
|
|
*/ |
|
143
|
|
|
public static function inlineButton($params = []) |
|
144
|
|
|
{ |
|
145
|
|
|
return self::button($params); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Hide the current custom keyboard and display the default letter-keyboard. |
|
150
|
|
|
* |
|
151
|
|
|
* <code> |
|
152
|
|
|
* $params = [ |
|
153
|
|
|
* 'hide_keyboard' => true, |
|
154
|
|
|
* 'selective' => false, |
|
155
|
|
|
* ]; |
|
156
|
|
|
* </code> |
|
157
|
|
|
* |
|
158
|
|
|
* @link https://core.telegram.org/bots/api#replykeyboardhide |
|
159
|
|
|
* |
|
160
|
|
|
* @param array $params |
|
161
|
|
|
* |
|
162
|
|
|
* @var bool $params ['hide_keyboard'] |
|
163
|
|
|
* @var bool $params ['selective'] |
|
164
|
|
|
* |
|
165
|
|
|
* @return string |
|
166
|
|
|
*/ |
|
167
|
|
|
public static function hide(array $params = []) |
|
168
|
|
|
{ |
|
169
|
|
|
return new static(array_merge(['hide_keyboard' => true, 'selective' => false], $params)); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Display a reply interface to the user (act as if the user has selected the bot‘s message and tapped ’Reply'). |
|
174
|
|
|
* |
|
175
|
|
|
* <code> |
|
176
|
|
|
* $params = [ |
|
177
|
|
|
* 'force_reply' => true, |
|
178
|
|
|
* 'selective' => false, |
|
179
|
|
|
* ]; |
|
180
|
|
|
* </code> |
|
181
|
|
|
* |
|
182
|
|
|
* @link https://core.telegram.org/bots/api#forcereply |
|
183
|
|
|
* |
|
184
|
|
|
* @param array $params |
|
185
|
|
|
* |
|
186
|
|
|
* @var bool $params ['force_reply'] |
|
187
|
|
|
* @var bool $params ['selective'] |
|
188
|
|
|
* |
|
189
|
|
|
* @return string |
|
190
|
|
|
*/ |
|
191
|
|
|
public static function forceReply(array $params = []) |
|
192
|
|
|
{ |
|
193
|
|
|
return new static(array_merge(['force_reply' => true, 'selective' => false], $params)); |
|
194
|
|
|
} |
|
195
|
|
|
} |
|
196
|
|
|
|