1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Telegram\Bot; |
4
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Container\Container; |
6
|
|
|
use Telegram\Bot\Commands\CommandBus; |
7
|
|
|
use Telegram\Bot\Events\EmitsEvents; |
8
|
|
|
use Telegram\Bot\Events\UpdateWasReceived; |
9
|
|
|
use Telegram\Bot\Exceptions\TelegramSDKException; |
10
|
|
|
use Telegram\Bot\FileUpload\InputFile; |
11
|
|
|
use Telegram\Bot\HttpClients\HttpClientInterface; |
12
|
|
|
use Telegram\Bot\Objects\Chat; |
13
|
|
|
use Telegram\Bot\Objects\ChatMember; |
14
|
|
|
use Telegram\Bot\Objects\File; |
15
|
|
|
use Telegram\Bot\Objects\Message; |
16
|
|
|
use Telegram\Bot\Objects\UnknownObject; |
17
|
|
|
use Telegram\Bot\Objects\Update; |
18
|
|
|
use Telegram\Bot\Objects\User; |
19
|
|
|
use Telegram\Bot\Objects\UserProfilePhotos; |
20
|
|
|
use Telegram\Bot\Keyboard\Keyboard; |
21
|
|
|
use Illuminate\Support\Str; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class Api. |
25
|
|
|
* |
26
|
|
|
* @mixin Commands\CommandBus |
27
|
|
|
*/ |
28
|
|
|
class Api |
29
|
|
|
{ |
30
|
|
|
use EmitsEvents; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string Version number of the Telegram Bot PHP SDK. |
34
|
|
|
*/ |
35
|
|
|
const VERSION = '3.0.0'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string The name of the environment variable that contains the Telegram Bot API Access Token. |
39
|
|
|
*/ |
40
|
|
|
const BOT_TOKEN_ENV_NAME = 'TELEGRAM_BOT_TOKEN'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var TelegramClient The Telegram client service. |
44
|
|
|
*/ |
45
|
|
|
protected $client; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string Telegram Bot API Access Token. |
49
|
|
|
*/ |
50
|
|
|
protected $accessToken = null; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var TelegramResponse|null Stores the last request made to Telegram Bot API. |
54
|
|
|
*/ |
55
|
|
|
protected $lastResponse; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var bool Indicates if the request to Telegram will be asynchronous (non-blocking). |
59
|
|
|
*/ |
60
|
|
|
protected $isAsyncRequest = false; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var CommandBus|null Telegram Command Bus. |
64
|
|
|
*/ |
65
|
|
|
protected $commandBus = null; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var Container IoC Container |
69
|
|
|
*/ |
70
|
|
|
protected static $container = null; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Timeout of the request in seconds. |
74
|
|
|
* |
75
|
|
|
* @var int |
76
|
|
|
*/ |
77
|
|
|
protected $timeOut = 60; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Connection timeout of the request in seconds. |
81
|
|
|
* |
82
|
|
|
* @var int |
83
|
|
|
*/ |
84
|
|
|
protected $connectTimeOut = 10; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Instantiates a new Telegram super-class object. |
88
|
|
|
* |
89
|
|
|
* |
90
|
|
|
* @param string $token The Telegram Bot API Access Token. |
91
|
|
|
* @param bool $async (Optional) Indicates if the request to Telegram |
92
|
|
|
* will be asynchronous (non-blocking). |
93
|
|
|
* @param HttpClientInterface $httpClientHandler (Optional) Custom HTTP Client Handler. |
94
|
|
|
* |
95
|
|
|
* @throws TelegramSDKException |
96
|
66 |
|
*/ |
97
|
|
|
public function __construct($token = null, $async = false, $httpClientHandler = null) |
98
|
66 |
|
{ |
99
|
66 |
|
$this->accessToken = isset($token) ? $token : getenv(static::BOT_TOKEN_ENV_NAME); |
100
|
2 |
|
if (!$this->accessToken) { |
101
|
|
|
throw new TelegramSDKException('Required "token" not supplied in config and could not find fallback environment variable "'.static::BOT_TOKEN_ENV_NAME.'"'); |
102
|
|
|
} |
103
|
66 |
|
|
104
|
66 |
|
if (isset($async)) { |
105
|
66 |
|
$this->setAsyncRequest($async); |
106
|
|
|
} |
107
|
66 |
|
|
108
|
66 |
|
$this->client = new TelegramClient($httpClientHandler); |
109
|
66 |
|
$this->commandBus = new CommandBus($this); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Invoke Bots Manager. |
114
|
|
|
* |
115
|
|
|
* @param $config |
116
|
|
|
* |
117
|
|
|
* @return BotsManager |
118
|
|
|
*/ |
119
|
|
|
public static function manager($config) |
120
|
|
|
{ |
121
|
|
|
return new BotsManager($config); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Returns the TelegramClient service. |
126
|
|
|
* |
127
|
|
|
* @return TelegramClient |
128
|
6 |
|
*/ |
129
|
|
|
public function getClient() |
130
|
6 |
|
{ |
131
|
|
|
return $this->client; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Returns Telegram Bot API Access Token. |
136
|
|
|
* |
137
|
|
|
* @return string |
138
|
42 |
|
*/ |
139
|
|
|
public function getAccessToken() |
140
|
42 |
|
{ |
141
|
|
|
return $this->accessToken; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Returns the last response returned from API request. |
146
|
|
|
* |
147
|
|
|
* @return TelegramResponse |
148
|
2 |
|
*/ |
149
|
|
|
public function getLastResponse() |
150
|
2 |
|
{ |
151
|
|
|
return $this->lastResponse; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Sets the bot access token to use with API requests. |
156
|
|
|
* |
157
|
|
|
* @param string $accessToken The bot access token to save. |
158
|
|
|
* |
159
|
|
|
* @throws \InvalidArgumentException |
160
|
|
|
* |
161
|
|
|
* @return Api |
162
|
8 |
|
*/ |
163
|
|
|
public function setAccessToken($accessToken) |
164
|
8 |
|
{ |
165
|
2 |
|
if (is_string($accessToken)) { |
166
|
|
|
$this->accessToken = $accessToken; |
167
|
2 |
|
|
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
6 |
|
|
171
|
|
|
throw new \InvalidArgumentException('The Telegram bot access token must be of type "string"'); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Make this request asynchronous (non-blocking). |
176
|
|
|
* |
177
|
|
|
* @param bool $isAsyncRequest |
178
|
|
|
* |
179
|
|
|
* @return Api |
180
|
66 |
|
*/ |
181
|
|
|
public function setAsyncRequest($isAsyncRequest) |
182
|
66 |
|
{ |
183
|
|
|
$this->isAsyncRequest = $isAsyncRequest; |
184
|
66 |
|
|
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Check if this is an asynchronous request (non-blocking). |
190
|
|
|
* |
191
|
|
|
* @return bool |
192
|
42 |
|
*/ |
193
|
|
|
public function isAsyncRequest() |
194
|
42 |
|
{ |
195
|
|
|
return $this->isAsyncRequest; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Returns SDK's Command Bus. |
200
|
|
|
* |
201
|
|
|
* @return CommandBus |
202
|
8 |
|
*/ |
203
|
|
|
public function getCommandBus() |
204
|
8 |
|
{ |
205
|
|
|
return $this->commandBus; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* A simple method for testing your bot's auth token. |
210
|
|
|
* Returns basic information about the bot in form of a User object. |
211
|
|
|
* |
212
|
|
|
* @link https://core.telegram.org/bots/api#getme |
213
|
|
|
* |
214
|
|
|
* @throws TelegramSDKException |
215
|
|
|
* |
216
|
|
|
* @return User |
217
|
4 |
|
*/ |
218
|
|
|
public function getMe() |
219
|
4 |
|
{ |
220
|
|
|
$response = $this->post('getMe'); |
221
|
2 |
|
|
222
|
|
|
return new User($response->getDecodedBody()); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Send text messages. |
227
|
|
|
* |
228
|
|
|
* <code> |
229
|
|
|
* $params = [ |
230
|
|
|
* 'chat_id' => '', |
231
|
|
|
* 'text' => '', |
232
|
|
|
* 'parse_mode' => '', |
233
|
|
|
* 'disable_web_page_preview' => '', |
234
|
|
|
* 'disable_notification' => '', |
235
|
|
|
* 'reply_to_message_id' => '', |
236
|
|
|
* 'reply_markup' => '', |
237
|
|
|
* ]; |
238
|
|
|
* </code> |
239
|
|
|
* |
240
|
|
|
* @link https://core.telegram.org/bots/api#sendmessage |
241
|
|
|
* |
242
|
|
|
* @param array $params |
243
|
|
|
* |
244
|
|
|
* @var int|string $params ['chat_id'] |
245
|
|
|
* @var string $params ['text'] |
246
|
|
|
* @var string $params ['parse_mode'] |
247
|
|
|
* @var bool $params ['disable_web_page_preview'] |
248
|
|
|
* @var bool $params ['disable_notification'] |
249
|
|
|
* @var int $params ['reply_to_message_id'] |
250
|
|
|
* @var string $params ['reply_markup'] |
251
|
|
|
* |
252
|
|
|
* @throws TelegramSDKException |
253
|
|
|
* |
254
|
|
|
* @return Message |
255
|
4 |
|
*/ |
256
|
|
|
public function sendMessage(array $params) |
257
|
4 |
|
{ |
258
|
|
|
$response = $this->post('sendMessage', $params); |
259
|
4 |
|
|
260
|
|
|
return new Message($response->getDecodedBody()); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
|
264
|
|
|
public function deleteMessage(array $params) |
265
|
|
|
{ |
266
|
|
|
$response = $this->post('deleteMessage', $params); |
267
|
|
|
|
268
|
|
|
return new Message($response->getDecodedBody()); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Forward messages of any kind. |
274
|
|
|
* |
275
|
|
|
* <code> |
276
|
|
|
* $params = [ |
277
|
|
|
* 'chat_id' => '', |
278
|
|
|
* 'from_chat_id' => '', |
279
|
|
|
* 'disable_notification' => '', |
280
|
|
|
* 'message_id' => '', |
281
|
|
|
* ]; |
282
|
|
|
* </code> |
283
|
|
|
* |
284
|
|
|
* @link https://core.telegram.org/bots/api#forwardmessage |
285
|
|
|
* |
286
|
|
|
* @param array $params |
287
|
2 |
|
* |
288
|
|
|
* @var int|string $params ['chat_id'] |
289
|
2 |
|
* @var int $params ['from_chat_id'] |
290
|
|
|
* @var bool $params ['disable_notification'] |
291
|
2 |
|
* @var int $params ['message_id'] |
292
|
|
|
* |
293
|
|
|
* @throws TelegramSDKException |
294
|
|
|
* |
295
|
|
|
* @return Message |
296
|
|
|
*/ |
297
|
|
|
public function forwardMessage(array $params) |
298
|
|
|
{ |
299
|
|
|
$response = $this->post('forwardMessage', $params); |
300
|
|
|
|
301
|
|
|
return new Message($response->getDecodedBody()); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Send Photos. |
306
|
|
|
* |
307
|
|
|
* <code> |
308
|
|
|
* $params = [ |
309
|
|
|
* 'chat_id' => '', |
310
|
|
|
* 'photo' => '', |
311
|
|
|
* 'caption' => '', |
312
|
|
|
* 'disable_notification' => '', |
313
|
|
|
* 'reply_to_message_id' => '', |
314
|
|
|
* 'reply_markup' => '', |
315
|
|
|
* ]; |
316
|
|
|
* </code> |
317
|
|
|
* |
318
|
|
|
* @link https://core.telegram.org/bots/api#sendphoto |
319
|
|
|
* |
320
|
|
|
* @param array $params |
321
|
|
|
* |
322
|
|
|
* @var int|string $params ['chat_id'] |
323
|
4 |
|
* @var string $params ['photo'] |
324
|
|
|
* @var string $params ['caption'] |
325
|
4 |
|
* @var bool $params ['disable_notification'] |
326
|
|
|
* @var int $params ['reply_to_message_id'] |
327
|
4 |
|
* @var string $params ['reply_markup'] |
328
|
|
|
* |
329
|
|
|
* @throws TelegramSDKException |
330
|
|
|
* |
331
|
|
|
* @return Message |
332
|
|
|
*/ |
333
|
|
|
public function sendPhoto(array $params) |
334
|
|
|
{ |
335
|
|
|
$response = $this->uploadFile('sendPhoto', $params); |
336
|
|
|
|
337
|
|
|
return new Message($response->getDecodedBody()); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Send regular audio files. |
342
|
|
|
* |
343
|
|
|
* <code> |
344
|
|
|
* $params = [ |
345
|
|
|
* 'chat_id' => '', |
346
|
|
|
* 'audio' => '', |
347
|
|
|
* 'duration' => '', |
348
|
|
|
* 'performer' => '', |
349
|
|
|
* 'title' => '', |
350
|
|
|
* 'disable_notification' => '', |
351
|
|
|
* 'reply_to_message_id' => '', |
352
|
|
|
* 'reply_markup' => '', |
353
|
|
|
* ]; |
354
|
|
|
* </code> |
355
|
|
|
* |
356
|
|
|
* @link https://core.telegram.org/bots/api#sendaudio |
357
|
|
|
* |
358
|
|
|
* @param array $params |
359
|
|
|
* |
360
|
|
|
* @var int|string $params ['chat_id'] |
361
|
|
|
* @var string $params ['audio'] |
362
|
|
|
* @var int $params ['duration'] |
363
|
2 |
|
* @var string $params ['performer'] |
364
|
|
|
* @var string $params ['title'] |
365
|
2 |
|
* @var bool $params ['disable_notification'] |
366
|
|
|
* @var int $params ['reply_to_message_id'] |
367
|
2 |
|
* @var string $params ['reply_markup'] |
368
|
|
|
* |
369
|
|
|
* @throws TelegramSDKException |
370
|
|
|
* |
371
|
|
|
* @return Message |
372
|
|
|
*/ |
373
|
|
|
public function sendAudio(array $params) |
374
|
|
|
{ |
375
|
|
|
$response = $this->uploadFile('sendAudio', $params); |
376
|
|
|
|
377
|
|
|
return new Message($response->getDecodedBody()); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Send general files. |
382
|
|
|
* |
383
|
|
|
* <code> |
384
|
|
|
* $params = [ |
385
|
|
|
* 'chat_id' => '', |
386
|
|
|
* 'document' => '', |
387
|
|
|
* 'caption' => '', |
388
|
|
|
* 'disable_notification' => '', |
389
|
|
|
* 'reply_to_message_id' => '', |
390
|
|
|
* 'reply_markup' => '', |
391
|
|
|
* ]; |
392
|
|
|
* </code> |
393
|
|
|
* |
394
|
|
|
* @link https://core.telegram.org/bots/api#senddocument |
395
|
|
|
* |
396
|
|
|
* @param array $params |
397
|
|
|
* |
398
|
|
|
* @var int|string $params ['chat_id'] |
399
|
2 |
|
* @var string $params ['document'] |
400
|
|
|
* @var string $params ['caption'] |
401
|
2 |
|
* @var bool $params ['disable_notification'] |
402
|
|
|
* @var int $params ['reply_to_message_id'] |
403
|
2 |
|
* @var string $params ['reply_markup'] |
404
|
|
|
* |
405
|
|
|
* @throws TelegramSDKException |
406
|
|
|
* |
407
|
|
|
* @return Message |
408
|
|
|
*/ |
409
|
|
|
public function sendDocument(array $params) |
410
|
|
|
{ |
411
|
|
|
$response = $this->uploadFile('sendDocument', $params); |
412
|
|
|
|
413
|
|
|
return new Message($response->getDecodedBody()); |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* Send .webp stickers. |
418
|
|
|
* |
419
|
|
|
* <code> |
420
|
|
|
* $params = [ |
421
|
|
|
* 'chat_id' => '', |
422
|
|
|
* 'sticker' => '', |
423
|
|
|
* 'disable_notification' => '', |
424
|
|
|
* 'reply_to_message_id' => '', |
425
|
|
|
* 'reply_markup' => '', |
426
|
|
|
* ]; |
427
|
|
|
* </code> |
428
|
|
|
* |
429
|
|
|
* @link https://core.telegram.org/bots/api#sendsticker |
430
|
|
|
* |
431
|
|
|
* @param array $params |
432
|
|
|
* |
433
|
2 |
|
* @var int|string $params ['chat_id'] |
434
|
|
|
* @var string $params ['sticker'] |
435
|
2 |
|
* @var bool $params ['disable_notification'] |
436
|
|
|
* @var int $params ['reply_to_message_id'] |
437
|
|
|
* @var string $params ['reply_markup'] |
438
|
|
|
* |
439
|
2 |
|
* @throws TelegramSDKException |
440
|
|
|
* |
441
|
2 |
|
* @return Message |
442
|
|
|
*/ |
443
|
|
|
public function sendSticker(array $params) |
444
|
|
|
{ |
445
|
|
|
if (is_file($params['sticker']) && (pathinfo($params['sticker'], PATHINFO_EXTENSION) !== 'webp')) { |
446
|
|
|
throw new TelegramSDKException('Invalid Sticker Provided. Supported Format: Webp'); |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
$response = $this->uploadFile('sendSticker', $params); |
450
|
|
|
|
451
|
|
|
return new Message($response->getDecodedBody()); |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
/** |
455
|
|
|
* Send Video File, Telegram clients support mp4 videos (other formats may be sent as Document). |
456
|
|
|
* |
457
|
|
|
* <code> |
458
|
|
|
* $params = [ |
459
|
|
|
* 'chat_id' => '', |
460
|
|
|
* 'video' => '', |
461
|
|
|
* 'duration' => '', |
462
|
|
|
* 'width' => '', |
463
|
|
|
* 'height' => '', |
464
|
|
|
* 'caption' => '', |
465
|
|
|
* 'disable_notification' => '', |
466
|
|
|
* 'reply_to_message_id' => '', |
467
|
|
|
* 'reply_markup' => '', |
468
|
|
|
* ]; |
469
|
|
|
* </code> |
470
|
|
|
* |
471
|
|
|
* @see sendDocument |
472
|
|
|
* @link https://core.telegram.org/bots/api#sendvideo |
473
|
|
|
* |
474
|
|
|
* @param array $params |
475
|
|
|
* |
476
|
|
|
* @var int|string $params ['chat_id'] |
477
|
|
|
* @var string $params ['video'] |
478
|
|
|
* @var int $params ['duration'] |
479
|
|
|
* @var int $params ['width'] |
480
|
2 |
|
* @var int $params ['height'] |
481
|
|
|
* @var string $params ['caption'] |
482
|
2 |
|
* @var bool $params ['disable_notification'] |
483
|
|
|
* @var int $params ['reply_to_message_id'] |
484
|
2 |
|
* @var string $params ['reply_markup'] |
485
|
|
|
* |
486
|
|
|
* @throws TelegramSDKException |
487
|
|
|
* |
488
|
|
|
* @return Message |
489
|
|
|
*/ |
490
|
|
|
public function sendVideo(array $params) |
491
|
|
|
{ |
492
|
|
|
$response = $this->uploadFile('sendVideo', $params); |
493
|
|
|
|
494
|
|
|
return new Message($response->getDecodedBody()); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* Send voice audio files. |
499
|
|
|
* |
500
|
|
|
* <code> |
501
|
|
|
* $params = [ |
502
|
|
|
* 'chat_id' => '', |
503
|
|
|
* 'voice' => '', |
504
|
|
|
* 'duration' => '', |
505
|
|
|
* 'disable_notification' => '', |
506
|
|
|
* 'reply_to_message_id' => '', |
507
|
|
|
* 'reply_markup' => '', |
508
|
|
|
* ]; |
509
|
|
|
* </code> |
510
|
|
|
* |
511
|
|
|
* @link https://core.telegram.org/bots/api#sendaudio |
512
|
|
|
* |
513
|
|
|
* @param array $params |
514
|
|
|
* |
515
|
|
|
* @var int|string $params ['chat_id'] |
516
|
2 |
|
* @var string $params ['voice'] |
517
|
|
|
* @var int $params ['duration'] |
518
|
2 |
|
* @var bool $params ['disable_notification'] |
519
|
|
|
* @var int $params ['reply_to_message_id'] |
520
|
2 |
|
* @var string $params ['reply_markup'] |
521
|
|
|
* |
522
|
|
|
* @throws TelegramSDKException |
523
|
|
|
* |
524
|
|
|
* @return Message |
525
|
|
|
*/ |
526
|
|
|
public function sendVoice(array $params) |
527
|
|
|
{ |
528
|
|
|
$response = $this->uploadFile('sendVoice', $params); |
529
|
|
|
|
530
|
|
|
return new Message($response->getDecodedBody()); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
/** |
534
|
|
|
* Send point on the map. |
535
|
|
|
* |
536
|
|
|
* <code> |
537
|
|
|
* $params = [ |
538
|
|
|
* 'chat_id' => '', |
539
|
|
|
* 'latitude' => '', |
540
|
|
|
* 'longitude' => '', |
541
|
|
|
* 'disable_notification' => '', |
542
|
|
|
* 'reply_to_message_id' => '', |
543
|
|
|
* 'reply_markup' => '', |
544
|
|
|
* ]; |
545
|
|
|
* </code> |
546
|
|
|
* |
547
|
|
|
* @link https://core.telegram.org/bots/api#sendlocation |
548
|
|
|
* |
549
|
|
|
* @param array $params |
550
|
|
|
* |
551
|
|
|
* @var int|string $params ['chat_id'] |
552
|
2 |
|
* @var float $params ['latitude'] |
553
|
|
|
* @var float $params ['longitude'] |
554
|
2 |
|
* @var bool $params ['disable_notification'] |
555
|
|
|
* @var int $params ['reply_to_message_id'] |
556
|
2 |
|
* @var string $params ['reply_markup'] |
557
|
|
|
* |
558
|
|
|
* @throws TelegramSDKException |
559
|
|
|
* |
560
|
|
|
* @return Message |
561
|
|
|
*/ |
562
|
|
|
public function sendLocation(array $params) |
563
|
|
|
{ |
564
|
|
|
$response = $this->post('sendLocation', $params); |
565
|
|
|
|
566
|
|
|
return new Message($response->getDecodedBody()); |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
/** |
570
|
|
|
* Send information about a venue. |
571
|
|
|
* |
572
|
|
|
* <code> |
573
|
|
|
* $params = [ |
574
|
|
|
* 'chat_id' => '', |
575
|
|
|
* 'latitude' => '', |
576
|
|
|
* 'longitude' => '', |
577
|
|
|
* 'title' => '', |
578
|
|
|
* 'address' => '', |
579
|
|
|
* 'foursquare_id' => '', |
580
|
|
|
* 'disable_notification' => '', |
581
|
|
|
* 'reply_to_message_id' => '', |
582
|
|
|
* 'reply_markup' => '', |
583
|
|
|
* ]; |
584
|
|
|
* </code> |
585
|
|
|
* |
586
|
|
|
* @link https://core.telegram.org/bots/api#sendvenue |
587
|
|
|
* |
588
|
|
|
* @param array $params |
589
|
|
|
* |
590
|
|
|
* @var int|string $params ['chat_id'] |
591
|
|
|
* @var float $params ['latitude'] |
592
|
|
|
* @var float $params ['longitude'] |
593
|
|
|
* @var string $params ['title'] |
594
|
|
|
* @var string $params ['address'] |
595
|
|
|
* @var string $params ['foursquare_id'] |
596
|
|
|
* @var bool $params ['disable_notification'] |
597
|
|
|
* @var int $params ['reply_to_message_id'] |
598
|
|
|
* @var string $params ['reply_markup'] |
599
|
|
|
* |
600
|
|
|
* @throws TelegramSDKException |
601
|
|
|
* |
602
|
|
|
* @return Message |
603
|
|
|
*/ |
604
|
|
|
public function sendVenue(array $params) |
605
|
|
|
{ |
606
|
|
|
$response = $this->post('sendVenue', $params); |
607
|
|
|
|
608
|
|
|
return new Message($response->getDecodedBody()); |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
/** |
612
|
|
|
* Send phone contacts. |
613
|
|
|
* |
614
|
|
|
* <code> |
615
|
|
|
* $params = [ |
616
|
|
|
* 'chat_id' => '', |
617
|
|
|
* 'phone_number' => '', |
618
|
|
|
* 'first_name' => '', |
619
|
|
|
* 'last_name' => '', |
620
|
|
|
* 'disable_notification' => '', |
621
|
|
|
* 'reply_to_message_id' => '', |
622
|
|
|
* 'reply_markup' => '', |
623
|
|
|
* ]; |
624
|
|
|
* </code> |
625
|
|
|
* |
626
|
|
|
* @link https://core.telegram.org/bots/api#sendcontact |
627
|
|
|
* |
628
|
|
|
* @param array $params |
629
|
|
|
* |
630
|
|
|
* @var int|string $params ['chat_id'] |
631
|
|
|
* @var string $params ['phone_number'] |
632
|
|
|
* @var string $params ['first_name'] |
633
|
|
|
* @var string $params ['last_name'] |
634
|
|
|
* @var bool $params ['disable_notification'] |
635
|
|
|
* @var int $params ['reply_to_message_id'] |
636
|
|
|
* @var string $params ['reply_markup'] |
637
|
|
|
* |
638
|
|
|
* @throws TelegramSDKException |
639
|
|
|
* |
640
|
|
|
* @return Message |
641
|
|
|
*/ |
642
|
|
|
public function sendContact(array $params) |
643
|
|
|
{ |
644
|
|
|
$response = $this->post('sendContact', $params); |
645
|
|
|
|
646
|
|
|
return new Message($response->getDecodedBody()); |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
/** |
650
|
|
|
* Broadcast a Chat Action. |
651
|
|
|
* |
652
|
|
|
* <code> |
653
|
|
|
* $params = [ |
654
|
|
|
* 'chat_id' => '', |
655
|
|
|
* 'action' => '', |
656
|
|
|
* ]; |
657
|
|
|
* </code> |
658
|
|
|
* |
659
|
|
|
* @link https://core.telegram.org/bots/api#sendchataction |
660
|
4 |
|
* |
661
|
|
|
* @param array $params |
662
|
|
|
* |
663
|
4 |
|
* @var int|string $params ['chat_id'] |
664
|
4 |
|
* @var string $params ['action'] |
665
|
4 |
|
* |
666
|
4 |
|
* @throws TelegramSDKException |
667
|
4 |
|
* |
668
|
4 |
|
* @return bool |
669
|
4 |
|
*/ |
670
|
4 |
|
public function sendChatAction(array $params) |
671
|
4 |
|
{ |
672
|
|
|
$validActions = [ |
673
|
4 |
|
'typing', |
674
|
2 |
|
'upload_photo', |
675
|
|
|
'record_video', |
676
|
2 |
|
'upload_video', |
677
|
|
|
'record_audio', |
678
|
|
|
'upload_audio', |
679
|
2 |
|
'upload_document', |
680
|
|
|
'find_location', |
681
|
|
|
]; |
682
|
|
|
|
683
|
|
|
if (isset($params['action']) && in_array($params['action'], $validActions)) { |
684
|
|
|
$this->post('sendChatAction', $params); |
685
|
|
|
|
686
|
|
|
return true; |
687
|
|
|
} |
688
|
|
|
|
689
|
|
|
throw new TelegramSDKException('Invalid Action! Accepted value: '.implode(', ', $validActions)); |
690
|
|
|
} |
691
|
|
|
|
692
|
|
|
/** |
693
|
|
|
* Returns a list of profile pictures for a user. |
694
|
|
|
* |
695
|
|
|
* <code> |
696
|
|
|
* $params = [ |
697
|
|
|
* 'user_id' => '', |
698
|
|
|
* 'offset' => '', |
699
|
|
|
* 'limit' => '', |
700
|
|
|
* ]; |
701
|
|
|
* </code> |
702
|
|
|
* |
703
|
|
|
* @link https://core.telegram.org/bots/api#getuserprofilephotos |
704
|
|
|
* |
705
|
|
|
* @param array $params |
706
|
|
|
* |
707
|
|
|
* @var int $params ['user_id'] |
708
|
|
|
* @var int $params ['offset'] |
709
|
|
|
* @var int $params ['limit'] |
710
|
|
|
* |
711
|
|
|
* @throws TelegramSDKException |
712
|
|
|
* |
713
|
|
|
* @return UserProfilePhotos |
714
|
|
|
*/ |
715
|
|
|
public function getUserProfilePhotos(array $params) |
716
|
|
|
{ |
717
|
|
|
$response = $this->post('getUserProfilePhotos', $params); |
718
|
|
|
|
719
|
|
|
return new UserProfilePhotos($response->getDecodedBody()); |
720
|
|
|
} |
721
|
|
|
|
722
|
|
|
/** |
723
|
|
|
* Returns basic info about a file and prepare it for downloading. |
724
|
|
|
* |
725
|
|
|
* <code> |
726
|
|
|
* $params = [ |
727
|
|
|
* 'file_id' => '', |
728
|
|
|
* ]; |
729
|
|
|
* </code> |
730
|
|
|
* |
731
|
|
|
* The file can then be downloaded via the link |
732
|
|
|
* https://api.telegram.org/file/bot<token>/<file_path>, |
733
|
|
|
* where <file_path> is taken from the response. |
734
|
|
|
* |
735
|
2 |
|
* @link https://core.telegram.org/bots/api#getFile |
736
|
|
|
* |
737
|
2 |
|
* @param array $params |
738
|
|
|
* |
739
|
2 |
|
* @var string $params ['file_id'] |
740
|
|
|
* |
741
|
|
|
* @throws TelegramSDKException |
742
|
|
|
* |
743
|
|
|
* @return File |
744
|
|
|
*/ |
745
|
|
|
public function getFile(array $params) |
746
|
|
|
{ |
747
|
|
|
$response = $this->post('getFile', $params); |
748
|
|
|
|
749
|
|
|
return new File($response->getDecodedBody()); |
750
|
|
|
} |
751
|
|
|
|
752
|
|
|
/** |
753
|
|
|
* Kick a user from a group or a supergroup. |
754
|
|
|
* |
755
|
|
|
* In the case of supergroups, the user will not be able to return to the group on their own using |
756
|
|
|
* invite links etc., unless unbanned first. |
757
|
|
|
* |
758
|
|
|
* The bot must be an administrator in the group for this to work. |
759
|
|
|
* |
760
|
|
|
* <code> |
761
|
|
|
* $params = [ |
762
|
|
|
* 'chat_id' => '', |
763
|
|
|
* 'user_id' => '', |
764
|
|
|
* ]; |
765
|
|
|
* </code> |
766
|
|
|
* |
767
|
|
|
* @link https://core.telegram.org/bots/api#kickchatmember |
768
|
|
|
* |
769
|
|
|
* @param array $params |
770
|
|
|
* |
771
|
|
|
* @var int|string $params ['chat_id'] |
772
|
|
|
* @var int $params ['user_id'] |
773
|
|
|
* |
774
|
|
|
* @throws TelegramSDKException |
775
|
|
|
* |
776
|
|
|
* @return bool |
777
|
|
|
*/ |
778
|
|
|
public function kickChatMember(array $params) |
779
|
|
|
{ |
780
|
|
|
$this->post('kickChatMember', $params); |
781
|
|
|
|
782
|
|
|
return true; |
783
|
|
|
} |
784
|
|
|
|
785
|
|
|
/** |
786
|
|
|
* Unban a previously kicked user in a supergroup. |
787
|
|
|
* |
788
|
|
|
* The user will not return to the group automatically, but will be able to join via link, etc. |
789
|
|
|
* |
790
|
|
|
* The bot must be an administrator in the group for this to work. |
791
|
|
|
* |
792
|
|
|
* <code> |
793
|
|
|
* $params = [ |
794
|
|
|
* 'chat_id' => '', |
795
|
|
|
* 'user_id' => '', |
796
|
|
|
* ]; |
797
|
|
|
* </code> |
798
|
|
|
* |
799
|
|
|
* @link https://core.telegram.org/bots/api#unbanchatmember |
800
|
|
|
* |
801
|
|
|
* @param array $params |
802
|
|
|
* |
803
|
|
|
* @var int|string $params ['chat_id'] |
804
|
|
|
* @var int $params ['user_id'] |
805
|
|
|
* |
806
|
|
|
* @throws TelegramSDKException |
807
|
|
|
* |
808
|
|
|
* @return bool |
809
|
|
|
*/ |
810
|
|
|
public function unbanChatMember(array $params) |
811
|
|
|
{ |
812
|
|
|
$this->post('unbanChatMember', $params); |
813
|
|
|
|
814
|
|
|
return true; |
815
|
|
|
} |
816
|
|
|
|
817
|
|
|
/** |
818
|
|
|
* Get up to date information about the chat (current name of the user for one-on-one conversations, |
819
|
|
|
* current username of a user, group or channel, |
820
|
|
|
* |
821
|
|
|
* <code> |
822
|
|
|
* $params = [ |
823
|
|
|
* 'chat_id' => '', |
824
|
|
|
* ]; |
825
|
|
|
* </code> |
826
|
|
|
* |
827
|
|
|
* @link https://core.telegram.org/bots/api#getchat |
828
|
|
|
* |
829
|
|
|
* @param array $params |
830
|
|
|
* |
831
|
|
|
* @var string|int $params ['chat_id'] Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) |
832
|
|
|
* |
833
|
|
|
* @throws TelegramSDKException |
834
|
|
|
* |
835
|
|
|
* @return Chat |
836
|
|
|
*/ |
837
|
|
|
public function getChat(array $params) |
838
|
|
|
{ |
839
|
|
|
$response = $this->post('getChat', $params); |
840
|
|
|
|
841
|
|
|
return new Chat($response->getDecodedBody()); |
842
|
|
|
} |
843
|
|
|
|
844
|
|
|
/** |
845
|
|
|
* Get a list of administrators in a chat. |
846
|
|
|
* |
847
|
|
|
* <code> |
848
|
|
|
* $params = [ |
849
|
|
|
* 'chat_id' => '', |
850
|
|
|
* ]; |
851
|
|
|
* </code> |
852
|
|
|
* |
853
|
|
|
* @link https://core.telegram.org/bots/api#getchatadministrators |
854
|
|
|
* |
855
|
|
|
* @param array $params |
856
|
|
|
* |
857
|
|
|
* @var string|int $params ['chat_id'] Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername); |
858
|
|
|
* |
859
|
|
|
* @throws TelegramSDKException |
860
|
|
|
* |
861
|
|
|
* @return ChatMember[] |
862
|
|
|
*/ |
863
|
|
|
public function getChatAdministrators(array $params) |
864
|
|
|
{ |
865
|
|
|
$response = $this->post('getChatAdministrators', $params); |
866
|
|
|
|
867
|
|
|
return collect($response->getResult()) |
868
|
|
|
->map(function ($admin) { |
869
|
|
|
return new ChatMember($admin); |
870
|
|
|
}) |
871
|
|
|
->all(); |
872
|
|
|
} |
873
|
|
|
|
874
|
|
|
/** |
875
|
|
|
* Get the number of members in a chat |
876
|
|
|
* |
877
|
|
|
* <code> |
878
|
|
|
* $params = [ |
879
|
|
|
* 'chat_id' => '', |
880
|
|
|
* ]; |
881
|
|
|
* </code> |
882
|
|
|
* |
883
|
|
|
* @link https://core.telegram.org/bots/api#getchatmemberscount |
884
|
|
|
* |
885
|
|
|
* @param array $params |
886
|
|
|
* |
887
|
|
|
* @var string|int $params ['chat_id'] Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) |
888
|
|
|
* |
889
|
|
|
* @throws TelegramSDKException |
890
|
|
|
* |
891
|
|
|
* @return int |
892
|
|
|
*/ |
893
|
|
|
public function getChatMembersCount(array $params) |
894
|
|
|
{ |
895
|
|
|
$response = $this->post('getChatMembersCount', $params); |
896
|
|
|
|
897
|
|
|
return $response->getResult(); |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
/** |
901
|
|
|
* Get information about a member of a chat. |
902
|
|
|
* |
903
|
|
|
* <code> |
904
|
|
|
* $params = [ |
905
|
|
|
* 'chat_id' => '', |
906
|
|
|
* 'user_id' => '', |
907
|
|
|
* ]; |
908
|
|
|
* </code> |
909
|
|
|
* |
910
|
|
|
* @link https://core.telegram.org/bots/api#getchatmember |
911
|
|
|
* |
912
|
|
|
* @param array $params |
913
|
|
|
* |
914
|
|
|
* @var string|int $params ['chat_id'] Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) |
915
|
|
|
* @var int $params ['user_id'] Unique identifier of the target user. |
916
|
|
|
* |
917
|
|
|
* @throws TelegramSDKException |
918
|
|
|
* |
919
|
|
|
* @return ChatMember |
920
|
|
|
*/ |
921
|
|
|
public function getChatMember(array $params) |
922
|
|
|
{ |
923
|
|
|
$response = $this->post('getChatMember', $params); |
924
|
|
|
|
925
|
|
|
return new ChatMember($response->getDecodedBody()); |
926
|
|
|
} |
927
|
|
|
|
928
|
|
|
/** |
929
|
|
|
* Send answers to callback queries sent from inline keyboards. |
930
|
|
|
* |
931
|
|
|
* he answer will be displayed to the user as a notification at the top of the chat screen or as an alert. |
932
|
|
|
* |
933
|
|
|
* <code> |
934
|
|
|
* $params = [ |
935
|
|
|
* 'callback_query_id' => '', |
936
|
|
|
* 'text' => '', |
937
|
|
|
* 'show_alert' => '', |
938
|
|
|
* ]; |
939
|
|
|
* </code> |
940
|
|
|
* |
941
|
|
|
* @link https://core.telegram.org/bots/api#answerCallbackQuery |
942
|
|
|
* |
943
|
|
|
* @param array $params |
944
|
|
|
* |
945
|
|
|
* @var string $params ['callback_query_id'] |
946
|
|
|
* @var string $params ['text'] |
947
|
|
|
* @var bool $params ['show_alert'] |
948
|
|
|
* |
949
|
|
|
* @throws TelegramSDKException |
950
|
|
|
* |
951
|
|
|
* @return bool |
952
|
|
|
*/ |
953
|
|
|
public function answerCallbackQuery(array $params) |
954
|
|
|
{ |
955
|
|
|
$this->post('answerCallbackQuery', $params); |
956
|
|
|
|
957
|
|
|
return true; |
958
|
|
|
} |
959
|
|
|
|
960
|
|
|
|
961
|
|
|
/** |
962
|
|
|
* Edit text messages sent by the bot or via the bot (for inline bots). |
963
|
|
|
* |
964
|
|
|
* <code> |
965
|
|
|
* $params = [ |
966
|
|
|
* 'chat_id' => '', |
967
|
|
|
* 'message_id' => '', |
968
|
|
|
* 'inline_message_id' => '', |
969
|
|
|
* 'text' => '', |
970
|
|
|
* 'parse_mode' => '', |
971
|
|
|
* 'disable_web_page_preview' => '', |
972
|
|
|
* 'reply_markup' => '', |
973
|
|
|
* ]; |
974
|
|
|
* </code> |
975
|
|
|
* |
976
|
|
|
* @link https://core.telegram.org/bots/api#editMessageText |
977
|
|
|
* |
978
|
|
|
* @param array $params |
979
|
|
|
* |
980
|
|
|
* @var int|string $params ['chat_id'] |
981
|
|
|
* @var int $params ['message_id'] |
982
|
|
|
* @var string $params ['inline_message_id'] |
983
|
|
|
* @var string $params ['text'] |
984
|
|
|
* @var string $params ['parse_mode'] |
985
|
|
|
* @var bool $params ['disable_web_page_preview'] |
986
|
|
|
* @var string $params ['reply_markup'] |
987
|
|
|
* |
988
|
|
|
* @throws TelegramSDKException |
989
|
|
|
* |
990
|
|
|
* @return Message|bool |
991
|
|
|
*/ |
992
|
|
|
public function editMessageText(array $params) |
993
|
|
|
{ |
994
|
|
|
$response = $this->post('editMessageText', $params); |
995
|
|
|
|
996
|
|
|
return new Message($response->getDecodedBody()); |
997
|
|
|
} |
998
|
|
|
|
999
|
|
|
/** |
1000
|
|
|
* Edit captions of messages sent by the bot or via the bot (for inline bots). |
1001
|
|
|
* |
1002
|
|
|
* <code> |
1003
|
|
|
* $params = [ |
1004
|
|
|
* 'chat_id' => '', |
1005
|
|
|
* 'message_id' => '', |
1006
|
|
|
* 'inline_message_id' => '', |
1007
|
|
|
* 'caption' => '', |
1008
|
|
|
* 'reply_markup' => '', |
1009
|
|
|
* ]; |
1010
|
|
|
* </code> |
1011
|
|
|
* |
1012
|
|
|
* @link https://core.telegram.org/bots/api#editMessageCaption |
1013
|
|
|
* |
1014
|
|
|
* @param array $params |
1015
|
|
|
* |
1016
|
|
|
* @var int|string $params ['chat_id'] |
1017
|
|
|
* @var int $params ['message_id'] |
1018
|
|
|
* @var string $params ['inline_message_id'] |
1019
|
|
|
* @var string $params ['caption'] |
1020
|
|
|
* @var string $params ['reply_markup'] |
1021
|
|
|
* |
1022
|
|
|
* @throws TelegramSDKException |
1023
|
|
|
* |
1024
|
|
|
* @return Message|bool |
1025
|
|
|
*/ |
1026
|
|
|
public function editMessageCaption(array $params) |
1027
|
|
|
{ |
1028
|
|
|
$response = $this->post('editMessageCaption', $params); |
1029
|
|
|
|
1030
|
|
|
return new Message($response->getDecodedBody()); |
1031
|
|
|
} |
1032
|
|
|
|
1033
|
|
|
/** |
1034
|
|
|
* Edit only the reply markup of messages sent by the bot or via the bot (for inline bots). |
1035
|
|
|
* |
1036
|
|
|
* <code> |
1037
|
|
|
* $params = [ |
1038
|
|
|
* 'chat_id' => '', |
1039
|
|
|
* 'message_id' => '', |
1040
|
|
|
* 'inline_message_id' => '', |
1041
|
|
|
* 'reply_markup' => '', |
1042
|
|
|
* ]; |
1043
|
|
|
* </code> |
1044
|
|
|
* |
1045
|
|
|
* @link https://core.telegram.org/bots/api#editMessageReplyMarkup |
1046
|
|
|
* |
1047
|
|
|
* @param array $params |
1048
|
|
|
* |
1049
|
|
|
* @var int|string $params ['chat_id'] |
1050
|
|
|
* @var int $params ['message_id'] |
1051
|
|
|
* @var string $params ['inline_message_id'] |
1052
|
|
|
* @var string $params ['reply_markup'] |
1053
|
|
|
* |
1054
|
|
|
* @throws TelegramSDKException |
1055
|
|
|
* |
1056
|
|
|
* @return Message|bool |
1057
|
|
|
*/ |
1058
|
|
|
public function editMessageReplyMarkup(array $params) |
1059
|
|
|
{ |
1060
|
|
|
$response = $this->post('editMessageReplyMarkup', $params); |
1061
|
|
|
|
1062
|
|
|
return new Message($response->getDecodedBody()); |
1063
|
|
|
} |
1064
|
|
|
|
1065
|
|
|
/** |
1066
|
|
|
* Use this method to send answers to an inline query. |
1067
|
|
|
* |
1068
|
|
|
* <code> |
1069
|
|
|
* $params = [ |
1070
|
|
|
* 'inline_query_id' => '', |
1071
|
|
|
* 'results' => [], |
1072
|
|
|
* 'cache_time' => 0, |
1073
|
|
|
* 'is_personal' => false, |
1074
|
|
|
* 'next_offset' => '', |
1075
|
|
|
* 'switch_pm_text' => '', |
1076
|
|
|
* 'switch_pm_parameter' => '', |
1077
|
|
|
* ]; |
1078
|
|
|
* </code> |
1079
|
|
|
* |
1080
|
|
|
* @link https://core.telegram.org/bots/api#answerinlinequery |
1081
|
|
|
* |
1082
|
|
|
* @param array $params |
1083
|
|
|
* |
1084
|
|
|
* @var string $params ['inline_query_id'] |
1085
|
|
|
* @var array $params ['results'] |
1086
|
|
|
* @var int|null $params ['cache_time'] |
1087
|
|
|
* @var bool|null $params ['is_personal'] |
1088
|
|
|
* @var string|null $params ['next_offset'] |
1089
|
|
|
* @var string|null $params ['switch_pm_text'] |
1090
|
|
|
* @var string|null $params ['switch_pm_parameter'] |
1091
|
|
|
* |
1092
|
|
|
* @throws TelegramSDKException |
1093
|
|
|
* |
1094
|
|
|
* @return bool |
1095
|
|
|
*/ |
1096
|
|
|
public function answerInlineQuery(array $params = []) |
1097
|
|
|
{ |
1098
|
|
|
if (is_array($params['results'])) { |
1099
|
|
|
$params['results'] = json_encode($params['results']); |
1100
|
|
|
} |
1101
|
|
|
|
1102
|
|
|
$this->post('answerInlineQuery', $params); |
1103
|
|
|
|
1104
|
|
|
return true; |
1105
|
|
|
} |
1106
|
|
|
|
1107
|
|
|
/** |
1108
|
|
|
* Set a Webhook to receive incoming updates via an outgoing webhook. |
1109
|
|
|
* |
1110
|
|
|
* <code> |
1111
|
|
|
* $params = [ |
1112
|
|
|
* 'url' => '', |
1113
|
|
|
* 'certificate' => '', |
1114
|
|
|
* ]; |
1115
|
|
|
* </code> |
1116
|
|
|
* |
1117
|
|
|
* @link https://core.telegram.org/bots/api#setwebhook |
1118
|
|
|
* |
1119
|
6 |
|
* @param array $params |
1120
|
|
|
* |
1121
|
6 |
|
* @var string $params ['url'] HTTPS url to send updates to. |
1122
|
2 |
|
* @var string $params ['certificate'] Upload your public key certificate so that the root certificate in |
1123
|
|
|
* use can be checked. |
1124
|
|
|
* |
1125
|
4 |
|
* @throws TelegramSDKException |
1126
|
2 |
|
* |
1127
|
|
|
* @return TelegramResponse |
1128
|
|
|
*/ |
1129
|
2 |
|
public function setWebhook(array $params) |
1130
|
|
|
{ |
1131
|
|
|
if (filter_var($params['url'], FILTER_VALIDATE_URL) === false) { |
1132
|
|
|
throw new TelegramSDKException('Invalid URL Provided'); |
1133
|
|
|
} |
1134
|
|
|
|
1135
|
|
|
if (parse_url($params['url'], PHP_URL_SCHEME) !== 'https') { |
1136
|
|
|
throw new TelegramSDKException('Invalid URL, should be a HTTPS url.'); |
1137
|
|
|
} |
1138
|
|
|
|
1139
|
|
|
return $this->uploadFile('setWebhook', $params); |
1140
|
|
|
} |
1141
|
|
|
|
1142
|
|
|
/** |
1143
|
|
|
* Returns a webhook update sent by Telegram. |
1144
|
|
|
* Works only if you set a webhook. |
1145
|
|
|
* |
1146
|
|
|
* @see setWebhook |
1147
|
|
|
* |
1148
|
|
|
* @return Update |
1149
|
|
|
*/ |
1150
|
|
|
public function getWebhookUpdate($shouldEmitEvent = true) |
1151
|
|
|
{ |
1152
|
|
|
$body = json_decode(file_get_contents('php://input'), true); |
1153
|
|
|
|
1154
|
|
|
$update = new Update($body); |
1155
|
|
|
|
1156
|
|
|
if ($shouldEmitEvent) { |
1157
|
|
|
$this->emitEvent(new UpdateWasReceived($update, $this)); |
1158
|
|
|
} |
1159
|
|
|
|
1160
|
|
|
return $update; |
1161
|
|
|
} |
1162
|
|
|
|
1163
|
|
|
/** |
1164
|
|
|
* Alias for getWebhookUpdate |
1165
|
|
|
* |
1166
|
|
|
* @deprecated Call method getWebhookUpdate (note lack of letter s at end) |
1167
|
|
|
* To be removed in next major version. |
1168
|
|
|
* |
1169
|
|
|
* @param bool $shouldEmitEvent |
1170
|
|
|
* |
1171
|
|
|
* @return Update |
1172
|
|
|
*/ |
1173
|
|
|
public function getWebhookUpdates($shouldEmitEvent = true) |
1174
|
|
|
{ |
1175
|
2 |
|
return $this->getWebhookUpdate($shouldEmitEvent); |
1176
|
|
|
} |
1177
|
2 |
|
|
1178
|
|
|
/** |
1179
|
2 |
|
* Removes the outgoing webhook (if any). |
1180
|
|
|
* |
1181
|
|
|
* @throws TelegramSDKException |
1182
|
|
|
* |
1183
|
|
|
* @return TelegramResponse |
1184
|
|
|
*/ |
1185
|
|
|
public function removeWebhook() |
1186
|
|
|
{ |
1187
|
|
|
$url = ''; |
1188
|
|
|
|
1189
|
|
|
return $this->post('setWebhook', compact('url')); |
1190
|
|
|
} |
1191
|
|
|
|
1192
|
|
|
/** |
1193
|
|
|
* Use this method to receive incoming updates using long polling. |
1194
|
|
|
* |
1195
|
|
|
* <code> |
1196
|
|
|
* $params = [ |
1197
|
|
|
* 'offset' => '', |
1198
|
|
|
* 'limit' => '', |
1199
|
|
|
* 'timeout' => '', |
1200
|
|
|
* ]; |
1201
|
|
|
* </code> |
1202
|
|
|
* |
1203
|
|
|
* @link https://core.telegram.org/bots/api#getupdates |
1204
|
|
|
* |
1205
|
6 |
|
* @param array $params |
1206
|
|
|
* @param bool $shouldEmitEvents |
1207
|
6 |
|
* @var int|null $params ['offset'] |
1208
|
|
|
* @var int|null $params ['limit'] |
1209
|
6 |
|
* @var int|null $params ['timeout'] |
1210
|
|
|
* |
1211
|
|
|
* @throws TelegramSDKException |
1212
|
6 |
|
* |
1213
|
|
|
* @return Update[] |
1214
|
6 |
|
*/ |
1215
|
6 |
|
public function getUpdates(array $params = [], $shouldEmitEvents = true) |
1216
|
6 |
|
{ |
1217
|
|
|
$response = $this->post('getUpdates', $params); |
1218
|
6 |
|
|
1219
|
6 |
|
return collect($response->getResult()) |
1220
|
6 |
|
->map(function ($data) use ($shouldEmitEvents) { |
1221
|
|
|
|
1222
|
|
|
$update = new Update($data); |
1223
|
|
|
|
1224
|
|
|
if ($shouldEmitEvents) { |
1225
|
|
|
$this->emitEvent(new UpdateWasReceived($update, $this)); |
1226
|
|
|
} |
1227
|
|
|
|
1228
|
|
|
return $update; |
1229
|
|
|
}) |
1230
|
|
|
->all(); |
1231
|
|
|
} |
1232
|
|
|
|
1233
|
|
|
|
1234
|
|
|
/** |
1235
|
|
|
* Builds a custom keyboard markup. |
1236
|
|
|
* |
1237
|
|
|
* <code> |
1238
|
|
|
* $params = [ |
1239
|
|
|
* 'keyboard' => '', |
1240
|
|
|
* 'resize_keyboard' => '', |
1241
|
|
|
* 'one_time_keyboard' => '', |
1242
|
|
|
* 'selective' => '', |
1243
|
|
|
* ]; |
1244
|
|
|
* </code> |
1245
|
|
|
* |
1246
|
|
|
* @deprecated Use Telegram\Bot\Keyboard\Keyboard::make(array $params = []) instead. |
1247
|
|
|
* To be removed in next major version. |
1248
|
|
|
* |
1249
|
|
|
* @link https://core.telegram.org/bots/api#replykeyboardmarkup |
1250
|
|
|
* |
1251
|
|
|
* @param array $params |
1252
|
|
|
* |
1253
|
|
|
* @var array $params ['keyboard'] |
1254
|
|
|
* @var bool $params ['resize_keyboard'] |
1255
|
|
|
* @var bool $params ['one_time_keyboard'] |
1256
|
|
|
* @var bool $params ['selective'] |
1257
|
|
|
* |
1258
|
|
|
* @return string |
1259
|
|
|
*/ |
1260
|
|
|
public function replyKeyboardMarkup(array $params) |
1261
|
|
|
{ |
1262
|
|
|
return Keyboard::make($params); |
1263
|
|
|
} |
1264
|
|
|
|
1265
|
|
|
/** |
1266
|
|
|
* Hide the current custom keyboard and display the default letter-keyboard. |
1267
|
|
|
* |
1268
|
|
|
* <code> |
1269
|
|
|
* $params = [ |
1270
|
|
|
* 'hide_keyboard' => true, |
1271
|
|
|
* 'selective' => false, |
1272
|
|
|
* ]; |
1273
|
|
|
* </code> |
1274
|
|
|
* |
1275
|
|
|
* @deprecated Use Telegram\Bot\Keyboard\Keyboard::hide(array $params = []) instead. |
1276
|
|
|
* To be removed in next major version. |
1277
|
|
|
* |
1278
|
|
|
* @link https://core.telegram.org/bots/api#replykeyboardhide |
1279
|
|
|
* |
1280
|
|
|
* @param array $params |
1281
|
|
|
* |
1282
|
|
|
* @var bool $params ['hide_keyboard'] |
1283
|
|
|
* @var bool $params ['selective'] |
1284
|
|
|
* |
1285
|
|
|
* @return string |
1286
|
|
|
*/ |
1287
|
|
|
public static function replyKeyboardHide(array $params = []) |
1288
|
|
|
{ |
1289
|
|
|
return Keyboard::hide($params); |
1290
|
|
|
} |
1291
|
|
|
|
1292
|
|
|
/** |
1293
|
|
|
* Display a reply interface to the user (act as if the user has selected the bot‘s message and tapped ’Reply'). |
1294
|
|
|
* |
1295
|
|
|
* <code> |
1296
|
|
|
* $params = [ |
1297
|
|
|
* 'force_reply' => true, |
1298
|
|
|
* 'selective' => false, |
1299
|
|
|
* ]; |
1300
|
|
|
* </code> |
1301
|
|
|
* |
1302
|
|
|
* @deprecated Use Telegram\Bot\Keyboard\Keyboard::forceReply(array $params = []) instead. |
1303
|
|
|
* To be removed in next major version. |
1304
|
|
|
* |
1305
|
|
|
* @link https://core.telegram.org/bots/api#forcereply |
1306
|
|
|
* |
1307
|
|
|
* @param array $params |
1308
|
|
|
* |
1309
|
|
|
* @var bool $params ['force_reply'] |
1310
|
|
|
* @var bool $params ['selective'] |
1311
|
|
|
* |
1312
|
|
|
* @return Keyboard |
1313
|
|
|
*/ |
1314
|
|
|
public static function forceReply(array $params = []) |
1315
|
|
|
{ |
1316
|
6 |
|
return Keyboard::forceReply($params); |
1317
|
|
|
} |
1318
|
6 |
|
|
1319
|
|
|
/** |
1320
|
|
|
* Processes Inbound Commands. |
1321
|
|
|
* |
1322
|
|
|
* @param bool $webhook |
1323
|
|
|
* @param array $params |
1324
|
|
|
* |
1325
|
6 |
|
* @return Update|Update[] |
1326
|
6 |
|
*/ |
1327
|
|
|
public function commandsHandler($webhook = false, array $params = []) |
1328
|
6 |
|
{ |
1329
|
6 |
|
if ($webhook) { |
1330
|
6 |
|
$update = $this->getWebhookUpdate(); |
1331
|
6 |
|
$this->processCommand($update); |
1332
|
|
|
|
1333
|
|
|
return $update; |
1334
|
6 |
|
} |
1335
|
6 |
|
|
1336
|
6 |
|
$updates = $this->getUpdates($params); |
1337
|
6 |
|
$highestId = -1; |
1338
|
6 |
|
|
1339
|
6 |
|
foreach ($updates as $update) { |
1340
|
|
|
$highestId = $update->getUpdateId(); |
1341
|
6 |
|
$this->processCommand($update); |
1342
|
|
|
} |
1343
|
|
|
|
1344
|
|
|
//An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. |
1345
|
|
|
if ($highestId != -1) { |
1346
|
|
|
$params = []; |
1347
|
|
|
$params['offset'] = $highestId + 1; |
1348
|
|
|
$params['limit'] = 1; |
1349
|
6 |
|
$this->markUpdateAsRead($params); |
1350
|
|
|
} |
1351
|
6 |
|
|
1352
|
|
|
return $updates; |
1353
|
6 |
|
} |
1354
|
6 |
|
|
1355
|
6 |
|
/** |
1356
|
6 |
|
* Check update object for a command and process. |
1357
|
|
|
* |
1358
|
|
|
* @param Update $update |
1359
|
|
|
*/ |
1360
|
|
|
public function processCommand(Update $update) |
1361
|
|
|
{ |
1362
|
|
|
$message = $update->getMessage(); |
1363
|
|
|
|
1364
|
|
|
if ($message !== null && $message->has('text')) { |
1365
|
|
|
$this->getCommandBus()->handler($message->getText(), $update); |
1366
|
|
|
} |
1367
|
|
|
} |
1368
|
|
|
|
1369
|
|
|
/** |
1370
|
|
|
* Helper to Trigger Commands. |
1371
|
|
|
* |
1372
|
|
|
* @param string $name Command Name |
1373
|
|
|
* @param Update $update Update Object |
1374
|
|
|
* |
1375
|
|
|
* @return mixed |
1376
|
|
|
*/ |
1377
|
|
|
public function triggerCommand($name, Update $update) |
1378
|
|
|
{ |
1379
|
|
|
return $this->getCommandBus()->execute($name, $update->getMessage()->getText(), $update); |
1380
|
|
|
} |
1381
|
|
|
|
1382
|
|
|
/** |
1383
|
|
|
* Determine if a given type is the message. |
1384
|
|
|
* |
1385
|
|
|
* @deprecated Call method isType directly on Message object |
1386
|
|
|
* To be removed in next major version. |
1387
|
|
|
* |
1388
|
|
|
* @param string $type |
1389
|
|
|
* @param Update|Message $object |
1390
|
|
|
* |
1391
|
|
|
* @throws \ErrorException |
1392
|
|
|
* |
1393
|
|
|
*/ |
1394
|
|
|
public function isMessageType($type, $object) |
|
|
|
|
1395
|
|
|
{ |
1396
|
|
|
trigger_error('This method has been deprecated. Use isType() on the Message object instead.', E_USER_DEPRECATED); |
1397
|
|
|
} |
1398
|
|
|
|
1399
|
|
|
/** |
1400
|
|
|
* Detect Message Type Based on Update or Message Object. |
1401
|
|
|
* |
1402
|
|
|
* @deprecated Call method detectType directly on Message object |
1403
|
|
|
* To be removed in next major version. |
1404
|
|
|
* |
1405
|
|
|
* @param Update|Message $object |
1406
|
|
|
* |
1407
|
|
|
* @throws \ErrorException |
1408
|
|
|
* |
1409
|
|
|
* @return string|null |
1410
|
|
|
*/ |
1411
|
|
|
public function detectMessageType($object) |
|
|
|
|
1412
|
|
|
{ |
1413
|
|
|
trigger_error('This method has been deprecated. Use detectType() on the Message object instead.', E_USER_DEPRECATED); |
1414
|
|
|
} |
1415
|
|
|
|
1416
|
|
|
/** |
1417
|
|
|
* Sends a GET request to Telegram Bot API and returns the result. |
1418
|
|
|
* |
1419
|
|
|
* @param string $endpoint |
1420
|
|
|
* @param array $params |
1421
|
|
|
* |
1422
|
|
|
* @throws TelegramSDKException |
1423
|
|
|
* |
1424
|
|
|
* @return TelegramResponse |
1425
|
|
|
*/ |
1426
|
|
|
protected function get($endpoint, $params = []) |
1427
|
|
|
{ |
1428
|
|
|
if (array_key_exists('reply_markup', $params)) { |
1429
|
|
|
$params['reply_markup'] = (string)$params['reply_markup']; |
1430
|
|
|
} |
1431
|
|
|
|
1432
|
|
|
return $this->sendRequest( |
1433
|
|
|
'GET', |
1434
|
|
|
$endpoint, |
1435
|
|
|
$params |
1436
|
|
|
); |
1437
|
40 |
|
} |
1438
|
|
|
|
1439
|
40 |
|
/** |
1440
|
16 |
|
* Sends a POST request to Telegram Bot API and returns the result. |
1441
|
16 |
|
* |
1442
|
|
|
* @param string $endpoint |
1443
|
24 |
|
* @param array $params |
1444
|
|
|
* @param bool $fileUpload Set true if a file is being uploaded. |
1445
|
|
|
* |
1446
|
|
|
* @return TelegramResponse |
1447
|
24 |
|
*/ |
1448
|
|
|
protected function post($endpoint, array $params = [], $fileUpload = false) |
1449
|
|
|
{ |
1450
|
40 |
|
if ($fileUpload) { |
1451
|
40 |
|
$params = ['multipart' => $params]; |
1452
|
40 |
|
} else { |
1453
|
|
|
|
1454
|
40 |
|
if (array_key_exists('reply_markup', $params)) { |
1455
|
|
|
$params['reply_markup'] = (string)$params['reply_markup']; |
1456
|
|
|
} |
1457
|
|
|
|
1458
|
|
|
$params = ['form_params' => $params]; |
1459
|
|
|
} |
1460
|
|
|
|
1461
|
|
|
return $this->sendRequest( |
1462
|
|
|
'POST', |
1463
|
|
|
$endpoint, |
1464
|
|
|
$params |
1465
|
|
|
); |
1466
|
|
|
} |
1467
|
|
|
|
1468
|
16 |
|
/** |
1469
|
|
|
* Sends a multipart/form-data request to Telegram Bot API and returns the result. |
1470
|
16 |
|
* Used primarily for file uploads. |
1471
|
|
|
* |
1472
|
16 |
|
* @param string $endpoint |
1473
|
16 |
|
* @param array $params |
1474
|
16 |
|
* |
1475
|
|
|
* @throws TelegramSDKException |
1476
|
16 |
|
* |
1477
|
|
|
* @return TelegramResponse |
1478
|
|
|
*/ |
1479
|
|
|
protected function uploadFile($endpoint, array $params = []) |
1480
|
|
|
{ |
1481
|
16 |
|
$multipart_params = collect($params) |
1482
|
16 |
|
->reject(function ($value) { |
1483
|
16 |
|
return is_null($value); |
1484
|
16 |
|
}) |
1485
|
|
|
->map(function ($contents, $name) { |
1486
|
16 |
|
|
1487
|
16 |
|
if (!is_resource($contents) && $this->isValidFileOrUrl($name, $contents)) { |
1488
|
|
|
$contents = (new InputFile($contents))->open(); |
1489
|
16 |
|
} |
1490
|
|
|
|
1491
|
|
|
return [ |
1492
|
|
|
'name' => $name, |
1493
|
|
|
'contents' => $contents, |
1494
|
|
|
]; |
1495
|
|
|
}) |
1496
|
|
|
//Reset the keys on the collection |
1497
|
|
|
->values() |
1498
|
|
|
->all(); |
1499
|
|
|
|
1500
|
|
|
return $this->post($endpoint, $multipart_params, true); |
1501
|
|
|
} |
1502
|
|
|
|
1503
|
40 |
|
/** |
1504
|
|
|
* Sends a request to Telegram Bot API and returns the result. |
1505
|
|
|
* |
1506
|
|
|
* @param string $method |
1507
|
|
|
* @param string $endpoint |
1508
|
40 |
|
* @param array $params |
1509
|
|
|
* |
1510
|
40 |
|
* @throws TelegramSDKException |
1511
|
|
|
* |
1512
|
|
|
* @return TelegramResponse |
1513
|
|
|
*/ |
1514
|
|
|
protected function sendRequest( |
1515
|
|
|
$method, |
1516
|
|
|
$endpoint, |
1517
|
|
|
array $params = [] |
1518
|
|
|
) { |
1519
|
|
|
$request = $this->request($method, $endpoint, $params); |
1520
|
|
|
|
1521
|
|
|
return $this->lastResponse = $this->client->sendRequest($request); |
1522
|
40 |
|
} |
1523
|
|
|
|
1524
|
|
|
/** |
1525
|
|
|
* Instantiates a new TelegramRequest entity. |
1526
|
|
|
* |
1527
|
40 |
|
* @param string $method |
1528
|
40 |
|
* @param string $endpoint |
1529
|
40 |
|
* @param array $params |
1530
|
40 |
|
* |
1531
|
40 |
|
* @return TelegramRequest |
1532
|
40 |
|
*/ |
1533
|
40 |
|
protected function request( |
1534
|
40 |
|
$method, |
1535
|
40 |
|
$endpoint, |
1536
|
|
|
array $params = [] |
1537
|
|
|
) { |
1538
|
|
|
return new TelegramRequest( |
1539
|
|
|
$this->getAccessToken(), |
1540
|
|
|
$method, |
1541
|
|
|
$endpoint, |
1542
|
|
|
$params, |
1543
|
|
|
$this->isAsyncRequest(), |
1544
|
|
|
$this->getTimeOut(), |
1545
|
|
|
$this->getConnectTimeOut() |
1546
|
|
|
); |
1547
|
|
|
} |
1548
|
2 |
|
|
1549
|
|
|
/** |
1550
|
2 |
|
* Magic method to process any "get" requests. |
1551
|
2 |
|
* |
1552
|
|
|
* @param $method |
1553
|
|
|
* @param $arguments |
1554
|
|
|
* |
1555
|
|
|
* @throws TelegramSDKException |
1556
|
|
|
* |
1557
|
|
|
* @return bool|TelegramResponse|UnknownObject |
1558
|
|
|
*/ |
1559
|
|
|
public function __call($method, $arguments) |
1560
|
|
|
{ |
1561
|
|
|
if (preg_match('/^\w+Commands?/', $method, $matches)) { |
1562
|
|
|
return call_user_func_array([$this->getCommandBus(), $matches[0]], $arguments); |
1563
|
|
|
} |
1564
|
|
|
|
1565
|
|
|
$action = substr($method, 0, 3); |
1566
|
|
|
if ($action === 'get') { |
1567
|
|
|
/* @noinspection PhpUndefinedFunctionInspection */ |
1568
|
|
|
$class_name = Str::studly(substr($method, 3)); |
1569
|
|
|
$class = 'Telegram\Bot\Objects\\'.$class_name; |
1570
|
|
|
$response = $this->post($method, $arguments[0] ?: []); |
1571
|
|
|
|
1572
|
|
|
if (class_exists($class)) { |
1573
|
|
|
return new $class($response->getDecodedBody()); |
1574
|
|
|
} |
1575
|
|
|
|
1576
|
|
|
return $response; |
1577
|
|
|
} |
1578
|
|
|
$response = $this->post($method, $arguments[0]); |
1579
|
2 |
|
|
1580
|
|
|
return new UnknownObject($response->getDecodedBody()); |
1581
|
2 |
|
} |
1582
|
2 |
|
|
1583
|
|
|
/** |
1584
|
|
|
* Set the IoC Container. |
1585
|
|
|
* |
1586
|
|
|
* @param $container Container instance |
1587
|
|
|
* |
1588
|
|
|
* @return void |
1589
|
2 |
|
*/ |
1590
|
|
|
public static function setContainer(Container $container) |
1591
|
2 |
|
{ |
1592
|
|
|
self::$container = $container; |
1593
|
|
|
} |
1594
|
|
|
|
1595
|
|
|
/** |
1596
|
|
|
* Get the IoC Container. |
1597
|
|
|
* |
1598
|
|
|
* @return Container |
1599
|
|
|
*/ |
1600
|
|
|
public function getContainer() |
1601
|
|
|
{ |
1602
|
|
|
return self::$container; |
1603
|
|
|
} |
1604
|
|
|
|
1605
|
|
|
/** |
1606
|
|
|
* Check if IoC Container has been set. |
1607
|
40 |
|
* |
1608
|
|
|
* @return boolean |
1609
|
40 |
|
*/ |
1610
|
|
|
public function hasContainer() |
1611
|
|
|
{ |
1612
|
|
|
return self::$container !== null; |
1613
|
|
|
} |
1614
|
|
|
|
1615
|
|
|
/** |
1616
|
|
|
* @return int |
1617
|
2 |
|
*/ |
1618
|
|
|
public function getTimeOut() |
1619
|
2 |
|
{ |
1620
|
|
|
return $this->timeOut; |
1621
|
2 |
|
} |
1622
|
|
|
|
1623
|
|
|
/** |
1624
|
|
|
* @param int $timeOut |
1625
|
|
|
* |
1626
|
|
|
* @return $this |
1627
|
40 |
|
*/ |
1628
|
|
|
public function setTimeOut($timeOut) |
1629
|
40 |
|
{ |
1630
|
|
|
$this->timeOut = $timeOut; |
1631
|
|
|
|
1632
|
|
|
return $this; |
1633
|
|
|
} |
1634
|
|
|
|
1635
|
|
|
/** |
1636
|
|
|
* @return int |
1637
|
2 |
|
*/ |
1638
|
|
|
public function getConnectTimeOut() |
1639
|
2 |
|
{ |
1640
|
|
|
return $this->connectTimeOut; |
1641
|
2 |
|
} |
1642
|
|
|
|
1643
|
|
|
/** |
1644
|
|
|
* @param int $connectTimeOut |
1645
|
|
|
* |
1646
|
|
|
* @return $this |
1647
|
|
|
*/ |
1648
|
|
|
public function setConnectTimeOut($connectTimeOut) |
1649
|
|
|
{ |
1650
|
|
|
$this->connectTimeOut = $connectTimeOut; |
1651
|
6 |
|
|
1652
|
|
|
return $this; |
1653
|
6 |
|
} |
1654
|
|
|
|
1655
|
|
|
/** |
1656
|
|
|
* An alias for getUpdates that helps readability. |
1657
|
|
|
* |
1658
|
|
|
* @param $params |
1659
|
|
|
* |
1660
|
|
|
* @return Objects\Update[] |
1661
|
|
|
*/ |
1662
|
|
|
protected function markUpdateAsRead($params) |
1663
|
|
|
{ |
1664
|
|
|
return $this->getUpdates($params, false); |
1665
|
16 |
|
} |
1666
|
|
|
|
1667
|
|
|
/** |
1668
|
16 |
|
* Determines if the string passed to be uploaded is a valid |
1669
|
2 |
|
* file on the local file system, or a valid remote URL. |
1670
|
|
|
* |
1671
|
|
|
* @param string $name |
1672
|
|
|
* @param string $contents |
1673
|
|
|
* |
1674
|
14 |
|
* @return bool |
1675
|
|
|
*/ |
1676
|
|
|
protected function isValidFileOrUrl($name, $contents) |
1677
|
|
|
{ |
1678
|
|
|
//Don't try to open a url as an actual file when using this method to setWebhook. |
1679
|
14 |
|
if ($name == 'url') { |
1680
|
|
|
return false; |
1681
|
|
|
} |
1682
|
|
|
|
1683
|
|
|
//If a certificate name is passed, we must check for the file existing on the local server, |
1684
|
14 |
|
// otherwise telegram ignores the fact it wasn't sent and no error is thrown. |
1685
|
|
|
if ($name == 'certificate') { |
1686
|
|
|
return true; |
1687
|
|
|
} |
1688
|
|
|
|
1689
|
|
|
//Is the content a valid file name. |
1690
|
|
|
if (is_readable($contents)) { |
1691
|
|
|
return true; |
1692
|
|
|
} |
1693
|
|
|
|
1694
|
|
|
//Is the content a valid URL |
1695
|
|
|
return filter_var($contents, FILTER_VALIDATE_URL); |
1696
|
|
|
} |
1697
|
|
|
} |
1698
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.