Passed
Pull Request — master (#86)
by
unknown
02:19
created

BotApi::promoteChatMember()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 12
cp 0
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 22
nc 1
nop 10
crap 2

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($inlineQueryId, $results, $cacheTime = 300, $isPersonal = false, $nextOffset = '', $switchPmText = null, $switchPmParameter = null)
838
    {
839
        $results = array_map(function ($item) {
840
            /* @var AbstractInlineQueryResult $item */
841
842
            return json_decode($item->toJson(), true);
843
        }, $results);
844
845
        return $this->call('answerInlineQuery', [
846
            'inline_query_id' => $inlineQueryId,
847
            'results' => json_encode($results),
848
            'cache_time' => $cacheTime,
849
            'is_personal' => $isPersonal,
850
            'next_offset' => $nextOffset,
851
            'switch_pm_text' => $switchPmText,
852
            'switch_pm_parameter' => $switchPmParameter,
853
        ]);
854
    }
855
856
    /**
857
     * Use this method to kick a user from a group or a supergroup.
858
     * In the case of supergroups, the user will not be able to return to the group
859
     * on their own using invite links, etc., unless unbanned first.
860
     * The bot must be an administrator in the group for this to work. Returns True on success.
861
     *
862
     * @param int|string $chatId Unique identifier for the target group
863
     * or username of the target supergroup (in the format @supergroupusername)
864
     * @param int $userId Unique identifier of the target user
865
     * @param null|int $untilDate Date when the user will be unbanned, unix time.
866
     *                            If user is banned for more than 366 days or less than 30 seconds from the current time
867
     *                            they are considered to be banned forever
868
     *
869
     * @return bool
870
     */
871
    public function kickChatMember($chatId, $userId, $untilDate = null)
872
    {
873
        return $this->call('kickChatMember', [
874
            'chat_id' => $chatId,
875
            'user_id' => $userId,
876
            'until_date' => $untilDate
877
        ]);
878
    }
879
880
    /**
881
     * Use this method to unban a previously kicked user in a supergroup.
882
     * The user will not return to the group automatically, but will be able to join via link, etc.
883
     * The bot must be an administrator in the group for this to work. Returns True on success.
884
     *
885
     * @param int|string $chatId Unique identifier for the target group
886
     * or username of the target supergroup (in the format @supergroupusername)
887
     * @param int $userId Unique identifier of the target user
888
     *
889
     * @return bool
890
     */
891
    public function unbanChatMember($chatId, $userId)
892
    {
893
        return $this->call('unbanChatMember', [
894
            'chat_id' => $chatId,
895
            'user_id' => $userId,
896
        ]);
897
    }
898
899
    /**
900
     * Use this method to send answers to callback queries sent from inline keyboards.
901
     * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.
902
     *
903
     * @param $callbackQueryId
904
     * @param null $text
905
     * @param bool $showAlert
906
     *
907
     * @return bool
908
     */
909
    public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = false)
910
    {
911
        return $this->call('answerCallbackQuery', [
912
            'callback_query_id' => $callbackQueryId,
913
            'text' => $text,
914
            'show_alert' => (bool)$showAlert,
915
        ]);
916
    }
917
918
919
    /**
920
     * Use this method to edit text messages sent by the bot or via the bot
921
     *
922
     * @param int|string $chatId
923
     * @param int $messageId
924
     * @param string $text
925
     * @param string $inlineMessageId
926
     * @param string|null $parseMode
927
     * @param bool $disablePreview
928
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
929
     * @return Message
930
     */
931 View Code Duplication
    public function editMessageText(
932
        $chatId,
933
        $messageId,
934
        $text,
935
        $parseMode = null,
936
        $disablePreview = false,
937
        $replyMarkup = null,
938
        $inlineMessageId = null
939
    ) {
940
        return Message::fromResponse($this->call('editMessageText', [
941
            'chat_id' => $chatId,
942
            'message_id' => $messageId,
943
            'text' => $text,
944
            'inline_message_id' => $inlineMessageId,
945
            'parse_mode' => $parseMode,
946
            'disable_web_page_preview' => $disablePreview,
947
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
948
        ]));
949
    }
950
951
    /**
952
     * Use this method to edit text messages sent by the bot or via the bot
953
     *
954
     * @param int|string $chatId
955
     * @param int $messageId
956
     * @param string|null $caption
957
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
958
     * @param string $inlineMessageId
959
     *
960
     * @return \TelegramBot\Api\Types\Message
961
     * @throws \TelegramBot\Api\InvalidArgumentException
962
     * @throws \TelegramBot\Api\Exception
963
     */
964
    public function editMessageCaption(
965
        $chatId,
966
        $messageId,
967
        $caption = null,
968
        $replyMarkup = null,
969
        $inlineMessageId = null
970
    ) {
971
        return Message::fromResponse($this->call('editMessageCaption', [
972
            'chat_id' => $chatId,
973
            'message_id' => $messageId,
974
            'inline_message_id' => $inlineMessageId,
975
            'caption' => $caption,
976
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
977
        ]));
978
    }
979
980
    /**
981
     * Use this method to edit only the reply markup of messages sent by the bot or via the bot
982
     *
983
     * @param int|string $chatId
984
     * @param int $messageId
985
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
986
     * @param string $inlineMessageId
987
     *
988
     * @return Message
989
     */
990 View Code Duplication
    public function editMessageReplyMarkup(
991
        $chatId,
992
        $messageId,
993
        $replyMarkup = null,
994
        $inlineMessageId = null
995
    ) {
996
        return Message::fromResponse($this->call('editMessageReplyMarkup', [
997
            'chat_id' => $chatId,
998
            'message_id' => $messageId,
999
            'inline_message_id' => $inlineMessageId,
1000
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
1001
        ]));
1002
    }
1003
1004
    /**
1005
     * Use this method to delete a message, including service messages, with the following limitations:
1006
     *  - A message can only be deleted if it was sent less than 48 hours ago.
1007
     *  - Bots can delete outgoing messages in groups and supergroups.
1008
     *  - Bots granted can_post_messages permissions can delete outgoing messages in channels.
1009
     *  - If the bot is an administrator of a group, it can delete any message there.
1010
     *  - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
1011
     *
1012
     * @param int|string $chatId
1013
     * @param int $messageId
1014
     *
1015
     * @return bool
1016
     */
1017
    public function deleteMessage($chatId, $messageId)
1018
    {
1019
        return $this->call('deleteMessage', [
1020
            'chat_id' => $chatId,
1021
            'message_id' => $messageId,
1022
        ]);
1023
    }
1024
1025
    /**
1026
     * Close curl
1027
     */
1028 9
    public function __destruct()
1029
    {
1030 9
        $this->curl && curl_close($this->curl);
1031 9
    }
1032
1033
    /**
1034
     * @return string
1035
     */
1036
    public function getUrl()
1037
    {
1038
        return self::URL_PREFIX.$this->token;
1039
    }
1040
1041
    /**
1042
     * @return string
1043
     */
1044
    public function getFileUrl()
1045
    {
1046
        return self::FILE_URL_PREFIX.$this->token;
1047
    }
1048
1049
    /**
1050
     * @param \TelegramBot\Api\Types\Update $update
1051
     * @param string $eventName
1052
     *
1053
     * @throws \TelegramBot\Api\Exception
1054
     */
1055
    public function trackUpdate(Update $update, $eventName = 'Message')
1056
    {
1057
        if (!in_array($update->getUpdateId(), $this->trackedEvents)) {
1058
            $this->trackedEvents[] = $update->getUpdateId();
1059
1060
            $this->track($update->getMessage(), $eventName);
1061
1062
            if (count($this->trackedEvents) > self::MAX_TRACKED_EVENTS) {
1063
                $this->trackedEvents = array_slice($this->trackedEvents, round(self::MAX_TRACKED_EVENTS / 4));
1064
            }
1065
        }
1066
    }
1067
1068
    /**
1069
     * Wrapper for tracker
1070
     *
1071
     * @param \TelegramBot\Api\Types\Message $message
1072
     * @param string $eventName
1073
     *
1074
     * @throws \TelegramBot\Api\Exception
1075
     */
1076
    public function track(Message $message, $eventName = 'Message')
1077
    {
1078
        if ($this->tracker instanceof Botan) {
1079
            $this->tracker->track($message, $eventName);
1080
        }
1081
    }
1082
1083
    /**
1084
     * Use this method to send invoices. On success, the sent Message is returned.
1085
     *
1086
     * @param int|string $chatId
1087
     * @param string $title
1088
     * @param string $description
1089
     * @param string $payload
1090
     * @param string $providerToken
1091
     * @param string $startParameter
1092
     * @param string $currency
1093
     * @param array $prices
1094
     * @param string|null $photoUrl
1095
     * @param int|null $photoSize
1096
     * @param int|null $photoWidth
1097
     * @param int|null $photoHeight
1098
     * @param bool $needName
1099
     * @param bool $needPhoneNumber
1100
     * @param bool $needEmail
1101
     * @param bool $needShippingAddress
1102
     * @param bool $isFlexible
1103
     * @param int|null $replyToMessageId
1104
     * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup
1105
     * @param bool $disableNotification
1106
     *
1107
     * @return Message
1108
     */
1109
    public function sendInvoice(
1110
        $chatId,
1111
        $title,
1112
        $description,
1113
        $payload,
1114
        $providerToken,
1115
        $startParameter,
1116
        $currency,
1117
        $prices,
1118
        $isFlexible = false,
1119
        $photoUrl = null,
1120
        $photoSize = null,
1121
        $photoWidth = null,
1122
        $photoHeight = null,
1123
        $needName = false,
1124
        $needPhoneNumber = false,
1125
        $needEmail = false,
1126
        $needShippingAddress = false,
1127
        $replyToMessageId = null,
1128
        $replyMarkup = null,
1129
        $disableNotification = false
1130
    ) {
1131
        return Message::fromResponse($this->call('sendInvoice', [
1132
            'chat_id' => $chatId,
1133
            'title' => $title,
1134
            'description' => $description,
1135
            'payload' => $payload,
1136
            'provider_token' => $providerToken,
1137
            'start_parameter' => $startParameter,
1138
            'currency' => $currency,
1139
            'prices' => json_encode($prices),
1140
            'is_flexible' => $isFlexible,
1141
            'photo_url' => $photoUrl,
1142
            'photo_size' => $photoSize,
1143
            'photo_width' => $photoWidth,
1144
            'photo_height' => $photoHeight,
1145
            'need_name' => $needName,
1146
            'need_phone_number' => $needPhoneNumber,
1147
            'need_email' => $needEmail,
1148
            'need_shipping_address' => $needShippingAddress,
1149
            'reply_to_message_id' => $replyToMessageId,
1150
            'reply_markup' => is_null($replyMarkup) ? $replyMarkup : $replyMarkup->toJson(),
1151
            'disable_notification' => (bool)$disableNotification,
1152
        ]));
1153
    }
1154
1155
    /**
1156
     * If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API
1157
     * will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries.
1158
     * On success, True is returned.
1159
     *
1160
     * @param string $shippingQueryId
1161
     * @param bool $ok
1162
     * @param array $shipping_options
1163
     * @param null|string $errorMessage
1164
     *
1165
     * @return bool
1166
     *
1167
     */
1168
    public function answerShippingQuery($shippingQueryId, $ok = true, $shipping_options = [], $errorMessage = null)
1169
    {
1170
        return $this->call('answerShippingQuery', [
1171
            'shipping_query_id' => $shippingQueryId,
1172
            'ok' => (bool)$ok,
1173
            'shipping_options' => json_encode($shipping_options),
1174
            'error_message' => $errorMessage
1175
        ]);
1176
    }
1177
1178
    /**
1179
     * Use this method to respond to such pre-checkout queries. On success, True is returned.
1180
     * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
1181
     *
1182
     * @param string $preCheckoutQueryId
1183
     * @param bool $ok
1184
     * @param null|string $errorMessage
1185
     *
1186
     * @return mixed
1187
     */
1188
    public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMessage = null)
1189
    {
1190
        return $this->call('answerPreCheckoutQuery', [
1191
            'pre_checkout_query_id' => $preCheckoutQueryId,
1192
            'ok' => (bool)$ok,
1193
            'error_message' => $errorMessage
1194
        ]);
1195
    }
1196
1197
    /**
1198
     * Use this method to restrict a user in a supergroup.
1199
     * The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights.
1200
     * Pass True for all boolean parameters to lift restrictions from a user.
1201
     *
1202
     * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup
1203
     *                   (in the format @supergroupusername)
1204
     * @param int $userId Unique identifier of the target user
1205
     * @param null|integer $untilDate Date when restrictions will be lifted for the user, unix time.
1206
     *                     If user is restricted for more than 366 days or less than 30 seconds from the current time,
1207
     *                     they are considered to be restricted forever
1208
     * @param bool $canSendMessages Pass True, if the user can send text messages, contacts, locations and venues
1209
     * @param bool $canSendMediaMessages No Pass True, if the user can send audios, documents, photos, videos,
1210
     *                                   video notes and voice notes, implies can_send_messages
1211
     * @param bool $canSendOtherMessages Pass True, if the user can send animations, games, stickers and
1212
     *                                   use inline bots, implies can_send_media_messages
1213
     * @param bool $canAddWebPagePreviews Pass True, if the user may add web page previews to their messages,
1214
     *                                    implies can_send_media_messages
1215
     *
1216
     * @return bool
1217
     */
1218
    public function restrictChatMember(
1219
        $chatId,
1220
        $userId,
1221
        $untilDate = null,
1222
        $canSendMessages = false,
1223
        $canSendMediaMessages = false,
1224
        $canSendOtherMessages = false,
1225
        $canAddWebPagePreviews = false
1226
    ) {
1227
        return $this->call('restrictChatMember', [
1228
            'chat_id' => $chatId,
1229
            'user_id' => $userId,
1230
            'until_date' => $untilDate,
1231
            'can_send_messages' => $canSendMessages,
1232
            'can_send_media_messages' => $canSendMediaMessages,
1233
            'can_send_other_messages' => $canSendOtherMessages,
1234
            'can_add_web_page_previews' => $canAddWebPagePreviews
1235
        ]);
1236
    }
1237
1238
    /**
1239
     * Use this method to promote or demote a user in a supergroup or a channel.
1240
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1241
     * Pass False for all boolean parameters to demote a user.
1242
     *
1243
     * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup
1244
     *                   (in the format @supergroupusername)
1245
     * @param int $userId Unique identifier of the target user
1246
     * @param bool $canChangeInfo Pass True, if the administrator can change chat title, photo and other settings
1247
     * @param bool $canPostMessages Pass True, if the administrator can create channel posts, channels only
1248
     * @param bool $canEditMessages Pass True, if the administrator can edit messages of other users, channels only
1249
     * @param bool $canDeleteMessages Pass True, if the administrator can delete messages of other users
1250
     * @param bool $canInviteUsers Pass True, if the administrator can invite new users to the chat
1251
     * @param bool $canRestrictMembers Pass True, if the administrator can restrict, ban or unban chat members
1252
     * @param bool $canPinMessages Pass True, if the administrator can pin messages, supergroups only
1253
     * @param bool $canPromoteMembers Pass True, if the administrator can add new administrators with a subset of his
1254
     *                                own privileges or demote administrators that he has promoted,directly or
1255
     *                                indirectly (promoted by administrators that were appointed by him)
1256
     *
1257
     * @return bool
1258
     */
1259
    public function promoteChatMember(
1260
        $chatId,
1261
        $userId,
1262
        $canChangeInfo = true,
1263
        $canPostMessages = true,
1264
        $canEditMessages = true,
1265
        $canDeleteMessages = true,
1266
        $canInviteUsers = true,
1267
        $canRestrictMembers = true,
1268
        $canPinMessages = true,
1269
        $canPromoteMembers = true
1270
    ) {
1271
        return $this->call('promoteChatMember', [
1272
            'chat_id' => $chatId,
1273
            'user_id' => $userId,
1274
            'can_change_info' => $canChangeInfo,
1275
            'can_post_messages' => $canPostMessages,
1276
            'can_edit_messages' => $canEditMessages,
1277
            'can_delete_messages' => $canDeleteMessages,
1278
            'can_invite_users' => $canInviteUsers,
1279
            'can_restrict_members' => $canRestrictMembers,
1280
            'can_pin_messages' => $canPinMessages,
1281
            'can_promote_members' => $canPromoteMembers
1282
        ]);
1283
    }
1284
1285
    /**
1286
     * Use this method to export an invite link to a supergroup or a channel.
1287
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1288
     *
1289
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1290
     *                           (in the format @channelusername)
1291
     * @return string
1292
     */
1293
    public function exportChatInviteLink($chatId)
1294
    {
1295
        return $this->call('exportChatInviteLink', [
1296
            'chat_id' => $chatId
1297
        ]);
1298
    }
1299
1300
    /**
1301
     * Use this method to set a new profile photo for the chat. Photos can't be changed for private chats.
1302
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1303
     *
1304
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1305
     *                           (in the format @channelusername)
1306
     * @param \CURLFile|string $photo New chat photo, uploaded using multipart/form-data
1307
     *
1308
     * @return bool
1309
     */
1310
    public function setChatPhoto($chatId, $photo)
1311
    {
1312
        return $this->call('setChatPhoto', [
1313
            'chat_id' => $chatId,
1314
            'photo' => $photo
1315
        ]);
1316
    }
1317
1318
    /**
1319
     * Use this method to delete a chat photo. Photos can't be changed for private chats.
1320
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1321
     *
1322
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1323
     *                           (in the format @channelusername)
1324
     *
1325
     * @return bool
1326
     */
1327
    public function deleteChatPhoto($chatId)
1328
    {
1329
        return $this->call('deleteChatPhoto', [
1330
            'chat_id' => $chatId
1331
        ]);
1332
    }
1333
1334
    /**
1335
     * Use this method to change the title of a chat. Titles can't be changed for private chats.
1336
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1337
     *
1338
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1339
     *                           (in the format @channelusername)
1340
     * @param string $title New chat title, 1-255 characters
1341
     *
1342
     * @return bool
1343
     */
1344
    public function setChatTitle($chatId, $title)
1345
    {
1346
        return $this->call('setChatTitle', [
1347
            'chat_id' => $chatId,
1348
            'title' => $title
1349
        ]);
1350
    }
1351
1352
    /**
1353
     * Use this method to change the description of a supergroup or a channel.
1354
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1355
     *
1356
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1357
     *                   (in the format @channelusername)
1358
     * @param string|null $description New chat description, 0-255 characters
1359
     *
1360
     * @return bool
1361
     */
1362
    public function setChatDescription($chatId, $description = null)
1363
    {
1364
        return $this->call('setChatDescription', [
1365
            'chat_id' => $chatId,
1366
            'title' => $description
1367
        ]);
1368
    }
1369
1370
    /**
1371
     * Use this method to pin a message in a supergroup.
1372
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1373
     *
1374
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1375
     *                   (in the format @channelusername)
1376
     * @param int $messageId Identifier of a message to pin
1377
     * @param bool $disableNotification
1378
     *
1379
     * @return bool
1380
     */
1381
    public function pinChatMessage($chatId, $messageId, $disableNotification = false)
1382
    {
1383
        return $this->call('pinChatMessage', [
1384
            'chat_id' => $chatId,
1385
            'message_id' => $messageId,
1386
            'disable_notification' => $disableNotification
1387
        ]);
1388
    }
1389
1390
    /**
1391
     * Use this method to unpin a message in a supergroup chat.
1392
     * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
1393
     *
1394
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1395
     *                   (in the format @channelusername)
1396
     *
1397
     * @return bool
1398
     */
1399
    public function unpinChatMessage($chatId)
1400
    {
1401
        return $this->call('unpinChatMessage', [
1402
            'chat_id' => $chatId
1403
        ]);
1404
    }
1405
1406
    /**
1407
     * Use this method to get up to date information about the chat
1408
     * (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).
1409
     *
1410
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1411
     *                   (in the format @channelusername)
1412
     *
1413
     * @return Chat
1414
     */
1415
    public function getChat($chatId)
1416
    {
1417
        return Chat::fromResponse($this->call('getChat', [
1418
            'chat_id' => $chatId
1419
        ]));
1420
    }
1421
1422
    /**
1423
     * Use this method to get information about a member of a chat.
1424
     *
1425
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1426
     *                   (in the format @channelusername)
1427
     * @param int $userId
1428
     *
1429
     * @return ChatMember
1430
     */
1431
    public function getChatMember($chatId, $userId)
1432
    {
1433
        return ChatMember::fromResponse($this->call('getChatMember', [
1434
            'chat_id' => $chatId,
1435
            'user_id' => $userId
1436
        ]));
1437
    }
1438
1439
    /**
1440
     * Use this method for your bot to leave a group, supergroup or channel.
1441
     *
1442
     * @param string|int $chatId Unique identifier for the target chat or username of the target channel
1443
     *                   (in the format @channelusername)
1444
     *
1445
     * @return bool
1446
     */
1447
    public function leaveChat($chatId)
1448
    {
1449
        return $this->call('leaveChat', [
1450
            'chat_id' => $chatId
1451
        ]);
1452
    }
1453
}
1454