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