Passed
Push — master ( e4d3c0...4ffd06 )
by
unknown
05:01
created

BotApi::sendVenue()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 23
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 23
c 0
b 0
f 0
ccs 0
cts 12
cp 0
rs 9.0856
cc 2
eloc 20
nc 1
nop 9
crap 6

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace TelegramBot\Api;
4
5
use TelegramBot\Api\Types\ArrayOfUpdates;
6
use TelegramBot\Api\Types\Chat;
7
use TelegramBot\Api\Types\ChatMember;
8
use TelegramBot\Api\Types\File;
9
use TelegramBot\Api\Types\Inline\QueryResult\AbstractInlineQueryResult;
10
use TelegramBot\Api\Types\Message;
11
use TelegramBot\Api\Types\Update;
12
use TelegramBot\Api\Types\User;
13
use TelegramBot\Api\Types\UserProfilePhotos;
14
15
/**
16
 * Class BotApi
17
 *
18
 * @package TelegramBot\Api
19
 */
20
class BotApi
21
{
22
    /**
23
     * HTTP codes
24
     *
25
     * @var array
26
     */
27
    public static $codes = [
28
        // Informational 1xx
29
        100 => 'Continue',
30
        101 => 'Switching Protocols',
31
        102 => 'Processing',            // RFC2518
32
        // Success 2xx
33
        200 => 'OK',
34
        201 => 'Created',
35
        202 => 'Accepted',
36
        203 => 'Non-Authoritative Information',
37
        204 => 'No Content',
38
        205 => 'Reset Content',
39
        206 => 'Partial Content',
40
        207 => 'Multi-Status',          // RFC4918
41
        208 => 'Already Reported',      // RFC5842
42
        226 => 'IM Used',               // RFC3229
43
        // Redirection 3xx
44
        300 => 'Multiple Choices',
45
        301 => 'Moved Permanently',
46
        302 => 'Found', // 1.1
47
        303 => 'See Other',
48
        304 => 'Not Modified',
49
        305 => 'Use Proxy',
50
        // 306 is deprecated but reserved
51
        307 => 'Temporary Redirect',
52
        308 => 'Permanent Redirect',    // RFC7238
53
        // Client Error 4xx
54
        400 => 'Bad Request',
55
        401 => 'Unauthorized',
56
        402 => 'Payment Required',
57
        403 => 'Forbidden',
58
        404 => 'Not Found',
59
        405 => 'Method Not Allowed',
60
        406 => 'Not Acceptable',
61
        407 => 'Proxy Authentication Required',
62
        408 => 'Request Timeout',
63
        409 => 'Conflict',
64
        410 => 'Gone',
65
        411 => 'Length Required',
66
        412 => 'Precondition Failed',
67
        413 => 'Payload Too Large',
68
        414 => 'URI Too Long',
69
        415 => 'Unsupported Media Type',
70
        416 => 'Range Not Satisfiable',
71
        417 => 'Expectation Failed',
72
        422 => 'Unprocessable Entity',                                        // RFC4918
73
        423 => 'Locked',                                                      // RFC4918
74
        424 => 'Failed Dependency',                                           // RFC4918
75
        425 => 'Reserved for WebDAV advanced collections expired proposal',   // RFC2817
76
        426 => 'Upgrade Required',                                            // RFC2817
77
        428 => 'Precondition Required',                                       // RFC6585
78
        429 => 'Too Many Requests',                                           // RFC6585
79
        431 => 'Request Header Fields Too Large',                             // RFC6585
80
        // Server Error 5xx
81
        500 => 'Internal Server Error',
82
        501 => 'Not Implemented',
83
        502 => 'Bad Gateway',
84
        503 => 'Service Unavailable',
85
        504 => 'Gateway Timeout',
86
        505 => 'HTTP Version Not Supported',
87
        506 => 'Variant Also Negotiates (Experimental)',                      // RFC2295
88
        507 => 'Insufficient Storage',                                        // RFC4918
89
        508 => 'Loop Detected',                                               // RFC5842
90
        510 => 'Not Extended',                                                // RFC2774
91
        511 => 'Network Authentication Required',                             // RFC6585
92
    ];
93
94
95
    /**
96
     * Default http status code
97
     */
98
    const DEFAULT_STATUS_CODE = 200;
99
100
    /**
101
     * Not Modified http status code
102
     */
103
    const NOT_MODIFIED_STATUS_CODE = 304;
104
105
    /**
106
     * Limits for tracked ids
107
     */
108
    const MAX_TRACKED_EVENTS = 200;
109
110
    /**
111
     * Url prefixes
112
     */
113
    const URL_PREFIX = 'https://api.telegram.org/bot';
114
115
    /**
116
     * Url prefix for files
117
     */
118
    const FILE_URL_PREFIX = 'https://api.telegram.org/file/bot';
119
120
    /**
121
     * CURL object
122
     *
123
     * @var
124
     */
125
    protected $curl;
126
127
    /**
128
     * Bot token
129
     *
130
     * @var string
131
     */
132
    protected $token;
133
134
    /**
135
     * Botan tracker
136
     *
137
     * @var \TelegramBot\Api\Botan
138
     */
139
    protected $tracker;
140
141
    /**
142
     * list of event ids
143
     *
144
     * @var array
145
     */
146
    protected $trackedEvents = [];
147
148
    /**
149
     * Check whether return associative array
150
     *
151
     * @var bool
152
     */
153
    protected $returnArray = true;
154
155
156
    /**
157
     * Constructor
158
     *
159
     * @param string $token Telegram Bot API token
160
     * @param string|null $trackerToken Yandex AppMetrica application api_key
161
     */
162 9
    public function __construct($token, $trackerToken = null)
163
    {
164 9
        $this->curl = curl_init();
165 9
        $this->token = $token;
166
167 9
        if ($trackerToken) {
168
            $this->tracker = new Botan($trackerToken);
169
        }
170 9
    }
171
172
    /**
173
     * Set return array
174
     *
175
     * @param bool $mode
176
     *
177
     * @return $this
178
     */
179
    public function setModeObject($mode = true)
180
    {
181
        $this->returnArray = !$mode;
182
183
        return $this;
184
    }
185
186
187
    /**
188
     * Call method
189
     *
190
     * @param string $method
191
     * @param array|null $data
192
     *
193
     * @return mixed
194
     * @throws \TelegramBot\Api\Exception
195
     * @throws \TelegramBot\Api\HttpException
196
     * @throws \TelegramBot\Api\InvalidJsonException
197
     */
198
    public function call($method, array $data = null)
199
    {
200
        $options = [
201
            CURLOPT_URL => $this->getUrl().'/'.$method,
202
            CURLOPT_RETURNTRANSFER => true,
203
            CURLOPT_POST => null,
204
            CURLOPT_POSTFIELDS => null,
205
        ];
206
207
        if ($data) {
208
            $options[CURLOPT_POST] = true;
209
            $options[CURLOPT_POSTFIELDS] = $data;
210
        }
211
212
        $response = self::jsonValidate($this->executeCurl($options), $this->returnArray);
213
214
        if ($this->returnArray) {
215
            if (!isset($response['ok'])) {
216
                throw new Exception($response['description'], $response['error_code']);
217
            }
218
219
            return $response['result'];
220
        }
221
222
        if (!$response->ok) {
223
            throw new Exception($response->description, $response->error_code);
224
        }
225
226
        return $response->result;
227
    }
228
229
    /**
230
     * curl_exec wrapper for response validation
231
     *
232
     * @param array $options
233
     *
234
     * @return string
235
     *
236
     * @throws \TelegramBot\Api\HttpException
237
     */
238
    protected function executeCurl(array $options)
239
    {
240
        curl_setopt_array($this->curl, $options);
241
242
        $result = curl_exec($this->curl);
243
        self::curlValidate($this->curl, $result);
244
        if ($result === false) {
245
            throw new HttpException(curl_error($this->curl), curl_errno($this->curl));
246
        }
247
248
        return $result;
249
    }
250
251
    /**
252
     * Response validation
253
     *
254
     * @param resource $curl
255
     * @param string $response
256
     * @throws HttpException
257
     */
258
    public static function curlValidate($curl, $response = null)
259
    {
260
        $json = json_decode($response, true)?: [];
261
        if (($httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE))
262
            && !in_array($httpCode, [self::DEFAULT_STATUS_CODE, self::NOT_MODIFIED_STATUS_CODE])
263
        ) {
264
            $errorDescription = array_key_exists('description', $json) ? $json['description'] : self::$codes[$httpCode];
265
            throw new HttpException($errorDescription, $httpCode);
266
        }
267
    }
268
269
    /**
270
     * JSON validation
271
     *
272
     * @param string $jsonString
273
     * @param boolean $asArray
274
     *
275
     * @return object|array
276
     * @throws \TelegramBot\Api\InvalidJsonException
277
     */
278
    public static function jsonValidate($jsonString, $asArray)
279
    {
280
        $json = json_decode($jsonString, $asArray);
281
282
        if (json_last_error() != JSON_ERROR_NONE) {
283
            throw new InvalidJsonException(json_last_error_msg(), json_last_error());
284
        }
285
286
        return $json;
287
    }
288
289
    /**
290
     * Use this method to send text messages. On success, the sent \TelegramBot\Api\Types\Message is returned.
291
     *
292
     * @param int|string $chatId
293
     * @param string $text
294
     * @param string|null $parseMode
295
     * @param bool $disablePreview
296
     * @param int|null $replyToMessageId
297
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
298
     * @param bool $disableNotification
299
     *
300
     * @return \TelegramBot\Api\Types\Message
301
     * @throws \TelegramBot\Api\InvalidArgumentException
302
     * @throws \TelegramBot\Api\Exception
303
     */
304
    public function sendMessage(
305
        $chatId,
306
        $text,
307
        $parseMode = null,
308
        $disablePreview = false,
309
        $replyToMessageId = null,
310
        $replyMarkup = null,
311
        $disableNotification = false
312
    ) {
313
        return Message::fromResponse($this->call('sendMessage', [
314
            'chat_id' => $chatId,
315
            'text' => $text,
316
            'parse_mode' => $parseMode,
317
            'disable_web_page_preview' => $disablePreview,
318
            'reply_to_message_id' => (int)$replyToMessageId,
319
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
320
            'disable_notification' => (bool)$disableNotification,
321
        ]));
322
    }
323
324
    /**
325
     * Use this method to send phone contacts
326
     *
327
     * @param int|string $chatId chat_id or @channel_name
328
     * @param string $phoneNumber
329
     * @param string $firstName
330
     * @param string $lastName
331
     * @param int|null $replyToMessageId
332
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
333
     * @param bool $disableNotification
334
     *
335
     * @return \TelegramBot\Api\Types\Message
336
     * @throws \TelegramBot\Api\Exception
337
     */
338 View Code Duplication
    public function sendContact(
339
        $chatId,
340
        $phoneNumber,
341
        $firstName,
342
        $lastName = null,
343
        $replyToMessageId = null,
344
        $replyMarkup = null,
345
        $disableNotification = false
346
    ) {
347
        return Message::fromResponse($this->call('sendContact', [
348
            'chat_id' => $chatId,
349
            'phone_number' => $phoneNumber,
350
            'first_name' => $firstName,
351
            'last_name' => $lastName,
352
            'reply_to_message_id' => $replyToMessageId,
353
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
354
            'disable_notification' => (bool)$disableNotification,
355
        ]));
356
    }
357
358
    /**
359
     * Use this method when you need to tell the user that something is happening on the bot's side.
360
     * The status is set for 5 seconds or less (when a message arrives from your bot,
361
     * Telegram clients clear its typing status).
362
     *
363
     * We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
364
     *
365
     * Type of action to broadcast. Choose one, depending on what the user is about to receive:
366
     * `typing` for text messages, `upload_photo` for photos, `record_video` or `upload_video` for videos,
367
     * `record_audio` or upload_audio for audio files, `upload_document` for general files,
368
     * `find_location` for location data.
369
     *
370
     * @param int $chatId
371
     * @param string $action
372
     *
373
     * @return bool
374
     * @throws \TelegramBot\Api\Exception
375
     */
376
    public function sendChatAction($chatId, $action)
377
    {
378
        return $this->call('sendChatAction', [
379
            'chat_id' => $chatId,
380
            'action' => $action,
381
        ]);
382
    }
383
384
    /**
385
     * Use this method to get a list of profile pictures for a user.
386
     *
387
     * @param int $userId
388
     * @param int $offset
389
     * @param int $limit
390
     *
391
     * @return \TelegramBot\Api\Types\UserProfilePhotos
392
     * @throws \TelegramBot\Api\Exception
393
     */
394
    public function getUserProfilePhotos($userId, $offset = 0, $limit = 100)
395
    {
396
        return UserProfilePhotos::fromResponse($this->call('getUserProfilePhotos', [
397
            'user_id' => (int)$userId,
398
            'offset' => (int)$offset,
399
            'limit' => (int)$limit,
400
        ]));
401
    }
402
403
    /**
404
     * Use this method to specify a url and receive incoming updates via an outgoing webhook.
405
     * Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url,
406
     * containing a JSON-serialized Update.
407
     * In case of an unsuccessful request, we will give up after a reasonable amount of attempts.
408
     *
409
     * @param string $url HTTPS url to send updates to. Use an empty string to remove webhook integration
410
     * @param \CURLFile|string $certificate Upload your public key certificate
411
     *                                      so that the root certificate in use can be checked
412
     *
413
     * @return string
414
     *
415
     * @throws \TelegramBot\Api\Exception
416
     */
417
    public function setWebhook($url = '', $certificate = null)
418
    {
419
        return $this->call('setWebhook', ['url' => $url, 'certificate' => $certificate]);
420
    }
421
422
    /**
423
     * A simple method for testing your bot's auth token.Requires no parameters.
424
     * Returns basic information about the bot in form of a User object.
425
     *
426
     * @return \TelegramBot\Api\Types\User
427
     * @throws \TelegramBot\Api\Exception
428
     * @throws \TelegramBot\Api\InvalidArgumentException
429
     */
430
    public function getMe()
431
    {
432
        return User::fromResponse($this->call('getMe'));
433
    }
434
435
    /**
436
     * Use this method to receive incoming updates using long polling.
437
     * An Array of Update objects is returned.
438
     *
439
     * Notes
440
     * 1. This method will not work if an outgoing webhook is set up.
441
     * 2. In order to avoid getting duplicate updates, recalculate offset after each server response.
442
     *
443
     * @param int $offset
444
     * @param int $limit
445
     * @param int $timeout
446
     *
447
     * @return Update[]
448
     * @throws \TelegramBot\Api\Exception
449
     * @throws \TelegramBot\Api\InvalidArgumentException
450
     */
451 2
    public function getUpdates($offset = 0, $limit = 100, $timeout = 0)
452
    {
453 2
        $updates = ArrayOfUpdates::fromResponse($this->call('getUpdates', [
454 2
            'offset' => $offset,
455 2
            'limit' => $limit,
456 2
            'timeout' => $timeout,
457 2
        ]));
458
459 2
        if ($this->tracker instanceof Botan) {
460
            foreach ($updates as $update) {
461
                $this->trackUpdate($update);
462
            }
463
        }
464
465 2
        return $updates;
466
    }
467
468
    /**
469
     * Use this method to send point on the map. On success, the sent Message is returned.
470
     *
471
     * @param int $chatId
472
     * @param float $latitude
473
     * @param float $longitude
474
     * @param int|null $replyToMessageId
475
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
476
     * @param bool $disableNotification
477
     *
478
     * @return \TelegramBot\Api\Types\Message
479
     * @throws \TelegramBot\Api\Exception
480
     */
481 View Code Duplication
    public function sendLocation(
482
        $chatId,
483
        $latitude,
484
        $longitude,
485
        $replyToMessageId = null,
486
        $replyMarkup = null,
487
        $disableNotification = false
488
    ) {
489
        return Message::fromResponse($this->call('sendLocation', [
490
            'chat_id' => $chatId,
491
            'latitude' => $latitude,
492
            'longitude' => $longitude,
493
            'reply_to_message_id' => $replyToMessageId,
494
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
495
            'disable_notification' => (bool)$disableNotification,
496
        ]));
497
    }
498
499
    /**
500
     * Use this method to send information about a venue. On success, the sent Message is returned.
501
     *
502
     * @param int|string $chatId chat_id or @channel_name
503
     * @param float $latitude
504
     * @param float $longitude
505
     * @param string $title
506
     * @param string $address
507
     * @param string|null $foursquareId
508
     * @param int|null $replyToMessageId
509
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
510
     * @param bool $disableNotification
511
     *
512
     * @return \TelegramBot\Api\Types\Message
513
     * @throws \TelegramBot\Api\Exception
514
     */
515
    public function sendVenue(
516
        $chatId,
517
        $latitude,
518
        $longitude,
519
        $title,
520
        $address,
521
        $foursquareId = null,
522
        $replyToMessageId = null,
523
        $replyMarkup = null,
524
        $disableNotification = false
525
    ) {
526
        return Message::fromResponse($this->call('sendVenue', [
527
            'chat_id' => $chatId,
528
            'latitude' => $latitude,
529
            'longitude' => $longitude,
530
            'title' => $title,
531
            'address' => $address,
532
            'foursquare_id' => $foursquareId,
533
            'reply_to_message_id' => $replyToMessageId,
534
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
535
            'disable_notification' => (bool)$disableNotification,
536
        ]));
537
    }
538
539
    /**
540
     * Use this method to send .webp stickers. On success, the sent Message is returned.
541
     *
542
     * @param int|string $chatId chat_id or @channel_name
543
     * @param \CURLFile|string $sticker
544
     * @param int|null $replyToMessageId
545
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
546
     * @param bool $disableNotification
547
     *
548
     * @return \TelegramBot\Api\Types\Message
549
     * @throws \TelegramBot\Api\InvalidArgumentException
550
     * @throws \TelegramBot\Api\Exception
551
     */
552 View Code Duplication
    public function sendSticker(
553
        $chatId,
554
        $sticker,
555
        $replyToMessageId = null,
556
        $replyMarkup = null,
557
        $disableNotification = false
558
    ) {
559
        return Message::fromResponse($this->call('sendSticker', [
560
            'chat_id' => $chatId,
561
            'sticker' => $sticker,
562
            'reply_to_message_id' => $replyToMessageId,
563
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
564
            'disable_notification' => (bool)$disableNotification,
565
        ]));
566
    }
567
568
    /**
569
     * Use this method to send video files,
570
     * Telegram clients support mp4 videos (other formats may be sent as Document).
571
     * On success, the sent Message is returned.
572
     *
573
     * @param int|string $chatId chat_id or @channel_name
574
     * @param \CURLFile|string $video
575
     * @param int|null $duration
576
     * @param string|null $caption
577
     * @param int|null $replyToMessageId
578
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
579
     * @param bool $disableNotification
580
     *
581
     * @return \TelegramBot\Api\Types\Message
582
     * @throws \TelegramBot\Api\InvalidArgumentException
583
     * @throws \TelegramBot\Api\Exception
584
     */
585
    public function sendVideo(
586
        $chatId,
587
        $video,
588
        $duration = null,
589
        $caption = null,
590
        $replyToMessageId = null,
591
        $replyMarkup = null,
592
        $disableNotification = false
593
    ) {
594
        return Message::fromResponse($this->call('sendVideo', [
595
            'chat_id' => $chatId,
596
            'video' => $video,
597
            'duration' => $duration,
598
            'caption' => $caption,
599
            'reply_to_message_id' => $replyToMessageId,
600
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
601
            'disable_notification' => (bool)$disableNotification,
602
        ]));
603
    }
604
605
    /**
606
     * Use this method to send audio files,
607
     * if you want Telegram clients to display the file as a playable voice message.
608
     * For this to work, your audio must be in an .ogg file encoded with OPUS
609
     * (other formats may be sent as Audio or Document).
610
     * On success, the sent Message is returned.
611
     * Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
612
     *
613
     * @param int|string $chatId chat_id or @channel_name
614
     * @param \CURLFile|string $voice
615
     * @param int|null $duration
616
     * @param int|null $replyToMessageId
617
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
618
     * @param bool $disableNotification
619
     *
620
     * @return \TelegramBot\Api\Types\Message
621
     * @throws \TelegramBot\Api\InvalidArgumentException
622
     * @throws \TelegramBot\Api\Exception
623
     */
624 View Code Duplication
    public function sendVoice(
625
        $chatId,
626
        $voice,
627
        $duration = null,
628
        $replyToMessageId = null,
629
        $replyMarkup = null,
630
        $disableNotification = false
631
    ) {
632
        return Message::fromResponse($this->call('sendVoice', [
633
            'chat_id' => $chatId,
634
            'voice' => $voice,
635
            'duration' => $duration,
636
            'reply_to_message_id' => $replyToMessageId,
637
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
638
            'disable_notification' => (bool)$disableNotification,
639
        ]));
640
    }
641
642
    /**
643
     * Use this method to forward messages of any kind. On success, the sent Message is returned.
644
     *
645
     * @param int|string $chatId chat_id or @channel_name
646
     * @param int $fromChatId
647
     * @param int $messageId
648
     * @param bool $disableNotification
649
     *
650
     * @return \TelegramBot\Api\Types\Message
651
     * @throws \TelegramBot\Api\InvalidArgumentException
652
     * @throws \TelegramBot\Api\Exception
653
     */
654
    public function forwardMessage($chatId, $fromChatId, $messageId, $disableNotification = false)
655
    {
656
        return Message::fromResponse($this->call('forwardMessage', [
657
            'chat_id' => $chatId,
658
            'from_chat_id' => $fromChatId,
659
            'message_id' => (int)$messageId,
660
            'disable_notification' => (bool)$disableNotification,
661
        ]));
662
    }
663
664
    /**
665
     * Use this method to send audio files,
666
     * if you want Telegram clients to display them in the music player.
667
     * Your audio must be in the .mp3 format.
668
     * On success, the sent Message is returned.
669
     * Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
670
     *
671
     * For backward compatibility, when the fields title and performer are both empty
672
     * and the mime-type of the file to be sent is not audio/mpeg, the file will be sent as a playable voice message.
673
     * For this to work, the audio must be in an .ogg file encoded with OPUS.
674
     * This behavior will be phased out in the future. For sending voice messages, use the sendVoice method instead.
675
     *
676
     * @deprecated since 20th February. Removed backward compatibility from the method sendAudio.
677
     * Voice messages now must be sent using the method sendVoice.
678
     * There is no more need to specify a non-empty title or performer while sending the audio by file_id.
679
     *
680
     * @param int|string $chatId chat_id or @channel_name
681
     * @param \CURLFile|string $audio
682
     * @param int|null $duration
683
     * @param string|null $performer
684
     * @param string|null $title
685
     * @param int|null $replyToMessageId
686
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
687
     * @param bool $disableNotification
688
     *
689
     * @return \TelegramBot\Api\Types\Message
690
     * @throws \TelegramBot\Api\InvalidArgumentException
691
     * @throws \TelegramBot\Api\Exception
692
     */
693
    public function sendAudio(
694
        $chatId,
695
        $audio,
696
        $duration = null,
697
        $performer = null,
698
        $title = null,
699
        $replyToMessageId = null,
700
        $replyMarkup = null,
701
        $disableNotification = false
702
    ) {
703
        return Message::fromResponse($this->call('sendAudio', [
704
            'chat_id' => $chatId,
705
            'audio' => $audio,
706
            'duration' => $duration,
707
            'performer' => $performer,
708
            'title' => $title,
709
            'reply_to_message_id' => $replyToMessageId,
710
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
711
            'disable_notification' => (bool)$disableNotification,
712
        ]));
713
    }
714
715
    /**
716
     * Use this method to send photos. On success, the sent Message is returned.
717
     *
718
     * @param int|string $chatId chat_id or @channel_name
719
     * @param \CURLFile|string $photo
720
     * @param string|null $caption
721
     * @param int|null $replyToMessageId
722
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
723
     * @param bool $disableNotification
724
     *
725
     * @return \TelegramBot\Api\Types\Message
726
     * @throws \TelegramBot\Api\InvalidArgumentException
727
     * @throws \TelegramBot\Api\Exception
728
     */
729 View Code Duplication
    public function sendPhoto(
730
        $chatId,
731
        $photo,
732
        $caption = null,
733
        $replyToMessageId = null,
734
        $replyMarkup = null,
735
        $disableNotification = false
736
    ) {
737
        return Message::fromResponse($this->call('sendPhoto', [
738
            'chat_id' => $chatId,
739
            'photo' => $photo,
740
            'caption' => $caption,
741
            'reply_to_message_id' => $replyToMessageId,
742
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
743
            'disable_notification' => (bool)$disableNotification,
744
        ]));
745
    }
746
747
    /**
748
     * Use this method to send general files. On success, the sent Message is returned.
749
     * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
750
     *
751
     * @param int|string $chatId chat_id or @channel_name
752
     * @param \CURLFile|string $document
753
     * @param string|null $caption
754
     * @param int|null $replyToMessageId
755
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
756
     * @param bool $disableNotification
757
     *
758
     * @return \TelegramBot\Api\Types\Message
759
     * @throws \TelegramBot\Api\InvalidArgumentException
760
     * @throws \TelegramBot\Api\Exception
761
     */
762 View Code Duplication
    public function sendDocument(
763
        $chatId,
764
        $document,
765
        $caption = null,
766
        $replyToMessageId = null,
767
        $replyMarkup = null,
768
        $disableNotification = false
769
    ) {
770
        return Message::fromResponse($this->call('sendDocument', [
771
            'chat_id' => $chatId,
772
            'document' => $document,
773
            'caption' => $caption,
774
            'reply_to_message_id' => $replyToMessageId,
775
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
776
            'disable_notification' => (bool)$disableNotification,
777
        ]));
778
    }
779
780
    /**
781
     * Use this method to get basic info about a file and prepare it for downloading.
782
     * For the moment, bots can download files of up to 20MB in size.
783
     * On success, a File object is returned.
784
     * The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>,
785
     * where <file_path> is taken from the response.
786
     * It is guaranteed that the link will be valid for at least 1 hour.
787
     * When the link expires, a new one can be requested by calling getFile again.
788
     *
789
     * @param $fileId
790
     *
791
     * @return \TelegramBot\Api\Types\File
792
     * @throws \TelegramBot\Api\InvalidArgumentException
793
     * @throws \TelegramBot\Api\Exception
794
     */
795
    public function getFile($fileId)
796
    {
797
        return File::fromResponse($this->call('getFile', ['file_id' => $fileId]));
798
    }
799
800
    /**
801
     * Get file contents via cURL
802
     *
803
     * @param $fileId
804
     *
805
     * @return string
806
     *
807
     * @throws \TelegramBot\Api\HttpException
808
     */
809
    public function downloadFile($fileId)
810
    {
811
        $file = $this->getFile($fileId);
812
        $options = [
813
            CURLOPT_HEADER => 0,
814
            CURLOPT_HTTPGET => 1,
815
            CURLOPT_RETURNTRANSFER => 1,
816
            CURLOPT_URL => $this->getFileUrl().'/'.$file->getFilePath(),
817
        ];
818
819
        return $this->executeCurl($options);
820
    }
821
822
    /**
823
     * Use this method to send answers to an inline query. On success, True is returned.
824
     * No more than 50 results per query are allowed.
825
     *
826
     * @param string $inlineQueryId
827
     * @param AbstractInlineQueryResult[] $results
828
     * @param int $cacheTime
829
     * @param bool $isPersonal
830
     * @param string $nextOffset
831
     * @param string $switchPmText
832
     * @param string $switchPmParameter
833
     *
834
     * @return mixed
835
     * @throws Exception
836
     */
837
    public function answerInlineQuery(
838
        $inlineQueryId,
839
        $results,
840
        $cacheTime = 300,
841
        $isPersonal = false,
842
        $nextOffset = '',
843
        $switchPmText = null,
844
        $switchPmParameter = null
845
    ) {
846
        $results = array_map(function ($item) {
847
            /* @var AbstractInlineQueryResult $item */
848
            return json_decode($item->toJson(), true);
849
        }, $results);
850
851
        return $this->call('answerInlineQuery', [
852
            'inline_query_id' => $inlineQueryId,
853
            'results' => json_encode($results),
854
            'cache_time' => $cacheTime,
855
            'is_personal' => $isPersonal,
856
            'next_offset' => $nextOffset,
857
            'switch_pm_text' => $switchPmText,
858
            'switch_pm_parameter' => $switchPmParameter,
859
        ]);
860
    }
861
862
    /**
863
     * Use this method to kick a user from a group or a supergroup.
864
     * In the case of supergroups, the user will not be able to return to the group
865
     * on their own using invite links, etc., unless unbanned first.
866
     * The bot must be an administrator in the group for this to work. Returns True on success.
867
     *
868
     * @param int|string $chatId Unique identifier for the target group
869
     * or username of the target supergroup (in the format @supergroupusername)
870
     * @param int $userId Unique identifier of the target user
871
     * @param null|int $untilDate Date when the user will be unbanned, unix time.
872
     *                            If user is banned for more than 366 days or less than 30 seconds from the current time
873
     *                            they are considered to be banned forever
874
     *
875
     * @return bool
876
     */
877
    public function kickChatMember($chatId, $userId, $untilDate = null)
878
    {
879
        return $this->call('kickChatMember', [
880
            'chat_id' => $chatId,
881
            'user_id' => $userId,
882
            'until_date' => $untilDate
883
        ]);
884
    }
885
886
    /**
887
     * Use this method to unban a previously kicked user in a supergroup.
888
     * The user will not return to the group automatically, but will be able to join via link, etc.
889
     * The bot must be an administrator in the group for this to work. Returns True on success.
890
     *
891
     * @param int|string $chatId Unique identifier for the target group
892
     * or username of the target supergroup (in the format @supergroupusername)
893
     * @param int $userId Unique identifier of the target user
894
     *
895
     * @return bool
896
     */
897
    public function unbanChatMember($chatId, $userId)
898
    {
899
        return $this->call('unbanChatMember', [
900
            'chat_id' => $chatId,
901
            'user_id' => $userId,
902
        ]);
903
    }
904
905
    /**
906
     * Use this method to send answers to callback queries sent from inline keyboards.
907
     * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
908
     *
909
     * @param $callbackQueryId
910
     * @param null $text
911
     * @param bool $showAlert
912
     *
913
     * @return bool
914
     */
915
    public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = false)
916
    {
917
        return $this->call('answerCallbackQuery', [
918
            'callback_query_id' => $callbackQueryId,
919
            'text' => $text,
920
            'show_alert' => (bool)$showAlert,
921
        ]);
922
    }
923
924
925
    /**
926
     * Use this method to edit text messages sent by the bot or via the bot
927
     *
928
     * @param int|string $chatId
929
     * @param int $messageId
930
     * @param string $text
931
     * @param string $inlineMessageId
932
     * @param string|null $parseMode
933
     * @param bool $disablePreview
934
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
935
     * @return Message
936
     */
937 View Code Duplication
    public function editMessageText(
938
        $chatId,
939
        $messageId,
940
        $text,
941
        $parseMode = null,
942
        $disablePreview = false,
943
        $replyMarkup = null,
944
        $inlineMessageId = null
945
    ) {
946
        return Message::fromResponse($this->call('editMessageText', [
947
            'chat_id' => $chatId,
948
            'message_id' => $messageId,
949
            'text' => $text,
950
            'inline_message_id' => $inlineMessageId,
951
            'parse_mode' => $parseMode,
952
            'disable_web_page_preview' => $disablePreview,
953
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
954
        ]));
955
    }
956
957
    /**
958
     * Use this method to edit text messages sent by the bot or via the bot
959
     *
960
     * @param int|string $chatId
961
     * @param int $messageId
962
     * @param string|null $caption
963
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
964
     * @param string $inlineMessageId
965
     *
966
     * @return \TelegramBot\Api\Types\Message
967
     * @throws \TelegramBot\Api\InvalidArgumentException
968
     * @throws \TelegramBot\Api\Exception
969
     */
970
    public function editMessageCaption(
971
        $chatId,
972
        $messageId,
973
        $caption = null,
974
        $replyMarkup = null,
975
        $inlineMessageId = null
976
    ) {
977
        return Message::fromResponse($this->call('editMessageCaption', [
978
            'chat_id' => $chatId,
979
            'message_id' => $messageId,
980
            'inline_message_id' => $inlineMessageId,
981
            'caption' => $caption,
982
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
983
        ]));
984
    }
985
986
    /**
987
     * Use this method to edit only the reply markup of messages sent by the bot or via the bot
988
     *
989
     * @param int|string $chatId
990
     * @param int $messageId
991
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
992
     * @param string $inlineMessageId
993
     *
994
     * @return Message
995
     */
996 View Code Duplication
    public function editMessageReplyMarkup(
997
        $chatId,
998
        $messageId,
999
        $replyMarkup = null,
1000
        $inlineMessageId = null
1001
    ) {
1002
        return Message::fromResponse($this->call('editMessageReplyMarkup', [
1003
            'chat_id' => $chatId,
1004
            'message_id' => $messageId,
1005
            'inline_message_id' => $inlineMessageId,
1006
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
1007
        ]));
1008
    }
1009
1010
    /**
1011
     * Use this method to delete a message, including service messages, with the following limitations:
1012
     *  - A message can only be deleted if it was sent less than 48 hours ago.
1013
     *  - Bots can delete outgoing messages in groups and supergroups.
1014
     *  - Bots granted can_post_messages permissions can delete outgoing messages in channels.
1015
     *  - If the bot is an administrator of a group, it can delete any message there.
1016
     *  - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
1017
     *
1018
     * @param int|string $chatId
1019
     * @param int $messageId
1020
     *
1021
     * @return bool
1022
     */
1023
    public function deleteMessage($chatId, $messageId)
1024
    {
1025
        return $this->call('deleteMessage', [
1026
            'chat_id' => $chatId,
1027
            'message_id' => $messageId,
1028
        ]);
1029
    }
1030
1031
    /**
1032
     * Close curl
1033
     */
1034 9
    public function __destruct()
1035
    {
1036 9
        $this->curl && curl_close($this->curl);
1037 9
    }
1038
1039
    /**
1040
     * @return string
1041
     */
1042
    public function getUrl()
1043
    {
1044
        return self::URL_PREFIX.$this->token;
1045
    }
1046
1047
    /**
1048
     * @return string
1049
     */
1050
    public function getFileUrl()
1051
    {
1052
        return self::FILE_URL_PREFIX.$this->token;
1053
    }
1054
1055
    /**
1056
     * @param \TelegramBot\Api\Types\Update $update
1057
     * @param string $eventName
1058
     *
1059
     * @throws \TelegramBot\Api\Exception
1060
     */
1061
    public function trackUpdate(Update $update, $eventName = 'Message')
1062
    {
1063
        if (!in_array($update->getUpdateId(), $this->trackedEvents)) {
1064
            $this->trackedEvents[] = $update->getUpdateId();
1065
1066
            $this->track($update->getMessage(), $eventName);
1067
1068
            if (count($this->trackedEvents) > self::MAX_TRACKED_EVENTS) {
1069
                $this->trackedEvents = array_slice($this->trackedEvents, round(self::MAX_TRACKED_EVENTS / 4));
1070
            }
1071
        }
1072
    }
1073
1074
    /**
1075
     * Wrapper for tracker
1076
     *
1077
     * @param \TelegramBot\Api\Types\Message $message
1078
     * @param string $eventName
1079
     *
1080
     * @throws \TelegramBot\Api\Exception
1081
     */
1082
    public function track(Message $message, $eventName = 'Message')
1083
    {
1084
        if ($this->tracker instanceof Botan) {
1085
            $this->tracker->track($message, $eventName);
1086
        }
1087
    }
1088
1089
    /**
1090
     * Use this method to send invoices. On success, the sent Message is returned.
1091
     *
1092
     * @param int|string $chatId
1093
     * @param string $title
1094
     * @param string $description
1095
     * @param string $payload
1096
     * @param string $providerToken
1097
     * @param string $startParameter
1098
     * @param string $currency
1099
     * @param array $prices
1100
     * @param string|null $photoUrl
1101
     * @param int|null $photoSize
1102
     * @param int|null $photoWidth
1103
     * @param int|null $photoHeight
1104
     * @param bool $needName
1105
     * @param bool $needPhoneNumber
1106
     * @param bool $needEmail
1107
     * @param bool $needShippingAddress
1108
     * @param bool $isFlexible
1109
     * @param int|null $replyToMessageId
1110
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
1111
     * @param bool $disableNotification
1112
     *
1113
     * @return Message
1114
     */
1115
    public function sendInvoice(
1116
        $chatId,
1117
        $title,
1118
        $description,
1119
        $payload,
1120
        $providerToken,
1121
        $startParameter,
1122
        $currency,
1123
        $prices,
1124
        $isFlexible = false,
1125
        $photoUrl = null,
1126
        $photoSize = null,
1127
        $photoWidth = null,
1128
        $photoHeight = null,
1129
        $needName = false,
1130
        $needPhoneNumber = false,
1131
        $needEmail = false,
1132
        $needShippingAddress = false,
1133
        $replyToMessageId = null,
1134
        $replyMarkup = null,
1135
        $disableNotification = false
1136
    ) {
1137
        return Message::fromResponse($this->call('sendInvoice', [
1138
            'chat_id' => $chatId,
1139
            'title' => $title,
1140
            'description' => $description,
1141
            'payload' => $payload,
1142
            'provider_token' => $providerToken,
1143
            'start_parameter' => $startParameter,
1144
            'currency' => $currency,
1145
            'prices' => json_encode($prices),
1146
            'is_flexible' => $isFlexible,
1147
            'photo_url' => $photoUrl,
1148
            'photo_size' => $photoSize,
1149
            'photo_width' => $photoWidth,
1150
            'photo_height' => $photoHeight,
1151
            'need_name' => $needName,
1152
            'need_phone_number' => $needPhoneNumber,
1153
            'need_email' => $needEmail,
1154
            'need_shipping_address' => $needShippingAddress,
1155
            'reply_to_message_id' => $replyToMessageId,
1156
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
1157
            'disable_notification' => (bool)$disableNotification,
1158
        ]));
1159
    }
1160
1161
    /**
1162
     * If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API
1163
     * will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries.
1164
     * On success, True is returned.
1165
     *
1166
     * @param string $shippingQueryId
1167
     * @param bool $ok
1168
     * @param array $shipping_options
1169
     * @param null|string $errorMessage
1170
     *
1171
     * @return bool
1172
     *
1173
     */
1174
    public function answerShippingQuery($shippingQueryId, $ok = true, $shipping_options = [], $errorMessage = null)
1175
    {
1176
        return $this->call('answerShippingQuery', [
1177
            'shipping_query_id' => $shippingQueryId,
1178
            'ok' => (bool)$ok,
1179
            'shipping_options' => json_encode($shipping_options),
1180
            'error_message' => $errorMessage
1181
        ]);
1182
    }
1183
1184
    /**
1185
     * Use this method to respond to such pre-checkout queries. On success, True is returned.
1186
     * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
1187
     *
1188
     * @param string $preCheckoutQueryId
1189
     * @param bool $ok
1190
     * @param null|string $errorMessage
1191
     *
1192
     * @return mixed
1193
     */
1194
    public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMessage = null)
1195
    {
1196
        return $this->call('answerPreCheckoutQuery', [
1197
            'pre_checkout_query_id' => $preCheckoutQueryId,
1198
            'ok' => (bool)$ok,
1199
            'error_message' => $errorMessage
1200
        ]);
1201
    }
1202
1203
    /**
1204
     * Use this method to restrict a user in a supergroup.
1205
     * The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights.
1206
     * Pass True for all boolean parameters to lift restrictions from a user.
1207
     *
1208
     * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup
1209
     *                   (in the format @supergroupusername)
1210
     * @param int $userId Unique identifier of the target user
1211
     * @param null|integer $untilDate Date when restrictions will be lifted for the user, unix time.
1212
     *                     If user is restricted for more than 366 days or less than 30 seconds from the current time,
1213
     *                     they are considered to be restricted forever
1214
     * @param bool $canSendMessages Pass True, if the user can send text messages, contacts, locations and venues
1215
     * @param bool $canSendMediaMessages No Pass True, if the user can send audios, documents, photos, videos,
1216
     *                                   video notes and voice notes, implies can_send_messages
1217
     * @param bool $canSendOtherMessages Pass True, if the user can send animations, games, stickers and
1218
     *                                   use inline bots, implies can_send_media_messages
1219
     * @param bool $canAddWebPagePreviews Pass True, if the user may add web page previews to their messages,
1220
     *                                    implies can_send_media_messages
1221
     *
1222
     * @return bool
1223
     */
1224
    public function restrictChatMember(
1225
        $chatId,
1226
        $userId,
1227
        $untilDate = null,
1228
        $canSendMessages = false,
1229
        $canSendMediaMessages = false,
1230
        $canSendOtherMessages = false,
1231
        $canAddWebPagePreviews = false
1232
    ) {
1233
        return $this->call('restrictChatMember', [
1234
            'chat_id' => $chatId,
1235
            'user_id' => $userId,
1236
            'until_date' => $untilDate,
1237
            'can_send_messages' => $canSendMessages,
1238
            'can_send_media_messages' => $canSendMediaMessages,
1239
            'can_send_other_messages' => $canSendOtherMessages,
1240
            'can_add_web_page_previews' => $canAddWebPagePreviews
1241
        ]);
1242
    }
1243
1244
    /**
1245
     * Use this method to promote or demote a user in a supergroup or a channel.
1246
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1247
     * Pass False for all boolean parameters to demote a user.
1248
     *
1249
     * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup
1250
     *                   (in the format @supergroupusername)
1251
     * @param int $userId Unique identifier of the target user
1252
     * @param bool $canChangeInfo Pass True, if the administrator can change chat title, photo and other settings
1253
     * @param bool $canPostMessages Pass True, if the administrator can create channel posts, channels only
1254
     * @param bool $canEditMessages Pass True, if the administrator can edit messages of other users, channels only
1255
     * @param bool $canDeleteMessages Pass True, if the administrator can delete messages of other users
1256
     * @param bool $canInviteUsers Pass True, if the administrator can invite new users to the chat
1257
     * @param bool $canRestrictMembers Pass True, if the administrator can restrict, ban or unban chat members
1258
     * @param bool $canPinMessages Pass True, if the administrator can pin messages, supergroups only
1259
     * @param bool $canPromoteMembers Pass True, if the administrator can add new administrators with a subset of his
1260
     *                                own privileges or demote administrators that he has promoted,directly or
1261
     *                                indirectly (promoted by administrators that were appointed by him)
1262
     *
1263
     * @return bool
1264
     */
1265
    public function promoteChatMember(
1266
        $chatId,
1267
        $userId,
1268
        $canChangeInfo = true,
1269
        $canPostMessages = true,
1270
        $canEditMessages = true,
1271
        $canDeleteMessages = true,
1272
        $canInviteUsers = true,
1273
        $canRestrictMembers = true,
1274
        $canPinMessages = true,
1275
        $canPromoteMembers = true
1276
    ) {
1277
        return $this->call('promoteChatMember', [
1278
            'chat_id' => $chatId,
1279
            'user_id' => $userId,
1280
            'can_change_info' => $canChangeInfo,
1281
            'can_post_messages' => $canPostMessages,
1282
            'can_edit_messages' => $canEditMessages,
1283
            'can_delete_messages' => $canDeleteMessages,
1284
            'can_invite_users' => $canInviteUsers,
1285
            'can_restrict_members' => $canRestrictMembers,
1286
            'can_pin_messages' => $canPinMessages,
1287
            'can_promote_members' => $canPromoteMembers
1288
        ]);
1289
    }
1290
1291
    /**
1292
     * Use this method to export an invite link to a supergroup or a channel.
1293
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1294
     *
1295
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1296
     *                           (in the format @channelusername)
1297
     * @return string
1298
     */
1299
    public function exportChatInviteLink($chatId)
1300
    {
1301
        return $this->call('exportChatInviteLink', [
1302
            'chat_id' => $chatId
1303
        ]);
1304
    }
1305
1306
    /**
1307
     * Use this method to set a new profile photo for the chat. Photos can't be changed for private chats.
1308
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1309
     *
1310
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1311
     *                           (in the format @channelusername)
1312
     * @param \CURLFile|string $photo New chat photo, uploaded using multipart/form-data
1313
     *
1314
     * @return bool
1315
     */
1316
    public function setChatPhoto($chatId, $photo)
1317
    {
1318
        return $this->call('setChatPhoto', [
1319
            'chat_id' => $chatId,
1320
            'photo' => $photo
1321
        ]);
1322
    }
1323
1324
    /**
1325
     * Use this method to delete a chat photo. Photos can't be changed for private chats.
1326
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1327
     *
1328
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1329
     *                           (in the format @channelusername)
1330
     *
1331
     * @return bool
1332
     */
1333
    public function deleteChatPhoto($chatId)
1334
    {
1335
        return $this->call('deleteChatPhoto', [
1336
            'chat_id' => $chatId
1337
        ]);
1338
    }
1339
1340
    /**
1341
     * Use this method to change the title of a chat. Titles can't be changed for private chats.
1342
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1343
     *
1344
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1345
     *                           (in the format @channelusername)
1346
     * @param string $title New chat title, 1-255 characters
1347
     *
1348
     * @return bool
1349
     */
1350
    public function setChatTitle($chatId, $title)
1351
    {
1352
        return $this->call('setChatTitle', [
1353
            'chat_id' => $chatId,
1354
            'title' => $title
1355
        ]);
1356
    }
1357
1358
    /**
1359
     * Use this method to change the description of a supergroup or a channel.
1360
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1361
     *
1362
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1363
     *                   (in the format @channelusername)
1364
     * @param string|null $description New chat description, 0-255 characters
1365
     *
1366
     * @return bool
1367
     */
1368
    public function setChatDescription($chatId, $description = null)
1369
    {
1370
        return $this->call('setChatDescription', [
1371
            'chat_id' => $chatId,
1372
            'title' => $description
1373
        ]);
1374
    }
1375
1376
    /**
1377
     * Use this method to pin a message in a supergroup.
1378
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1379
     *
1380
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1381
     *                   (in the format @channelusername)
1382
     * @param int $messageId Identifier of a message to pin
1383
     * @param bool $disableNotification
1384
     *
1385
     * @return bool
1386
     */
1387
    public function pinChatMessage($chatId, $messageId, $disableNotification = false)
1388
    {
1389
        return $this->call('pinChatMessage', [
1390
            'chat_id' => $chatId,
1391
            'message_id' => $messageId,
1392
            'disable_notification' => $disableNotification
1393
        ]);
1394
    }
1395
1396
    /**
1397
     * Use this method to unpin a message in a supergroup chat.
1398
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1399
     *
1400
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1401
     *                   (in the format @channelusername)
1402
     *
1403
     * @return bool
1404
     */
1405
    public function unpinChatMessage($chatId)
1406
    {
1407
        return $this->call('unpinChatMessage', [
1408
            'chat_id' => $chatId
1409
        ]);
1410
    }
1411
1412
    /**
1413
     * Use this method to get up to date information about the chat
1414
     * (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).
1415
     *
1416
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1417
     *                   (in the format @channelusername)
1418
     *
1419
     * @return Chat
1420
     */
1421
    public function getChat($chatId)
1422
    {
1423
        return Chat::fromResponse($this->call('getChat', [
1424
            'chat_id' => $chatId
1425
        ]));
1426
    }
1427
1428
    /**
1429
     * Use this method to get information about a member of a chat.
1430
     *
1431
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1432
     *                   (in the format @channelusername)
1433
     * @param int $userId
1434
     *
1435
     * @return ChatMember
1436
     */
1437
    public function getChatMember($chatId, $userId)
1438
    {
1439
        return ChatMember::fromResponse($this->call('getChatMember', [
1440
            'chat_id' => $chatId,
1441
            'user_id' => $userId
1442
        ]));
1443
    }
1444
1445
    /**
1446
     * Use this method for your bot to leave a group, supergroup or channel.
1447
     *
1448
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1449
     *                   (in the format @channelusername)
1450
     *
1451
     * @return bool
1452
     */
1453
    public function leaveChat($chatId)
1454
    {
1455
        return $this->call('leaveChat', [
1456
            'chat_id' => $chatId
1457
        ]);
1458
    }
1459
}
1460