Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like BotApi often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use BotApi, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
23 | class BotApi |
||
24 | { |
||
25 | /** |
||
26 | * HTTP codes |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | public static $codes = [ |
||
31 | // Informational 1xx |
||
32 | 100 => 'Continue', |
||
33 | 101 => 'Switching Protocols', |
||
34 | 102 => 'Processing', // RFC2518 |
||
35 | // Success 2xx |
||
36 | 200 => 'OK', |
||
37 | 201 => 'Created', |
||
38 | 202 => 'Accepted', |
||
39 | 203 => 'Non-Authoritative Information', |
||
40 | 204 => 'No Content', |
||
41 | 205 => 'Reset Content', |
||
42 | 206 => 'Partial Content', |
||
43 | 207 => 'Multi-Status', // RFC4918 |
||
44 | 208 => 'Already Reported', // RFC5842 |
||
45 | 226 => 'IM Used', // RFC3229 |
||
46 | // Redirection 3xx |
||
47 | 300 => 'Multiple Choices', |
||
48 | 301 => 'Moved Permanently', |
||
49 | 302 => 'Found', // 1.1 |
||
50 | 303 => 'See Other', |
||
51 | 304 => 'Not Modified', |
||
52 | 305 => 'Use Proxy', |
||
53 | // 306 is deprecated but reserved |
||
54 | 307 => 'Temporary Redirect', |
||
55 | 308 => 'Permanent Redirect', // RFC7238 |
||
56 | // Client Error 4xx |
||
57 | 400 => 'Bad Request', |
||
58 | 401 => 'Unauthorized', |
||
59 | 402 => 'Payment Required', |
||
60 | 403 => 'Forbidden', |
||
61 | 404 => 'Not Found', |
||
62 | 405 => 'Method Not Allowed', |
||
63 | 406 => 'Not Acceptable', |
||
64 | 407 => 'Proxy Authentication Required', |
||
65 | 408 => 'Request Timeout', |
||
66 | 409 => 'Conflict', |
||
67 | 410 => 'Gone', |
||
68 | 411 => 'Length Required', |
||
69 | 412 => 'Precondition Failed', |
||
70 | 413 => 'Payload Too Large', |
||
71 | 414 => 'URI Too Long', |
||
72 | 415 => 'Unsupported Media Type', |
||
73 | 416 => 'Range Not Satisfiable', |
||
74 | 417 => 'Expectation Failed', |
||
75 | 422 => 'Unprocessable Entity', // RFC4918 |
||
76 | 423 => 'Locked', // RFC4918 |
||
77 | 424 => 'Failed Dependency', // RFC4918 |
||
78 | 425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817 |
||
79 | 426 => 'Upgrade Required', // RFC2817 |
||
80 | 428 => 'Precondition Required', // RFC6585 |
||
81 | 429 => 'Too Many Requests', // RFC6585 |
||
82 | 431 => 'Request Header Fields Too Large', // RFC6585 |
||
83 | // Server Error 5xx |
||
84 | 500 => 'Internal Server Error', |
||
85 | 501 => 'Not Implemented', |
||
86 | 502 => 'Bad Gateway', |
||
87 | 503 => 'Service Unavailable', |
||
88 | 504 => 'Gateway Timeout', |
||
89 | 505 => 'HTTP Version Not Supported', |
||
90 | 506 => 'Variant Also Negotiates (Experimental)', // RFC2295 |
||
91 | 507 => 'Insufficient Storage', // RFC4918 |
||
92 | 508 => 'Loop Detected', // RFC5842 |
||
93 | 510 => 'Not Extended', // RFC2774 |
||
94 | 511 => 'Network Authentication Required', // RFC6585 |
||
95 | ]; |
||
96 | |||
97 | private $proxySettings = []; |
||
98 | |||
99 | /** |
||
100 | * Default http status code |
||
101 | */ |
||
102 | const DEFAULT_STATUS_CODE = 200; |
||
103 | |||
104 | /** |
||
105 | * Not Modified http status code |
||
106 | */ |
||
107 | const NOT_MODIFIED_STATUS_CODE = 304; |
||
108 | |||
109 | /** |
||
110 | * Limits for tracked ids |
||
111 | */ |
||
112 | const MAX_TRACKED_EVENTS = 200; |
||
113 | |||
114 | /** |
||
115 | * Url prefixes |
||
116 | */ |
||
117 | const URL_PREFIX = 'https://api.telegram.org/bot'; |
||
118 | |||
119 | /** |
||
120 | * Url prefix for files |
||
121 | */ |
||
122 | const FILE_URL_PREFIX = 'https://api.telegram.org/file/bot'; |
||
123 | |||
124 | /** |
||
125 | * CURL object |
||
126 | * |
||
127 | * @var |
||
128 | */ |
||
129 | protected $curl; |
||
130 | |||
131 | /** |
||
132 | * CURL custom options |
||
133 | * |
||
134 | * @var array |
||
135 | */ |
||
136 | protected $customCurlOptions = []; |
||
137 | |||
138 | /** |
||
139 | * Bot token |
||
140 | * |
||
141 | * @var string |
||
142 | */ |
||
143 | protected $token; |
||
144 | |||
145 | /** |
||
146 | * Botan tracker |
||
147 | * |
||
148 | * @var \TelegramBot\Api\Botan |
||
149 | */ |
||
150 | protected $tracker; |
||
151 | |||
152 | /** |
||
153 | * list of event ids |
||
154 | * |
||
155 | * @var array |
||
156 | */ |
||
157 | protected $trackedEvents = []; |
||
158 | |||
159 | /** |
||
160 | * Check whether return associative array |
||
161 | * |
||
162 | * @var bool |
||
163 | */ |
||
164 | protected $returnArray = true; |
||
165 | |||
166 | /** |
||
167 | * Constructor |
||
168 | * |
||
169 | * @param string $token Telegram Bot API token |
||
170 | * @param string|null $trackerToken Yandex AppMetrica application api_key |
||
171 | */ |
||
172 | 9 | public function __construct($token, $trackerToken = null) |
|
181 | |||
182 | /** |
||
183 | * Set return array |
||
184 | * |
||
185 | * @param bool $mode |
||
186 | * |
||
187 | * @return $this |
||
188 | */ |
||
189 | public function setModeObject($mode = true) |
||
195 | |||
196 | |||
197 | /** |
||
198 | * Call method |
||
199 | * |
||
200 | * @param string $method |
||
201 | * @param array|null $data |
||
202 | * |
||
203 | * @return mixed |
||
204 | * @throws \TelegramBot\Api\Exception |
||
205 | * @throws \TelegramBot\Api\HttpException |
||
206 | * @throws \TelegramBot\Api\InvalidJsonException |
||
207 | */ |
||
208 | public function call($method, array $data = null) |
||
243 | |||
244 | /** |
||
245 | * curl_exec wrapper for response validation |
||
246 | * |
||
247 | * @param array $options |
||
248 | * |
||
249 | * @return string |
||
250 | * |
||
251 | * @throws \TelegramBot\Api\HttpException |
||
252 | */ |
||
253 | protected function executeCurl(array $options) |
||
265 | |||
266 | /** |
||
267 | * Response validation |
||
268 | * |
||
269 | * @param resource $curl |
||
270 | * @param string $response |
||
271 | * @throws HttpException |
||
272 | */ |
||
273 | public static function curlValidate($curl, $response = null) |
||
284 | |||
285 | /** |
||
286 | * JSON validation |
||
287 | * |
||
288 | * @param string $jsonString |
||
289 | * @param boolean $asArray |
||
290 | * |
||
291 | * @return object|array |
||
292 | * @throws \TelegramBot\Api\InvalidJsonException |
||
293 | */ |
||
294 | public static function jsonValidate($jsonString, $asArray) |
||
304 | |||
305 | /** |
||
306 | * Use this method to send text messages. On success, the sent \TelegramBot\Api\Types\Message is returned. |
||
307 | * |
||
308 | * @param int|string $chatId |
||
309 | * @param string $text |
||
310 | * @param string|null $parseMode |
||
311 | * @param bool $disablePreview |
||
312 | * @param int|null $replyToMessageId |
||
313 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
314 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
315 | * @param bool $disableNotification |
||
316 | * |
||
317 | * @return \TelegramBot\Api\Types\Message |
||
318 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
319 | * @throws \TelegramBot\Api\Exception |
||
320 | */ |
||
321 | View Code Duplication | public function sendMessage( |
|
340 | |||
341 | /** |
||
342 | * Use this method to send phone contacts |
||
343 | * |
||
344 | * @param int|string $chatId chat_id or @channel_name |
||
345 | * @param string $phoneNumber |
||
346 | * @param string $firstName |
||
347 | * @param string $lastName |
||
348 | * @param int|null $replyToMessageId |
||
349 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
350 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
351 | * @param bool $disableNotification |
||
352 | * |
||
353 | * @return \TelegramBot\Api\Types\Message |
||
354 | * @throws \TelegramBot\Api\Exception |
||
355 | */ |
||
356 | View Code Duplication | public function sendContact( |
|
375 | |||
376 | /** |
||
377 | * Use this method when you need to tell the user that something is happening on the bot's side. |
||
378 | * The status is set for 5 seconds or less (when a message arrives from your bot, |
||
379 | * Telegram clients clear its typing status). |
||
380 | * |
||
381 | * We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive. |
||
382 | * |
||
383 | * Type of action to broadcast. Choose one, depending on what the user is about to receive: |
||
384 | * `typing` for text messages, `upload_photo` for photos, `record_video` or `upload_video` for videos, |
||
385 | * `record_audio` or upload_audio for audio files, `upload_document` for general files, |
||
386 | * `find_location` for location data. |
||
387 | * |
||
388 | * @param int $chatId |
||
389 | * @param string $action |
||
390 | * |
||
391 | * @return bool |
||
392 | * @throws \TelegramBot\Api\Exception |
||
393 | */ |
||
394 | public function sendChatAction($chatId, $action) |
||
401 | |||
402 | /** |
||
403 | * Use this method to get a list of profile pictures for a user. |
||
404 | * |
||
405 | * @param int $userId |
||
406 | * @param int $offset |
||
407 | * @param int $limit |
||
408 | * |
||
409 | * @return \TelegramBot\Api\Types\UserProfilePhotos |
||
410 | * @throws \TelegramBot\Api\Exception |
||
411 | */ |
||
412 | public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) |
||
420 | |||
421 | /** |
||
422 | * Use this method to specify a url and receive incoming updates via an outgoing webhook. |
||
423 | * Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, |
||
424 | * containing a JSON-serialized Update. |
||
425 | * In case of an unsuccessful request, we will give up after a reasonable amount of attempts. |
||
426 | * |
||
427 | * @param string $url HTTPS url to send updates to. Use an empty string to remove webhook integration |
||
428 | * @param \CURLFile|string $certificate Upload your public key certificate |
||
429 | * so that the root certificate in use can be checked |
||
430 | * |
||
431 | * @return string |
||
432 | * |
||
433 | * @throws \TelegramBot\Api\Exception |
||
434 | */ |
||
435 | public function setWebhook($url = '', $certificate = null) |
||
439 | |||
440 | /** |
||
441 | * Use this method to get current webhook status. |
||
442 | * |
||
443 | * @return WebhookInfo |
||
444 | * |
||
445 | * @throws \TelegramBot\Api\Exception |
||
446 | */ |
||
447 | public function getWebhookInfo() |
||
451 | |||
452 | /** |
||
453 | * A simple method for testing your bot's auth token.Requires no parameters. |
||
454 | * Returns basic information about the bot in form of a User object. |
||
455 | * |
||
456 | * @return \TelegramBot\Api\Types\User |
||
457 | * @throws \TelegramBot\Api\Exception |
||
458 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
459 | */ |
||
460 | public function getMe() |
||
464 | |||
465 | /** |
||
466 | * Use this method to receive incoming updates using long polling. |
||
467 | * An Array of Update objects is returned. |
||
468 | * |
||
469 | * Notes |
||
470 | * 1. This method will not work if an outgoing webhook is set up. |
||
471 | * 2. In order to avoid getting duplicate updates, recalculate offset after each server response. |
||
472 | * |
||
473 | * @param int $offset |
||
474 | * @param int $limit |
||
475 | * @param int $timeout |
||
476 | * |
||
477 | * @return Update[] |
||
478 | * @throws \TelegramBot\Api\Exception |
||
479 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
480 | */ |
||
481 | 2 | public function getUpdates($offset = 0, $limit = 100, $timeout = 0) |
|
497 | |||
498 | /** |
||
499 | * Use this method to send point on the map. On success, the sent Message is returned. |
||
500 | * |
||
501 | * @param int|string $chatId |
||
502 | * @param float $latitude |
||
503 | * @param float $longitude |
||
504 | * @param int|null $replyToMessageId |
||
505 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
506 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
507 | * @param bool $disableNotification |
||
508 | * |
||
509 | * @param null|int $livePeriod |
||
510 | * @return \TelegramBot\Api\Types\Message |
||
511 | */ |
||
512 | View Code Duplication | public function sendLocation( |
|
531 | |||
532 | /** |
||
533 | * Use this method to edit live location messages sent by the bot or via the bot (for inline bots). |
||
534 | * |
||
535 | * @param int|string $chatId |
||
536 | * @param int $messageId |
||
537 | * @param string $inlineMessageId |
||
538 | * @param float $latitude |
||
539 | * @param float $longitude |
||
540 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
541 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
542 | * @return \TelegramBot\Api\Types\Message |
||
543 | */ |
||
544 | public function editMessageLiveLocation( |
||
561 | |||
562 | /** |
||
563 | * Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots) before |
||
564 | * live_period expires. |
||
565 | * |
||
566 | * @param int|string $chatId |
||
567 | * @param int $messageId |
||
568 | * @param string $inlineMessageId |
||
569 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
570 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
571 | * @return \TelegramBot\Api\Types\Message |
||
572 | */ |
||
573 | public function stopMessageLiveLocation( |
||
586 | |||
587 | /** |
||
588 | * Use this method to send information about a venue. On success, the sent Message is returned. |
||
589 | * |
||
590 | * @param int|string $chatId chat_id or @channel_name |
||
591 | * @param float $latitude |
||
592 | * @param float $longitude |
||
593 | * @param string $title |
||
594 | * @param string $address |
||
595 | * @param string|null $foursquareId |
||
596 | * @param int|null $replyToMessageId |
||
597 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
598 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
599 | * @param bool $disableNotification |
||
600 | * |
||
601 | * @return \TelegramBot\Api\Types\Message |
||
602 | * @throws \TelegramBot\Api\Exception |
||
603 | */ |
||
604 | public function sendVenue( |
||
627 | |||
628 | /** |
||
629 | * Use this method to send .webp stickers. On success, the sent Message is returned. |
||
630 | * |
||
631 | * @param int|string $chatId chat_id or @channel_name |
||
632 | * @param \CURLFile|string $sticker |
||
633 | * @param int|null $replyToMessageId |
||
634 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
635 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
636 | * @param bool $disableNotification |
||
637 | * |
||
638 | * @return \TelegramBot\Api\Types\Message |
||
639 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
640 | * @throws \TelegramBot\Api\Exception |
||
641 | */ |
||
642 | View Code Duplication | public function sendSticker( |
|
657 | |||
658 | /** |
||
659 | * Use this method to send video files, |
||
660 | * Telegram clients support mp4 videos (other formats may be sent as Document). |
||
661 | * On success, the sent Message is returned. |
||
662 | * |
||
663 | * @param int|string $chatId chat_id or @channel_name |
||
664 | * @param \CURLFile|string $video |
||
665 | * @param int|null $duration |
||
666 | * @param string|null $caption |
||
667 | * @param int|null $replyToMessageId |
||
668 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
669 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
670 | * @param bool $disableNotification |
||
671 | * @param bool $supportsStreaming Pass True, if the uploaded video is suitable for streaming |
||
672 | * @param string|null $parseMode |
||
673 | * |
||
674 | * @return \TelegramBot\Api\Types\Message |
||
675 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
676 | * @throws \TelegramBot\Api\Exception |
||
677 | */ |
||
678 | View Code Duplication | public function sendVideo( |
|
701 | |||
702 | /** |
||
703 | * Use this method to send audio files, |
||
704 | * if you want Telegram clients to display the file as a playable voice message. |
||
705 | * For this to work, your audio must be in an .ogg file encoded with OPUS |
||
706 | * (other formats may be sent as Audio or Document). |
||
707 | * On success, the sent Message is returned. |
||
708 | * Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. |
||
709 | * |
||
710 | * @param int|string $chatId chat_id or @channel_name |
||
711 | * @param \CURLFile|string $voice |
||
712 | * @param int|null $duration |
||
713 | * @param int|null $replyToMessageId |
||
714 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
715 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
716 | * @param bool $disableNotification |
||
717 | * @param string|null $parseMode |
||
718 | * |
||
719 | * @return \TelegramBot\Api\Types\Message |
||
720 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
721 | * @throws \TelegramBot\Api\Exception |
||
722 | */ |
||
723 | View Code Duplication | public function sendVoice( |
|
742 | |||
743 | /** |
||
744 | * Use this method to forward messages of any kind. On success, the sent Message is returned. |
||
745 | * |
||
746 | * @param int|string $chatId chat_id or @channel_name |
||
747 | * @param int $fromChatId |
||
748 | * @param int $messageId |
||
749 | * @param bool $disableNotification |
||
750 | * |
||
751 | * @return \TelegramBot\Api\Types\Message |
||
752 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
753 | * @throws \TelegramBot\Api\Exception |
||
754 | */ |
||
755 | public function forwardMessage($chatId, $fromChatId, $messageId, $disableNotification = false) |
||
764 | |||
765 | /** |
||
766 | * Use this method to send audio files, |
||
767 | * if you want Telegram clients to display them in the music player. |
||
768 | * Your audio must be in the .mp3 format. |
||
769 | * On success, the sent Message is returned. |
||
770 | * Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. |
||
771 | * |
||
772 | * For backward compatibility, when the fields title and performer are both empty |
||
773 | * and the mime-type of the file to be sent is not audio/mpeg, the file will be sent as a playable voice message. |
||
774 | * For this to work, the audio must be in an .ogg file encoded with OPUS. |
||
775 | * This behavior will be phased out in the future. For sending voice messages, use the sendVoice method instead. |
||
776 | * |
||
777 | * @deprecated since 20th February. Removed backward compatibility from the method sendAudio. |
||
778 | * Voice messages now must be sent using the method sendVoice. |
||
779 | * There is no more need to specify a non-empty title or performer while sending the audio by file_id. |
||
780 | * |
||
781 | * @param int|string $chatId chat_id or @channel_name |
||
782 | * @param \CURLFile|string $audio |
||
783 | * @param int|null $duration |
||
784 | * @param string|null $performer |
||
785 | * @param string|null $title |
||
786 | * @param int|null $replyToMessageId |
||
787 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
788 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
789 | * @param bool $disableNotification |
||
790 | * @param string|null $parseMode |
||
791 | * |
||
792 | * @return \TelegramBot\Api\Types\Message |
||
793 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
794 | * @throws \TelegramBot\Api\Exception |
||
795 | */ |
||
796 | View Code Duplication | public function sendAudio( |
|
819 | |||
820 | /** |
||
821 | * Use this method to send photos. On success, the sent Message is returned. |
||
822 | * |
||
823 | * @param int|string $chatId chat_id or @channel_name |
||
824 | * @param \CURLFile|string $photo |
||
825 | * @param string|null $caption |
||
826 | * @param int|null $replyToMessageId |
||
827 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
828 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
829 | * @param bool $disableNotification |
||
830 | * @param string|null $parseMode |
||
831 | * |
||
832 | * @return \TelegramBot\Api\Types\Message |
||
833 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
834 | * @throws \TelegramBot\Api\Exception |
||
835 | */ |
||
836 | View Code Duplication | public function sendPhoto( |
|
855 | |||
856 | /** |
||
857 | * Use this method to send general files. On success, the sent Message is returned. |
||
858 | * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. |
||
859 | * |
||
860 | * @param int|string $chatId chat_id or @channel_name |
||
861 | * @param \CURLFile|string $document |
||
862 | * @param string|null $caption |
||
863 | * @param int|null $replyToMessageId |
||
864 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
865 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
866 | * @param bool $disableNotification |
||
867 | * @param string|null $parseMode |
||
868 | * |
||
869 | * @return \TelegramBot\Api\Types\Message |
||
870 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
871 | * @throws \TelegramBot\Api\Exception |
||
872 | */ |
||
873 | View Code Duplication | public function sendDocument( |
|
892 | |||
893 | /** |
||
894 | * Use this method to get basic info about a file and prepare it for downloading. |
||
895 | * For the moment, bots can download files of up to 20MB in size. |
||
896 | * On success, a File object is returned. |
||
897 | * The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, |
||
898 | * where <file_path> is taken from the response. |
||
899 | * It is guaranteed that the link will be valid for at least 1 hour. |
||
900 | * When the link expires, a new one can be requested by calling getFile again. |
||
901 | * |
||
902 | * @param $fileId |
||
903 | * |
||
904 | * @return \TelegramBot\Api\Types\File |
||
905 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
906 | * @throws \TelegramBot\Api\Exception |
||
907 | */ |
||
908 | public function getFile($fileId) |
||
912 | |||
913 | /** |
||
914 | * Get file contents via cURL |
||
915 | * |
||
916 | * @param $fileId |
||
917 | * |
||
918 | * @return string |
||
919 | * |
||
920 | * @throws \TelegramBot\Api\HttpException |
||
921 | */ |
||
922 | public function downloadFile($fileId) |
||
934 | |||
935 | /** |
||
936 | * Use this method to send answers to an inline query. On success, True is returned. |
||
937 | * No more than 50 results per query are allowed. |
||
938 | * |
||
939 | * @param string $inlineQueryId |
||
940 | * @param AbstractInlineQueryResult[] $results |
||
941 | * @param int $cacheTime |
||
942 | * @param bool $isPersonal |
||
943 | * @param string $nextOffset |
||
944 | * @param string $switchPmText |
||
945 | * @param string $switchPmParameter |
||
946 | * |
||
947 | * @return mixed |
||
948 | * @throws Exception |
||
949 | */ |
||
950 | public function answerInlineQuery( |
||
974 | |||
975 | /** |
||
976 | * Use this method to kick a user from a group or a supergroup. |
||
977 | * In the case of supergroups, the user will not be able to return to the group |
||
978 | * on their own using invite links, etc., unless unbanned first. |
||
979 | * The bot must be an administrator in the group for this to work. Returns True on success. |
||
980 | * |
||
981 | * @param int|string $chatId Unique identifier for the target group |
||
982 | * or username of the target supergroup (in the format @supergroupusername) |
||
983 | * @param int $userId Unique identifier of the target user |
||
984 | * @param null|int $untilDate Date when the user will be unbanned, unix time. |
||
985 | * If user is banned for more than 366 days or less than 30 seconds from the current time |
||
986 | * they are considered to be banned forever |
||
987 | * |
||
988 | * @return bool |
||
989 | */ |
||
990 | public function kickChatMember($chatId, $userId, $untilDate = null) |
||
998 | |||
999 | /** |
||
1000 | * Use this method to unban a previously kicked user in a supergroup. |
||
1001 | * The user will not return to the group automatically, but will be able to join via link, etc. |
||
1002 | * The bot must be an administrator in the group for this to work. Returns True on success. |
||
1003 | * |
||
1004 | * @param int|string $chatId Unique identifier for the target group |
||
1005 | * or username of the target supergroup (in the format @supergroupusername) |
||
1006 | * @param int $userId Unique identifier of the target user |
||
1007 | * |
||
1008 | * @return bool |
||
1009 | */ |
||
1010 | public function unbanChatMember($chatId, $userId) |
||
1017 | |||
1018 | /** |
||
1019 | * Use this method to send answers to callback queries sent from inline keyboards. |
||
1020 | * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. |
||
1021 | * |
||
1022 | * @param $callbackQueryId |
||
1023 | * @param null $text |
||
1024 | * @param bool $showAlert |
||
1025 | * |
||
1026 | * @return bool |
||
1027 | */ |
||
1028 | public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = false) |
||
1036 | |||
1037 | |||
1038 | /** |
||
1039 | * Use this method to edit text messages sent by the bot or via the bot |
||
1040 | * |
||
1041 | * @param int|string $chatId |
||
1042 | * @param int $messageId |
||
1043 | * @param string $text |
||
1044 | * @param string $inlineMessageId |
||
1045 | * @param string|null $parseMode |
||
1046 | * @param bool $disablePreview |
||
1047 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
1048 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
1049 | * @return Message |
||
1050 | */ |
||
1051 | View Code Duplication | public function editMessageText( |
|
1070 | |||
1071 | /** |
||
1072 | * Use this method to edit text messages sent by the bot or via the bot |
||
1073 | * |
||
1074 | * @param int|string $chatId |
||
1075 | * @param int $messageId |
||
1076 | * @param string|null $caption |
||
1077 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
1078 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
1079 | * @param string $inlineMessageId |
||
1080 | * |
||
1081 | * @return \TelegramBot\Api\Types\Message |
||
1082 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
1083 | * @throws \TelegramBot\Api\Exception |
||
1084 | */ |
||
1085 | View Code Duplication | public function editMessageCaption( |
|
1100 | |||
1101 | /** |
||
1102 | * Use this method to edit only the reply markup of messages sent by the bot or via the bot |
||
1103 | * |
||
1104 | * @param int|string $chatId |
||
1105 | * @param int $messageId |
||
1106 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
1107 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
1108 | * @param string $inlineMessageId |
||
1109 | * |
||
1110 | * @return Message |
||
1111 | */ |
||
1112 | public function editMessageReplyMarkup( |
||
1125 | |||
1126 | /** |
||
1127 | * Use this method to delete a message, including service messages, with the following limitations: |
||
1128 | * - A message can only be deleted if it was sent less than 48 hours ago. |
||
1129 | * - Bots can delete outgoing messages in groups and supergroups. |
||
1130 | * - Bots granted can_post_messages permissions can delete outgoing messages in channels. |
||
1131 | * - If the bot is an administrator of a group, it can delete any message there. |
||
1132 | * - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. |
||
1133 | * |
||
1134 | * @param int|string $chatId |
||
1135 | * @param int $messageId |
||
1136 | * |
||
1137 | * @return bool |
||
1138 | */ |
||
1139 | public function deleteMessage($chatId, $messageId) |
||
1146 | |||
1147 | /** |
||
1148 | * Close curl |
||
1149 | */ |
||
1150 | 9 | public function __destruct() |
|
1154 | |||
1155 | /** |
||
1156 | * @return string |
||
1157 | */ |
||
1158 | public function getUrl() |
||
1162 | |||
1163 | /** |
||
1164 | * @return string |
||
1165 | */ |
||
1166 | public function getFileUrl() |
||
1170 | |||
1171 | /** |
||
1172 | * @param \TelegramBot\Api\Types\Update $update |
||
1173 | * @param string $eventName |
||
1174 | * |
||
1175 | * @throws \TelegramBot\Api\Exception |
||
1176 | */ |
||
1177 | public function trackUpdate(Update $update, $eventName = 'Message') |
||
1189 | |||
1190 | /** |
||
1191 | * Wrapper for tracker |
||
1192 | * |
||
1193 | * @param \TelegramBot\Api\Types\Message $message |
||
1194 | * @param string $eventName |
||
1195 | * |
||
1196 | * @throws \TelegramBot\Api\Exception |
||
1197 | */ |
||
1198 | public function track(Message $message, $eventName = 'Message') |
||
1204 | |||
1205 | /** |
||
1206 | * Use this method to send invoices. On success, the sent Message is returned. |
||
1207 | * |
||
1208 | * @param int|string $chatId |
||
1209 | * @param string $title |
||
1210 | * @param string $description |
||
1211 | * @param string $payload |
||
1212 | * @param string $providerToken |
||
1213 | * @param string $startParameter |
||
1214 | * @param string $currency |
||
1215 | * @param array $prices |
||
1216 | * @param string|null $photoUrl |
||
1217 | * @param int|null $photoSize |
||
1218 | * @param int|null $photoWidth |
||
1219 | * @param int|null $photoHeight |
||
1220 | * @param bool $needName |
||
1221 | * @param bool $needPhoneNumber |
||
1222 | * @param bool $needEmail |
||
1223 | * @param bool $needShippingAddress |
||
1224 | * @param bool $isFlexible |
||
1225 | * @param int|null $replyToMessageId |
||
1226 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
1227 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
1228 | * @param bool $disableNotification |
||
1229 | * @param string|null $providerData |
||
1230 | * @param bool $sendPhoneNumberToProvider |
||
1231 | * @param bool $sendEmailToProvider |
||
1232 | * |
||
1233 | * @return Message |
||
1234 | */ |
||
1235 | public function sendInvoice( |
||
1286 | |||
1287 | /** |
||
1288 | * If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API |
||
1289 | * will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. |
||
1290 | * On success, True is returned. |
||
1291 | * |
||
1292 | * @param string $shippingQueryId |
||
1293 | * @param bool $ok |
||
1294 | * @param array $shipping_options |
||
1295 | * @param null|string $errorMessage |
||
1296 | * |
||
1297 | * @return bool |
||
1298 | * |
||
1299 | */ |
||
1300 | public function answerShippingQuery($shippingQueryId, $ok = true, $shipping_options = [], $errorMessage = null) |
||
1309 | |||
1310 | /** |
||
1311 | * Use this method to respond to such pre-checkout queries. On success, True is returned. |
||
1312 | * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. |
||
1313 | * |
||
1314 | * @param string $preCheckoutQueryId |
||
1315 | * @param bool $ok |
||
1316 | * @param null|string $errorMessage |
||
1317 | * |
||
1318 | * @return mixed |
||
1319 | */ |
||
1320 | public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMessage = null) |
||
1328 | |||
1329 | /** |
||
1330 | * Use this method to restrict a user in a supergroup. |
||
1331 | * The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. |
||
1332 | * Pass True for all boolean parameters to lift restrictions from a user. |
||
1333 | * |
||
1334 | * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup |
||
1335 | * (in the format @supergroupusername) |
||
1336 | * @param int $userId Unique identifier of the target user |
||
1337 | * @param null|integer $untilDate Date when restrictions will be lifted for the user, unix time. |
||
1338 | * If user is restricted for more than 366 days or less than 30 seconds from the current time, |
||
1339 | * they are considered to be restricted forever |
||
1340 | * @param bool $canSendMessages Pass True, if the user can send text messages, contacts, locations and venues |
||
1341 | * @param bool $canSendMediaMessages No Pass True, if the user can send audios, documents, photos, videos, |
||
1342 | * video notes and voice notes, implies can_send_messages |
||
1343 | * @param bool $canSendOtherMessages Pass True, if the user can send animations, games, stickers and |
||
1344 | * use inline bots, implies can_send_media_messages |
||
1345 | * @param bool $canAddWebPagePreviews Pass True, if the user may add web page previews to their messages, |
||
1346 | * implies can_send_media_messages |
||
1347 | * |
||
1348 | * @return bool |
||
1349 | */ |
||
1350 | public function restrictChatMember( |
||
1369 | |||
1370 | /** |
||
1371 | * Use this method to promote or demote a user in a supergroup or a channel. |
||
1372 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1373 | * Pass False for all boolean parameters to demote a user. |
||
1374 | * |
||
1375 | * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup |
||
1376 | * (in the format @supergroupusername) |
||
1377 | * @param int $userId Unique identifier of the target user |
||
1378 | * @param bool $canChangeInfo Pass True, if the administrator can change chat title, photo and other settings |
||
1379 | * @param bool $canPostMessages Pass True, if the administrator can create channel posts, channels only |
||
1380 | * @param bool $canEditMessages Pass True, if the administrator can edit messages of other users, channels only |
||
1381 | * @param bool $canDeleteMessages Pass True, if the administrator can delete messages of other users |
||
1382 | * @param bool $canInviteUsers Pass True, if the administrator can invite new users to the chat |
||
1383 | * @param bool $canRestrictMembers Pass True, if the administrator can restrict, ban or unban chat members |
||
1384 | * @param bool $canPinMessages Pass True, if the administrator can pin messages, supergroups only |
||
1385 | * @param bool $canPromoteMembers Pass True, if the administrator can add new administrators with a subset of his |
||
1386 | * own privileges or demote administrators that he has promoted,directly or |
||
1387 | * indirectly (promoted by administrators that were appointed by him) |
||
1388 | * |
||
1389 | * @return bool |
||
1390 | */ |
||
1391 | public function promoteChatMember( |
||
1416 | |||
1417 | /** |
||
1418 | * Use this method to export an invite link to a supergroup or a channel. |
||
1419 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1420 | * |
||
1421 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1422 | * (in the format @channelusername) |
||
1423 | * @return string |
||
1424 | */ |
||
1425 | public function exportChatInviteLink($chatId) |
||
1431 | |||
1432 | /** |
||
1433 | * Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. |
||
1434 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1435 | * |
||
1436 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1437 | * (in the format @channelusername) |
||
1438 | * @param \CURLFile|string $photo New chat photo, uploaded using multipart/form-data |
||
1439 | * |
||
1440 | * @return bool |
||
1441 | */ |
||
1442 | public function setChatPhoto($chatId, $photo) |
||
1449 | |||
1450 | /** |
||
1451 | * Use this method to delete a chat photo. Photos can't be changed for private chats. |
||
1452 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1453 | * |
||
1454 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1455 | * (in the format @channelusername) |
||
1456 | * |
||
1457 | * @return bool |
||
1458 | */ |
||
1459 | public function deleteChatPhoto($chatId) |
||
1465 | |||
1466 | /** |
||
1467 | * Use this method to change the title of a chat. Titles can't be changed for private chats. |
||
1468 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1469 | * |
||
1470 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1471 | * (in the format @channelusername) |
||
1472 | * @param string $title New chat title, 1-255 characters |
||
1473 | * |
||
1474 | * @return bool |
||
1475 | */ |
||
1476 | public function setChatTitle($chatId, $title) |
||
1483 | |||
1484 | /** |
||
1485 | * Use this method to change the description of a supergroup or a channel. |
||
1486 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1487 | * |
||
1488 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1489 | * (in the format @channelusername) |
||
1490 | * @param string|null $description New chat description, 0-255 characters |
||
1491 | * |
||
1492 | * @return bool |
||
1493 | */ |
||
1494 | public function setChatDescription($chatId, $description = null) |
||
1501 | |||
1502 | /** |
||
1503 | * Use this method to pin a message in a supergroup. |
||
1504 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1505 | * |
||
1506 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1507 | * (in the format @channelusername) |
||
1508 | * @param int $messageId Identifier of a message to pin |
||
1509 | * @param bool $disableNotification |
||
1510 | * |
||
1511 | * @return bool |
||
1512 | */ |
||
1513 | public function pinChatMessage($chatId, $messageId, $disableNotification = false) |
||
1521 | |||
1522 | /** |
||
1523 | * Use this method to unpin a message in a supergroup chat. |
||
1524 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1525 | * |
||
1526 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1527 | * (in the format @channelusername) |
||
1528 | * |
||
1529 | * @return bool |
||
1530 | */ |
||
1531 | public function unpinChatMessage($chatId) |
||
1537 | |||
1538 | /** |
||
1539 | * Use this method to get up to date information about the chat |
||
1540 | * (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). |
||
1541 | * |
||
1542 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1543 | * (in the format @channelusername) |
||
1544 | * |
||
1545 | * @return Chat |
||
1546 | */ |
||
1547 | public function getChat($chatId) |
||
1553 | |||
1554 | /** |
||
1555 | * Use this method to get information about a member of a chat. |
||
1556 | * |
||
1557 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1558 | * (in the format @channelusername) |
||
1559 | * @param int $userId |
||
1560 | * |
||
1561 | * @return ChatMember |
||
1562 | */ |
||
1563 | public function getChatMember($chatId, $userId) |
||
1570 | |||
1571 | /** |
||
1572 | * Use this method for your bot to leave a group, supergroup or channel. |
||
1573 | * |
||
1574 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1575 | * (in the format @channelusername) |
||
1576 | * |
||
1577 | * @return bool |
||
1578 | */ |
||
1579 | public function leaveChat($chatId) |
||
1585 | |||
1586 | /** |
||
1587 | * Use this method to get the number of members in a chat. |
||
1588 | * |
||
1589 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1590 | * (in the format @channelusername) |
||
1591 | * |
||
1592 | * @return int |
||
1593 | */ |
||
1594 | public function getChatMembersCount($chatId) |
||
1603 | |||
1604 | /** |
||
1605 | * Use this method to get a list of administrators in a chat. |
||
1606 | * |
||
1607 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1608 | * (in the format @channelusername) |
||
1609 | * |
||
1610 | * @return array |
||
1611 | */ |
||
1612 | public function getChatAdministrators($chatId) |
||
1623 | |||
1624 | /** |
||
1625 | * As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. |
||
1626 | * Use this method to send video messages. |
||
1627 | * On success, the sent Message is returned. |
||
1628 | * |
||
1629 | * @param int|string $chatId chat_id or @channel_name |
||
1630 | * @param \CURLFile|string $videoNote |
||
1631 | * @param int|null $duration |
||
1632 | * @param int|null $length |
||
1633 | * @param int|null $replyToMessageId |
||
1634 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
1635 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
1636 | * @param bool $disableNotification |
||
1637 | * |
||
1638 | * @return \TelegramBot\Api\Types\Message |
||
1639 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
1640 | * @throws \TelegramBot\Api\Exception |
||
1641 | */ |
||
1642 | View Code Duplication | public function sendVideoNote( |
|
1661 | |||
1662 | /** |
||
1663 | * Use this method to send a group of photos or videos as an album. |
||
1664 | * On success, the sent \TelegramBot\Api\Types\Message is returned. |
||
1665 | * |
||
1666 | * @param int|string $chatId |
||
1667 | * @param ArrayOfInputMedia $media |
||
1668 | * @param int|null $replyToMessageId |
||
1669 | * @param bool $disableNotification |
||
1670 | * |
||
1671 | * @return array |
||
1672 | * @throws \TelegramBot\Api\Exception |
||
1673 | */ |
||
1674 | public function sendMediaGroup( |
||
1687 | |||
1688 | /** |
||
1689 | * Enable proxy for curl requests. Empty string will disable proxy. |
||
1690 | * |
||
1691 | * @param string $proxyString |
||
1692 | * |
||
1693 | * @return BotApi |
||
1694 | */ |
||
1695 | public function setProxy($proxyString = '') |
||
1708 | |||
1709 | /** |
||
1710 | * Set an option for a cURL transfer |
||
1711 | * |
||
1712 | * @param int $option The CURLOPT_XXX option to set |
||
1713 | * @param mixed $value The value to be set on option |
||
1714 | */ |
||
1715 | public function setCurlOption($option, $value) |
||
1719 | |||
1720 | /** |
||
1721 | * Unset an option for a cURL transfer |
||
1722 | * |
||
1723 | * @param int $option The CURLOPT_XXX option to unset |
||
1724 | */ |
||
1725 | public function unsetCurlOption($option) |
||
1729 | |||
1730 | /** |
||
1731 | * Clean custom options |
||
1732 | */ |
||
1733 | public function resetCurlOptions() |
||
1737 | } |
||
1738 |