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