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 | * A simple method for testing your bot's auth token.Requires no parameters. |
||
442 | * Returns basic information about the bot in form of a User object. |
||
443 | * |
||
444 | * @return \TelegramBot\Api\Types\User |
||
445 | * @throws \TelegramBot\Api\Exception |
||
446 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
447 | */ |
||
448 | public function getMe() |
||
452 | |||
453 | /** |
||
454 | * Use this method to receive incoming updates using long polling. |
||
455 | * An Array of Update objects is returned. |
||
456 | * |
||
457 | * Notes |
||
458 | * 1. This method will not work if an outgoing webhook is set up. |
||
459 | * 2. In order to avoid getting duplicate updates, recalculate offset after each server response. |
||
460 | * |
||
461 | * @param int $offset |
||
462 | * @param int $limit |
||
463 | * @param int $timeout |
||
464 | * |
||
465 | * @return Update[] |
||
466 | * @throws \TelegramBot\Api\Exception |
||
467 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
468 | */ |
||
469 | 2 | public function getUpdates($offset = 0, $limit = 100, $timeout = 0) |
|
485 | |||
486 | /** |
||
487 | * Use this method to send point on the map. On success, the sent Message is returned. |
||
488 | * |
||
489 | * @param int|string $chatId |
||
490 | * @param float $latitude |
||
491 | * @param float $longitude |
||
492 | * @param int|null $replyToMessageId |
||
493 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
494 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
495 | * @param bool $disableNotification |
||
496 | * |
||
497 | * @param null|int $livePeriod |
||
498 | * @return \TelegramBot\Api\Types\Message |
||
499 | */ |
||
500 | View Code Duplication | public function sendLocation( |
|
519 | |||
520 | /** |
||
521 | * Use this method to edit live location messages sent by the bot or via the bot (for inline bots). |
||
522 | * |
||
523 | * @param int|string $chatId |
||
524 | * @param int $messageId |
||
525 | * @param string $inlineMessageId |
||
526 | * @param float $latitude |
||
527 | * @param float $longitude |
||
528 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
529 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
530 | * @return \TelegramBot\Api\Types\Message |
||
531 | */ |
||
532 | public function editMessageLiveLocation( |
||
549 | |||
550 | /** |
||
551 | * Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots) before |
||
552 | * live_period expires. |
||
553 | * |
||
554 | * @param int|string $chatId |
||
555 | * @param int $messageId |
||
556 | * @param string $inlineMessageId |
||
557 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
558 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
559 | * @return \TelegramBot\Api\Types\Message |
||
560 | */ |
||
561 | public function stopMessageLiveLocation( |
||
574 | |||
575 | /** |
||
576 | * Use this method to send information about a venue. On success, the sent Message is returned. |
||
577 | * |
||
578 | * @param int|string $chatId chat_id or @channel_name |
||
579 | * @param float $latitude |
||
580 | * @param float $longitude |
||
581 | * @param string $title |
||
582 | * @param string $address |
||
583 | * @param string|null $foursquareId |
||
584 | * @param int|null $replyToMessageId |
||
585 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
586 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
587 | * @param bool $disableNotification |
||
588 | * |
||
589 | * @return \TelegramBot\Api\Types\Message |
||
590 | * @throws \TelegramBot\Api\Exception |
||
591 | */ |
||
592 | public function sendVenue( |
||
615 | |||
616 | /** |
||
617 | * Use this method to send .webp stickers. On success, the sent Message is returned. |
||
618 | * |
||
619 | * @param int|string $chatId chat_id or @channel_name |
||
620 | * @param \CURLFile|string $sticker |
||
621 | * @param int|null $replyToMessageId |
||
622 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
623 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
624 | * @param bool $disableNotification |
||
625 | * |
||
626 | * @return \TelegramBot\Api\Types\Message |
||
627 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
628 | * @throws \TelegramBot\Api\Exception |
||
629 | */ |
||
630 | View Code Duplication | public function sendSticker( |
|
645 | |||
646 | /** |
||
647 | * Use this method to send video files, |
||
648 | * Telegram clients support mp4 videos (other formats may be sent as Document). |
||
649 | * On success, the sent Message is returned. |
||
650 | * |
||
651 | * @param int|string $chatId chat_id or @channel_name |
||
652 | * @param \CURLFile|string $video |
||
653 | * @param int|null $duration |
||
654 | * @param string|null $caption |
||
655 | * @param int|null $replyToMessageId |
||
656 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
657 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
658 | * @param bool $disableNotification |
||
659 | * @param bool $supportsStreaming Pass True, if the uploaded video is suitable for streaming |
||
660 | * @param string|null $parseMode |
||
661 | * |
||
662 | * @return \TelegramBot\Api\Types\Message |
||
663 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
664 | * @throws \TelegramBot\Api\Exception |
||
665 | */ |
||
666 | View Code Duplication | public function sendVideo( |
|
689 | |||
690 | /** |
||
691 | * Use this method to send audio files, |
||
692 | * if you want Telegram clients to display the file as a playable voice message. |
||
693 | * For this to work, your audio must be in an .ogg file encoded with OPUS |
||
694 | * (other formats may be sent as Audio or Document). |
||
695 | * On success, the sent Message is returned. |
||
696 | * Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. |
||
697 | * |
||
698 | * @param int|string $chatId chat_id or @channel_name |
||
699 | * @param \CURLFile|string $voice |
||
700 | * @param int|null $duration |
||
701 | * @param int|null $replyToMessageId |
||
702 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
703 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
704 | * @param bool $disableNotification |
||
705 | * @param string|null $parseMode |
||
706 | * |
||
707 | * @return \TelegramBot\Api\Types\Message |
||
708 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
709 | * @throws \TelegramBot\Api\Exception |
||
710 | */ |
||
711 | View Code Duplication | public function sendVoice( |
|
730 | |||
731 | /** |
||
732 | * Use this method to forward messages of any kind. On success, the sent Message is returned. |
||
733 | * |
||
734 | * @param int|string $chatId chat_id or @channel_name |
||
735 | * @param int $fromChatId |
||
736 | * @param int $messageId |
||
737 | * @param bool $disableNotification |
||
738 | * |
||
739 | * @return \TelegramBot\Api\Types\Message |
||
740 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
741 | * @throws \TelegramBot\Api\Exception |
||
742 | */ |
||
743 | public function forwardMessage($chatId, $fromChatId, $messageId, $disableNotification = false) |
||
752 | |||
753 | /** |
||
754 | * Use this method to send audio files, |
||
755 | * if you want Telegram clients to display them in the music player. |
||
756 | * Your audio must be in the .mp3 format. |
||
757 | * On success, the sent Message is returned. |
||
758 | * Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. |
||
759 | * |
||
760 | * For backward compatibility, when the fields title and performer are both empty |
||
761 | * and the mime-type of the file to be sent is not audio/mpeg, the file will be sent as a playable voice message. |
||
762 | * For this to work, the audio must be in an .ogg file encoded with OPUS. |
||
763 | * This behavior will be phased out in the future. For sending voice messages, use the sendVoice method instead. |
||
764 | * |
||
765 | * @deprecated since 20th February. Removed backward compatibility from the method sendAudio. |
||
766 | * Voice messages now must be sent using the method sendVoice. |
||
767 | * There is no more need to specify a non-empty title or performer while sending the audio by file_id. |
||
768 | * |
||
769 | * @param int|string $chatId chat_id or @channel_name |
||
770 | * @param \CURLFile|string $audio |
||
771 | * @param int|null $duration |
||
772 | * @param string|null $performer |
||
773 | * @param string|null $title |
||
774 | * @param int|null $replyToMessageId |
||
775 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
776 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
777 | * @param bool $disableNotification |
||
778 | * @param string|null $parseMode |
||
779 | * |
||
780 | * @return \TelegramBot\Api\Types\Message |
||
781 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
782 | * @throws \TelegramBot\Api\Exception |
||
783 | */ |
||
784 | View Code Duplication | public function sendAudio( |
|
807 | |||
808 | /** |
||
809 | * Use this method to send photos. On success, the sent Message is returned. |
||
810 | * |
||
811 | * @param int|string $chatId chat_id or @channel_name |
||
812 | * @param \CURLFile|string $photo |
||
813 | * @param string|null $caption |
||
814 | * @param int|null $replyToMessageId |
||
815 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
816 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
817 | * @param bool $disableNotification |
||
818 | * @param string|null $parseMode |
||
819 | * |
||
820 | * @return \TelegramBot\Api\Types\Message |
||
821 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
822 | * @throws \TelegramBot\Api\Exception |
||
823 | */ |
||
824 | View Code Duplication | public function sendPhoto( |
|
843 | |||
844 | /** |
||
845 | * Use this method to send general files. On success, the sent Message is returned. |
||
846 | * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. |
||
847 | * |
||
848 | * @param int|string $chatId chat_id or @channel_name |
||
849 | * @param \CURLFile|string $document |
||
850 | * @param string|null $caption |
||
851 | * @param int|null $replyToMessageId |
||
852 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
853 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
854 | * @param bool $disableNotification |
||
855 | * @param string|null $parseMode |
||
856 | * |
||
857 | * @return \TelegramBot\Api\Types\Message |
||
858 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
859 | * @throws \TelegramBot\Api\Exception |
||
860 | */ |
||
861 | View Code Duplication | public function sendDocument( |
|
880 | |||
881 | /** |
||
882 | * Use this method to get basic info about a file and prepare it for downloading. |
||
883 | * For the moment, bots can download files of up to 20MB in size. |
||
884 | * On success, a File object is returned. |
||
885 | * The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, |
||
886 | * where <file_path> is taken from the response. |
||
887 | * It is guaranteed that the link will be valid for at least 1 hour. |
||
888 | * When the link expires, a new one can be requested by calling getFile again. |
||
889 | * |
||
890 | * @param $fileId |
||
891 | * |
||
892 | * @return \TelegramBot\Api\Types\File |
||
893 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
894 | * @throws \TelegramBot\Api\Exception |
||
895 | */ |
||
896 | public function getFile($fileId) |
||
900 | |||
901 | /** |
||
902 | * Get file contents via cURL |
||
903 | * |
||
904 | * @param $fileId |
||
905 | * |
||
906 | * @return string |
||
907 | * |
||
908 | * @throws \TelegramBot\Api\HttpException |
||
909 | */ |
||
910 | public function downloadFile($fileId) |
||
922 | |||
923 | /** |
||
924 | * Use this method to send answers to an inline query. On success, True is returned. |
||
925 | * No more than 50 results per query are allowed. |
||
926 | * |
||
927 | * @param string $inlineQueryId |
||
928 | * @param AbstractInlineQueryResult[] $results |
||
929 | * @param int $cacheTime |
||
930 | * @param bool $isPersonal |
||
931 | * @param string $nextOffset |
||
932 | * @param string $switchPmText |
||
933 | * @param string $switchPmParameter |
||
934 | * |
||
935 | * @return mixed |
||
936 | * @throws Exception |
||
937 | */ |
||
938 | public function answerInlineQuery( |
||
962 | |||
963 | /** |
||
964 | * Use this method to kick a user from a group or a supergroup. |
||
965 | * In the case of supergroups, the user will not be able to return to the group |
||
966 | * on their own using invite links, etc., unless unbanned first. |
||
967 | * The bot must be an administrator in the group for this to work. Returns True on success. |
||
968 | * |
||
969 | * @param int|string $chatId Unique identifier for the target group |
||
970 | * or username of the target supergroup (in the format @supergroupusername) |
||
971 | * @param int $userId Unique identifier of the target user |
||
972 | * @param null|int $untilDate Date when the user will be unbanned, unix time. |
||
973 | * If user is banned for more than 366 days or less than 30 seconds from the current time |
||
974 | * they are considered to be banned forever |
||
975 | * |
||
976 | * @return bool |
||
977 | */ |
||
978 | public function kickChatMember($chatId, $userId, $untilDate = null) |
||
986 | |||
987 | /** |
||
988 | * Use this method to unban a previously kicked user in a supergroup. |
||
989 | * The user will not return to the group automatically, but will be able to join via link, etc. |
||
990 | * The bot must be an administrator in the group for this to work. Returns True on success. |
||
991 | * |
||
992 | * @param int|string $chatId Unique identifier for the target group |
||
993 | * or username of the target supergroup (in the format @supergroupusername) |
||
994 | * @param int $userId Unique identifier of the target user |
||
995 | * |
||
996 | * @return bool |
||
997 | */ |
||
998 | public function unbanChatMember($chatId, $userId) |
||
1005 | |||
1006 | /** |
||
1007 | * Use this method to send answers to callback queries sent from inline keyboards. |
||
1008 | * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. |
||
1009 | * |
||
1010 | * @param $callbackQueryId |
||
1011 | * @param null $text |
||
1012 | * @param bool $showAlert |
||
1013 | * |
||
1014 | * @return bool |
||
1015 | */ |
||
1016 | public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = false) |
||
1024 | |||
1025 | |||
1026 | /** |
||
1027 | * Use this method to edit text messages sent by the bot or via the bot |
||
1028 | * |
||
1029 | * @param int|string $chatId |
||
1030 | * @param int $messageId |
||
1031 | * @param string $text |
||
1032 | * @param string $inlineMessageId |
||
1033 | * @param string|null $parseMode |
||
1034 | * @param bool $disablePreview |
||
1035 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
1036 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
1037 | * @return Message |
||
1038 | */ |
||
1039 | View Code Duplication | public function editMessageText( |
|
1058 | |||
1059 | /** |
||
1060 | * Use this method to edit text messages sent by the bot or via the bot |
||
1061 | * |
||
1062 | * @param int|string $chatId |
||
1063 | * @param int $messageId |
||
1064 | * @param string|null $caption |
||
1065 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
1066 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
1067 | * @param string $inlineMessageId |
||
1068 | * |
||
1069 | * @return \TelegramBot\Api\Types\Message |
||
1070 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
1071 | * @throws \TelegramBot\Api\Exception |
||
1072 | */ |
||
1073 | View Code Duplication | public function editMessageCaption( |
|
1088 | |||
1089 | /** |
||
1090 | * Use this method to edit only the reply markup of messages sent by the bot or via the bot |
||
1091 | * |
||
1092 | * @param int|string $chatId |
||
1093 | * @param int $messageId |
||
1094 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
1095 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
1096 | * @param string $inlineMessageId |
||
1097 | * |
||
1098 | * @return Message |
||
1099 | */ |
||
1100 | public function editMessageReplyMarkup( |
||
1113 | |||
1114 | /** |
||
1115 | * Use this method to delete a message, including service messages, with the following limitations: |
||
1116 | * - A message can only be deleted if it was sent less than 48 hours ago. |
||
1117 | * - Bots can delete outgoing messages in groups and supergroups. |
||
1118 | * - Bots granted can_post_messages permissions can delete outgoing messages in channels. |
||
1119 | * - If the bot is an administrator of a group, it can delete any message there. |
||
1120 | * - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. |
||
1121 | * |
||
1122 | * @param int|string $chatId |
||
1123 | * @param int $messageId |
||
1124 | * |
||
1125 | * @return bool |
||
1126 | */ |
||
1127 | public function deleteMessage($chatId, $messageId) |
||
1134 | |||
1135 | /** |
||
1136 | * Close curl |
||
1137 | */ |
||
1138 | 9 | public function __destruct() |
|
1142 | |||
1143 | /** |
||
1144 | * @return string |
||
1145 | */ |
||
1146 | public function getUrl() |
||
1150 | |||
1151 | /** |
||
1152 | * @return string |
||
1153 | */ |
||
1154 | public function getFileUrl() |
||
1158 | |||
1159 | /** |
||
1160 | * @param \TelegramBot\Api\Types\Update $update |
||
1161 | * @param string $eventName |
||
1162 | * |
||
1163 | * @throws \TelegramBot\Api\Exception |
||
1164 | */ |
||
1165 | public function trackUpdate(Update $update, $eventName = 'Message') |
||
1177 | |||
1178 | /** |
||
1179 | * Wrapper for tracker |
||
1180 | * |
||
1181 | * @param \TelegramBot\Api\Types\Message $message |
||
1182 | * @param string $eventName |
||
1183 | * |
||
1184 | * @throws \TelegramBot\Api\Exception |
||
1185 | */ |
||
1186 | public function track(Message $message, $eventName = 'Message') |
||
1192 | |||
1193 | /** |
||
1194 | * Use this method to send invoices. On success, the sent Message is returned. |
||
1195 | * |
||
1196 | * @param int|string $chatId |
||
1197 | * @param string $title |
||
1198 | * @param string $description |
||
1199 | * @param string $payload |
||
1200 | * @param string $providerToken |
||
1201 | * @param string $startParameter |
||
1202 | * @param string $currency |
||
1203 | * @param array $prices |
||
1204 | * @param string|null $photoUrl |
||
1205 | * @param int|null $photoSize |
||
1206 | * @param int|null $photoWidth |
||
1207 | * @param int|null $photoHeight |
||
1208 | * @param bool $needName |
||
1209 | * @param bool $needPhoneNumber |
||
1210 | * @param bool $needEmail |
||
1211 | * @param bool $needShippingAddress |
||
1212 | * @param bool $isFlexible |
||
1213 | * @param int|null $replyToMessageId |
||
1214 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
1215 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
1216 | * @param bool $disableNotification |
||
1217 | * @param string|null $providerData |
||
1218 | * @param bool $sendPhoneNumberToProvider |
||
1219 | * @param bool $sendEmailToProvider |
||
1220 | * |
||
1221 | * @return Message |
||
1222 | */ |
||
1223 | public function sendInvoice( |
||
1274 | |||
1275 | /** |
||
1276 | * If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API |
||
1277 | * will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. |
||
1278 | * On success, True is returned. |
||
1279 | * |
||
1280 | * @param string $shippingQueryId |
||
1281 | * @param bool $ok |
||
1282 | * @param array $shipping_options |
||
1283 | * @param null|string $errorMessage |
||
1284 | * |
||
1285 | * @return bool |
||
1286 | * |
||
1287 | */ |
||
1288 | public function answerShippingQuery($shippingQueryId, $ok = true, $shipping_options = [], $errorMessage = null) |
||
1297 | |||
1298 | /** |
||
1299 | * Use this method to respond to such pre-checkout queries. On success, True is returned. |
||
1300 | * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. |
||
1301 | * |
||
1302 | * @param string $preCheckoutQueryId |
||
1303 | * @param bool $ok |
||
1304 | * @param null|string $errorMessage |
||
1305 | * |
||
1306 | * @return mixed |
||
1307 | */ |
||
1308 | public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMessage = null) |
||
1316 | |||
1317 | /** |
||
1318 | * Use this method to restrict a user in a supergroup. |
||
1319 | * The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. |
||
1320 | * Pass True for all boolean parameters to lift restrictions from a user. |
||
1321 | * |
||
1322 | * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup |
||
1323 | * (in the format @supergroupusername) |
||
1324 | * @param int $userId Unique identifier of the target user |
||
1325 | * @param null|integer $untilDate Date when restrictions will be lifted for the user, unix time. |
||
1326 | * If user is restricted for more than 366 days or less than 30 seconds from the current time, |
||
1327 | * they are considered to be restricted forever |
||
1328 | * @param bool $canSendMessages Pass True, if the user can send text messages, contacts, locations and venues |
||
1329 | * @param bool $canSendMediaMessages No Pass True, if the user can send audios, documents, photos, videos, |
||
1330 | * video notes and voice notes, implies can_send_messages |
||
1331 | * @param bool $canSendOtherMessages Pass True, if the user can send animations, games, stickers and |
||
1332 | * use inline bots, implies can_send_media_messages |
||
1333 | * @param bool $canAddWebPagePreviews Pass True, if the user may add web page previews to their messages, |
||
1334 | * implies can_send_media_messages |
||
1335 | * |
||
1336 | * @return bool |
||
1337 | */ |
||
1338 | public function restrictChatMember( |
||
1357 | |||
1358 | /** |
||
1359 | * Use this method to promote or demote a user in a supergroup or a channel. |
||
1360 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1361 | * Pass False for all boolean parameters to demote a user. |
||
1362 | * |
||
1363 | * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup |
||
1364 | * (in the format @supergroupusername) |
||
1365 | * @param int $userId Unique identifier of the target user |
||
1366 | * @param bool $canChangeInfo Pass True, if the administrator can change chat title, photo and other settings |
||
1367 | * @param bool $canPostMessages Pass True, if the administrator can create channel posts, channels only |
||
1368 | * @param bool $canEditMessages Pass True, if the administrator can edit messages of other users, channels only |
||
1369 | * @param bool $canDeleteMessages Pass True, if the administrator can delete messages of other users |
||
1370 | * @param bool $canInviteUsers Pass True, if the administrator can invite new users to the chat |
||
1371 | * @param bool $canRestrictMembers Pass True, if the administrator can restrict, ban or unban chat members |
||
1372 | * @param bool $canPinMessages Pass True, if the administrator can pin messages, supergroups only |
||
1373 | * @param bool $canPromoteMembers Pass True, if the administrator can add new administrators with a subset of his |
||
1374 | * own privileges or demote administrators that he has promoted,directly or |
||
1375 | * indirectly (promoted by administrators that were appointed by him) |
||
1376 | * |
||
1377 | * @return bool |
||
1378 | */ |
||
1379 | public function promoteChatMember( |
||
1404 | |||
1405 | /** |
||
1406 | * Use this method to export an invite link to a supergroup or a channel. |
||
1407 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1408 | * |
||
1409 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1410 | * (in the format @channelusername) |
||
1411 | * @return string |
||
1412 | */ |
||
1413 | public function exportChatInviteLink($chatId) |
||
1419 | |||
1420 | /** |
||
1421 | * Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. |
||
1422 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1423 | * |
||
1424 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1425 | * (in the format @channelusername) |
||
1426 | * @param \CURLFile|string $photo New chat photo, uploaded using multipart/form-data |
||
1427 | * |
||
1428 | * @return bool |
||
1429 | */ |
||
1430 | public function setChatPhoto($chatId, $photo) |
||
1437 | |||
1438 | /** |
||
1439 | * Use this method to delete a chat photo. Photos can't be changed for private chats. |
||
1440 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
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 deleteChatPhoto($chatId) |
||
1453 | |||
1454 | /** |
||
1455 | * Use this method to change the title of a chat. Titles can't be changed for private chats. |
||
1456 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1457 | * |
||
1458 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1459 | * (in the format @channelusername) |
||
1460 | * @param string $title New chat title, 1-255 characters |
||
1461 | * |
||
1462 | * @return bool |
||
1463 | */ |
||
1464 | public function setChatTitle($chatId, $title) |
||
1471 | |||
1472 | /** |
||
1473 | * Use this method to change the description of a supergroup or a channel. |
||
1474 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1475 | * |
||
1476 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1477 | * (in the format @channelusername) |
||
1478 | * @param string|null $description New chat description, 0-255 characters |
||
1479 | * |
||
1480 | * @return bool |
||
1481 | */ |
||
1482 | public function setChatDescription($chatId, $description = null) |
||
1489 | |||
1490 | /** |
||
1491 | * Use this method to pin a message in a supergroup. |
||
1492 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1493 | * |
||
1494 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1495 | * (in the format @channelusername) |
||
1496 | * @param int $messageId Identifier of a message to pin |
||
1497 | * @param bool $disableNotification |
||
1498 | * |
||
1499 | * @return bool |
||
1500 | */ |
||
1501 | public function pinChatMessage($chatId, $messageId, $disableNotification = false) |
||
1509 | |||
1510 | /** |
||
1511 | * Use this method to unpin a message in a supergroup chat. |
||
1512 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1513 | * |
||
1514 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1515 | * (in the format @channelusername) |
||
1516 | * |
||
1517 | * @return bool |
||
1518 | */ |
||
1519 | public function unpinChatMessage($chatId) |
||
1525 | |||
1526 | /** |
||
1527 | * Use this method to get up to date information about the chat |
||
1528 | * (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). |
||
1529 | * |
||
1530 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1531 | * (in the format @channelusername) |
||
1532 | * |
||
1533 | * @return Chat |
||
1534 | */ |
||
1535 | public function getChat($chatId) |
||
1541 | |||
1542 | /** |
||
1543 | * Use this method to get information about a member of a chat. |
||
1544 | * |
||
1545 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1546 | * (in the format @channelusername) |
||
1547 | * @param int $userId |
||
1548 | * |
||
1549 | * @return ChatMember |
||
1550 | */ |
||
1551 | public function getChatMember($chatId, $userId) |
||
1558 | |||
1559 | /** |
||
1560 | * Use this method for your bot to leave a group, supergroup or channel. |
||
1561 | * |
||
1562 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1563 | * (in the format @channelusername) |
||
1564 | * |
||
1565 | * @return bool |
||
1566 | */ |
||
1567 | public function leaveChat($chatId) |
||
1573 | |||
1574 | /** |
||
1575 | * Use this method to get the number of members in a chat. |
||
1576 | * |
||
1577 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1578 | * (in the format @channelusername) |
||
1579 | * |
||
1580 | * @return int |
||
1581 | */ |
||
1582 | public function getChatMembersCount($chatId) |
||
1591 | |||
1592 | /** |
||
1593 | * Use this method to get a list of administrators in a chat. |
||
1594 | * |
||
1595 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1596 | * (in the format @channelusername) |
||
1597 | * |
||
1598 | * @return array |
||
1599 | */ |
||
1600 | public function getChatAdministrators($chatId) |
||
1611 | |||
1612 | /** |
||
1613 | * As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. |
||
1614 | * Use this method to send video messages. |
||
1615 | * On success, the sent Message is returned. |
||
1616 | * |
||
1617 | * @param int|string $chatId chat_id or @channel_name |
||
1618 | * @param \CURLFile|string $videoNote |
||
1619 | * @param int|null $duration |
||
1620 | * @param int|null $length |
||
1621 | * @param int|null $replyToMessageId |
||
1622 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply| |
||
1623 | * Types\ReplyKeyboardRemove|null $replyMarkup |
||
1624 | * @param bool $disableNotification |
||
1625 | * |
||
1626 | * @return \TelegramBot\Api\Types\Message |
||
1627 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
1628 | * @throws \TelegramBot\Api\Exception |
||
1629 | */ |
||
1630 | View Code Duplication | public function sendVideoNote( |
|
1649 | |||
1650 | /** |
||
1651 | * Use this method to send a group of photos or videos as an album. |
||
1652 | * On success, the sent \TelegramBot\Api\Types\Message is returned. |
||
1653 | * |
||
1654 | * @param int|string $chatId |
||
1655 | * @param ArrayOfInputMedia $media |
||
1656 | * @param int|null $replyToMessageId |
||
1657 | * @param bool $disableNotification |
||
1658 | * |
||
1659 | * @return array |
||
1660 | * @throws \TelegramBot\Api\Exception |
||
1661 | */ |
||
1662 | public function sendMediaGroup( |
||
1675 | |||
1676 | /** |
||
1677 | * Enable proxy for curl requests. Empty string will disable proxy. |
||
1678 | * |
||
1679 | * @param string $proxyString |
||
1680 | * |
||
1681 | * @return BotApi |
||
1682 | */ |
||
1683 | public function setProxy($proxyString = '', $socks5 = false) |
||
1700 | |||
1701 | /** |
||
1702 | * Set an option for a cURL transfer |
||
1703 | * |
||
1704 | * @param int $option The CURLOPT_XXX option to set |
||
1705 | * @param mixed $value The value to be set on option |
||
1706 | */ |
||
1707 | public function setCurlOption($option, $value) |
||
1711 | |||
1712 | /** |
||
1713 | * Unset an option for a cURL transfer |
||
1714 | * |
||
1715 | * @param int $option The CURLOPT_XXX option to unset |
||
1716 | */ |
||
1717 | public function unsetCurlOption($option) |
||
1721 | |||
1722 | /** |
||
1723 | * Clean custom options |
||
1724 | */ |
||
1725 | public function resetCurlOptions() |
||
1729 | } |
||
1730 |