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 |
||
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) |
|
171 | |||
172 | /** |
||
173 | * Set return array |
||
174 | * |
||
175 | * @param bool $mode |
||
176 | * |
||
177 | * @return $this |
||
178 | */ |
||
179 | public function setModeObject($mode = true) |
||
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) |
||
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) |
||
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) |
||
268 | |||
269 | /** |
||
270 | * JSON validation |
||
271 | * |
||
272 | * @param string $jsonString |
||
273 | * @param boolean $asArray |
||
274 | * |
||
275 | * @return object|array|null |
||
276 | * @throws \TelegramBot\Api\InvalidJsonException |
||
277 | */ |
||
278 | public static function jsonValidate($jsonString, $asArray) |
||
292 | |||
293 | /** |
||
294 | * Use this method to send text messages. On success, the sent \TelegramBot\Api\Types\Message is returned. |
||
295 | * |
||
296 | * @param int|string $chatId |
||
297 | * @param string $text |
||
298 | * @param string|null $parseMode |
||
299 | * @param bool $disablePreview |
||
300 | * @param int|null $replyToMessageId |
||
301 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
302 | * @param bool $disableNotification |
||
303 | * |
||
304 | * @return \TelegramBot\Api\Types\Message |
||
305 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
306 | * @throws \TelegramBot\Api\Exception |
||
307 | */ |
||
308 | public function sendMessage( |
||
327 | |||
328 | /** |
||
329 | * Use this method to send phone contacts |
||
330 | * |
||
331 | * @param int|string $chatId chat_id or @channel_name |
||
332 | * @param string $phoneNumber |
||
333 | * @param string $firstName |
||
334 | * @param string $lastName |
||
335 | * @param int|null $replyToMessageId |
||
336 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
337 | * @param bool $disableNotification |
||
338 | * |
||
339 | * @return \TelegramBot\Api\Types\Message |
||
340 | * @throws \TelegramBot\Api\Exception |
||
341 | */ |
||
342 | View Code Duplication | public function sendContact( |
|
361 | |||
362 | /** |
||
363 | * Use this method when you need to tell the user that something is happening on the bot's side. |
||
364 | * The status is set for 5 seconds or less (when a message arrives from your bot, |
||
365 | * Telegram clients clear its typing status). |
||
366 | * |
||
367 | * We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive. |
||
368 | * |
||
369 | * Type of action to broadcast. Choose one, depending on what the user is about to receive: |
||
370 | * `typing` for text messages, `upload_photo` for photos, `record_video` or `upload_video` for videos, |
||
371 | * `record_audio` or upload_audio for audio files, `upload_document` for general files, |
||
372 | * `find_location` for location data. |
||
373 | * |
||
374 | * @param int $chatId |
||
375 | * @param string $action |
||
376 | * |
||
377 | * @return bool |
||
378 | * @throws \TelegramBot\Api\Exception |
||
379 | */ |
||
380 | public function sendChatAction($chatId, $action) |
||
387 | |||
388 | /** |
||
389 | * Use this method to get a list of profile pictures for a user. |
||
390 | * |
||
391 | * @param int $userId |
||
392 | * @param int $offset |
||
393 | * @param int $limit |
||
394 | * |
||
395 | * @return \TelegramBot\Api\Types\UserProfilePhotos |
||
396 | * @throws \TelegramBot\Api\Exception |
||
397 | */ |
||
398 | public function getUserProfilePhotos($userId, $offset = 0, $limit = 100) |
||
406 | |||
407 | /** |
||
408 | * Use this method to specify a url and receive incoming updates via an outgoing webhook. |
||
409 | * Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, |
||
410 | * containing a JSON-serialized Update. |
||
411 | * In case of an unsuccessful request, we will give up after a reasonable amount of attempts. |
||
412 | * |
||
413 | * @param string $url HTTPS url to send updates to. Use an empty string to remove webhook integration |
||
414 | * @param \CURLFile|string $certificate Upload your public key certificate |
||
415 | * so that the root certificate in use can be checked |
||
416 | * |
||
417 | * @return string |
||
418 | * |
||
419 | * @throws \TelegramBot\Api\Exception |
||
420 | */ |
||
421 | public function setWebhook($url = '', $certificate = null) |
||
425 | |||
426 | /** |
||
427 | * A simple method for testing your bot's auth token.Requires no parameters. |
||
428 | * Returns basic information about the bot in form of a User object. |
||
429 | * |
||
430 | * @return \TelegramBot\Api\Types\User |
||
431 | * @throws \TelegramBot\Api\Exception |
||
432 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
433 | */ |
||
434 | public function getMe() |
||
438 | |||
439 | /** |
||
440 | * Use this method to receive incoming updates using long polling. |
||
441 | * An Array of Update objects is returned. |
||
442 | * |
||
443 | * Notes |
||
444 | * 1. This method will not work if an outgoing webhook is set up. |
||
445 | * 2. In order to avoid getting duplicate updates, recalculate offset after each server response. |
||
446 | * |
||
447 | * @param int $offset |
||
448 | * @param int $limit |
||
449 | * @param int $timeout |
||
450 | * |
||
451 | * @return Update[] |
||
452 | * @throws \TelegramBot\Api\Exception |
||
453 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
454 | */ |
||
455 | 2 | public function getUpdates($offset = 0, $limit = 100, $timeout = 0) |
|
471 | |||
472 | /** |
||
473 | * Use this method to send point on the map. On success, the sent Message is returned. |
||
474 | * |
||
475 | * @param int $chatId |
||
476 | * @param float $latitude |
||
477 | * @param float $longitude |
||
478 | * @param int|null $replyToMessageId |
||
479 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
480 | * @param bool $disableNotification |
||
481 | * |
||
482 | * @return \TelegramBot\Api\Types\Message |
||
483 | * @throws \TelegramBot\Api\Exception |
||
484 | */ |
||
485 | View Code Duplication | public function sendLocation( |
|
502 | |||
503 | /** |
||
504 | * Use this method to send information about a venue. On success, the sent Message is returned. |
||
505 | * |
||
506 | * @param int|string $chatId chat_id or @channel_name |
||
507 | * @param float $latitude |
||
508 | * @param float $longitude |
||
509 | * @param string $title |
||
510 | * @param string $address |
||
511 | * @param string|null $foursquareId |
||
512 | * @param int|null $replyToMessageId |
||
513 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
514 | * @param bool $disableNotification |
||
515 | * |
||
516 | * @return \TelegramBot\Api\Types\Message |
||
517 | * @throws \TelegramBot\Api\Exception |
||
518 | */ |
||
519 | public function sendVenue( |
||
542 | |||
543 | /** |
||
544 | * Use this method to send .webp stickers. On success, the sent Message is returned. |
||
545 | * |
||
546 | * @param int|string $chatId chat_id or @channel_name |
||
547 | * @param \CURLFile|string $sticker |
||
548 | * @param int|null $replyToMessageId |
||
549 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
550 | * @param bool $disableNotification |
||
551 | * |
||
552 | * @return \TelegramBot\Api\Types\Message |
||
553 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
554 | * @throws \TelegramBot\Api\Exception |
||
555 | */ |
||
556 | View Code Duplication | public function sendSticker( |
|
571 | |||
572 | /** |
||
573 | * Use this method to send video files, |
||
574 | * Telegram clients support mp4 videos (other formats may be sent as Document). |
||
575 | * On success, the sent Message is returned. |
||
576 | * |
||
577 | * @param int|string $chatId chat_id or @channel_name |
||
578 | * @param \CURLFile|string $video |
||
579 | * @param int|null $duration |
||
580 | * @param string|null $caption |
||
581 | * @param int|null $replyToMessageId |
||
582 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
583 | * @param bool $disableNotification |
||
584 | * |
||
585 | * @return \TelegramBot\Api\Types\Message |
||
586 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
587 | * @throws \TelegramBot\Api\Exception |
||
588 | */ |
||
589 | public function sendVideo( |
||
608 | |||
609 | /** |
||
610 | * Use this method to send audio files, |
||
611 | * if you want Telegram clients to display the file as a playable voice message. |
||
612 | * For this to work, your audio must be in an .ogg file encoded with OPUS |
||
613 | * (other formats may be sent as Audio or Document). |
||
614 | * On success, the sent Message is returned. |
||
615 | * Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. |
||
616 | * |
||
617 | * @param int|string $chatId chat_id or @channel_name |
||
618 | * @param \CURLFile|string $voice |
||
619 | * @param int|null $duration |
||
620 | * @param int|null $replyToMessageId |
||
621 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
622 | * @param bool $disableNotification |
||
623 | * |
||
624 | * @return \TelegramBot\Api\Types\Message |
||
625 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
626 | * @throws \TelegramBot\Api\Exception |
||
627 | */ |
||
628 | View Code Duplication | public function sendVoice( |
|
645 | |||
646 | /** |
||
647 | * Use this method to forward messages of any kind. On success, the sent Message is returned. |
||
648 | * |
||
649 | * @param int|string $chatId chat_id or @channel_name |
||
650 | * @param int $fromChatId |
||
651 | * @param int $messageId |
||
652 | * @param bool $disableNotification |
||
653 | * |
||
654 | * @return \TelegramBot\Api\Types\Message |
||
655 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
656 | * @throws \TelegramBot\Api\Exception |
||
657 | */ |
||
658 | public function forwardMessage($chatId, $fromChatId, $messageId, $disableNotification = false) |
||
667 | |||
668 | /** |
||
669 | * Use this method to send audio files, |
||
670 | * if you want Telegram clients to display them in the music player. |
||
671 | * Your audio must be in the .mp3 format. |
||
672 | * On success, the sent Message is returned. |
||
673 | * Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. |
||
674 | * |
||
675 | * For backward compatibility, when the fields title and performer are both empty |
||
676 | * and the mime-type of the file to be sent is not audio/mpeg, the file will be sent as a playable voice message. |
||
677 | * For this to work, the audio must be in an .ogg file encoded with OPUS. |
||
678 | * This behavior will be phased out in the future. For sending voice messages, use the sendVoice method instead. |
||
679 | * |
||
680 | * @deprecated since 20th February. Removed backward compatibility from the method sendAudio. |
||
681 | * Voice messages now must be sent using the method sendVoice. |
||
682 | * There is no more need to specify a non-empty title or performer while sending the audio by file_id. |
||
683 | * |
||
684 | * @param int|string $chatId chat_id or @channel_name |
||
685 | * @param \CURLFile|string $audio |
||
686 | * @param int|null $duration |
||
687 | * @param string|null $performer |
||
688 | * @param string|null $title |
||
689 | * @param int|null $replyToMessageId |
||
690 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
691 | * @param bool $disableNotification |
||
692 | * |
||
693 | * @return \TelegramBot\Api\Types\Message |
||
694 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
695 | * @throws \TelegramBot\Api\Exception |
||
696 | */ |
||
697 | public function sendAudio( |
||
718 | |||
719 | /** |
||
720 | * Use this method to send photos. On success, the sent Message is returned. |
||
721 | * |
||
722 | * @param int|string $chatId chat_id or @channel_name |
||
723 | * @param \CURLFile|string $photo |
||
724 | * @param string|null $caption |
||
725 | * @param int|null $replyToMessageId |
||
726 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
727 | * @param bool $disableNotification |
||
728 | * |
||
729 | * @return \TelegramBot\Api\Types\Message |
||
730 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
731 | * @throws \TelegramBot\Api\Exception |
||
732 | */ |
||
733 | View Code Duplication | public function sendPhoto( |
|
750 | |||
751 | /** |
||
752 | * Use this method to send general files. On success, the sent Message is returned. |
||
753 | * Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. |
||
754 | * |
||
755 | * @param int|string $chatId chat_id or @channel_name |
||
756 | * @param \CURLFile|string $document |
||
757 | * @param string|null $caption |
||
758 | * @param int|null $replyToMessageId |
||
759 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
760 | * @param bool $disableNotification |
||
761 | * |
||
762 | * @return \TelegramBot\Api\Types\Message |
||
763 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
764 | * @throws \TelegramBot\Api\Exception |
||
765 | */ |
||
766 | View Code Duplication | public function sendDocument( |
|
783 | |||
784 | /** |
||
785 | * Use this method to get basic info about a file and prepare it for downloading. |
||
786 | * For the moment, bots can download files of up to 20MB in size. |
||
787 | * On success, a File object is returned. |
||
788 | * The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, |
||
789 | * where <file_path> is taken from the response. |
||
790 | * It is guaranteed that the link will be valid for at least 1 hour. |
||
791 | * When the link expires, a new one can be requested by calling getFile again. |
||
792 | * |
||
793 | * @param $fileId |
||
794 | * |
||
795 | * @return \TelegramBot\Api\Types\File |
||
796 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
797 | * @throws \TelegramBot\Api\Exception |
||
798 | */ |
||
799 | public function getFile($fileId) |
||
803 | |||
804 | /** |
||
805 | * Get file contents via cURL |
||
806 | * |
||
807 | * @param $fileId |
||
808 | * |
||
809 | * @return string |
||
810 | * |
||
811 | * @throws \TelegramBot\Api\HttpException |
||
812 | */ |
||
813 | public function downloadFile($fileId) |
||
825 | |||
826 | /** |
||
827 | * Use this method to send answers to an inline query. On success, True is returned. |
||
828 | * No more than 50 results per query are allowed. |
||
829 | * |
||
830 | * @param string $inlineQueryId |
||
831 | * @param AbstractInlineQueryResult[] $results |
||
832 | * @param int $cacheTime |
||
833 | * @param bool $isPersonal |
||
834 | * @param string $nextOffset |
||
835 | * @param string $switchPmText |
||
836 | * @param string $switchPmParameter |
||
837 | * |
||
838 | * @return mixed |
||
839 | * @throws Exception |
||
840 | */ |
||
841 | public function answerInlineQuery( |
||
865 | |||
866 | /** |
||
867 | * Use this method to kick a user from a group or a supergroup. |
||
868 | * In the case of supergroups, the user will not be able to return to the group |
||
869 | * on their own using invite links, etc., unless unbanned first. |
||
870 | * The bot must be an administrator in the group for this to work. Returns True on success. |
||
871 | * |
||
872 | * @param int|string $chatId Unique identifier for the target group |
||
873 | * or username of the target supergroup (in the format @supergroupusername) |
||
874 | * @param int $userId Unique identifier of the target user |
||
875 | * @param null|int $untilDate Date when the user will be unbanned, unix time. |
||
876 | * If user is banned for more than 366 days or less than 30 seconds from the current time |
||
877 | * they are considered to be banned forever |
||
878 | * |
||
879 | * @return bool |
||
880 | */ |
||
881 | public function kickChatMember($chatId, $userId, $untilDate = null) |
||
889 | |||
890 | /** |
||
891 | * Use this method to unban a previously kicked user in a supergroup. |
||
892 | * The user will not return to the group automatically, but will be able to join via link, etc. |
||
893 | * The bot must be an administrator in the group for this to work. Returns True on success. |
||
894 | * |
||
895 | * @param int|string $chatId Unique identifier for the target group |
||
896 | * or username of the target supergroup (in the format @supergroupusername) |
||
897 | * @param int $userId Unique identifier of the target user |
||
898 | * |
||
899 | * @return bool |
||
900 | */ |
||
901 | public function unbanChatMember($chatId, $userId) |
||
908 | |||
909 | /** |
||
910 | * Use this method to send answers to callback queries sent from inline keyboards. |
||
911 | * The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. |
||
912 | * |
||
913 | * @param $callbackQueryId |
||
914 | * @param null $text |
||
915 | * @param bool $showAlert |
||
916 | * |
||
917 | * @return bool |
||
918 | */ |
||
919 | public function answerCallbackQuery($callbackQueryId, $text = null, $showAlert = false) |
||
927 | |||
928 | |||
929 | /** |
||
930 | * Use this method to edit text messages sent by the bot or via the bot |
||
931 | * |
||
932 | * @param int|string $chatId |
||
933 | * @param int $messageId |
||
934 | * @param string $text |
||
935 | * @param string $inlineMessageId |
||
936 | * @param string|null $parseMode |
||
937 | * @param bool $disablePreview |
||
938 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
939 | * @return Message |
||
940 | */ |
||
941 | View Code Duplication | public function editMessageText( |
|
960 | |||
961 | /** |
||
962 | * Use this method to edit text messages sent by the bot or via the bot |
||
963 | * |
||
964 | * @param int|string $chatId |
||
965 | * @param int $messageId |
||
966 | * @param string|null $caption |
||
967 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
968 | * @param string $inlineMessageId |
||
969 | * |
||
970 | * @return \TelegramBot\Api\Types\Message |
||
971 | * @throws \TelegramBot\Api\InvalidArgumentException |
||
972 | * @throws \TelegramBot\Api\Exception |
||
973 | */ |
||
974 | public function editMessageCaption( |
||
989 | |||
990 | /** |
||
991 | * Use this method to edit only the reply markup of messages sent by the bot or via the bot |
||
992 | * |
||
993 | * @param int|string $chatId |
||
994 | * @param int $messageId |
||
995 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
996 | * @param string $inlineMessageId |
||
997 | * |
||
998 | * @return Message |
||
999 | */ |
||
1000 | View Code Duplication | public function editMessageReplyMarkup( |
|
1013 | |||
1014 | /** |
||
1015 | * Use this method to delete a message, including service messages, with the following limitations: |
||
1016 | * - A message can only be deleted if it was sent less than 48 hours ago. |
||
1017 | * - Bots can delete outgoing messages in groups and supergroups. |
||
1018 | * - Bots granted can_post_messages permissions can delete outgoing messages in channels. |
||
1019 | * - If the bot is an administrator of a group, it can delete any message there. |
||
1020 | * - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. |
||
1021 | * |
||
1022 | * @param int|string $chatId |
||
1023 | * @param int $messageId |
||
1024 | * |
||
1025 | * @return bool |
||
1026 | */ |
||
1027 | public function deleteMessage($chatId, $messageId) |
||
1034 | |||
1035 | /** |
||
1036 | * Close curl |
||
1037 | */ |
||
1038 | 9 | public function __destruct() |
|
1042 | |||
1043 | /** |
||
1044 | * @return string |
||
1045 | */ |
||
1046 | public function getUrl() |
||
1050 | |||
1051 | /** |
||
1052 | * @return string |
||
1053 | */ |
||
1054 | public function getFileUrl() |
||
1058 | |||
1059 | /** |
||
1060 | * @param \TelegramBot\Api\Types\Update $update |
||
1061 | * @param string $eventName |
||
1062 | * |
||
1063 | * @throws \TelegramBot\Api\Exception |
||
1064 | */ |
||
1065 | public function trackUpdate(Update $update, $eventName = 'Message') |
||
1077 | |||
1078 | /** |
||
1079 | * Wrapper for tracker |
||
1080 | * |
||
1081 | * @param \TelegramBot\Api\Types\Message $message |
||
1082 | * @param string $eventName |
||
1083 | * |
||
1084 | * @throws \TelegramBot\Api\Exception |
||
1085 | */ |
||
1086 | public function track(Message $message, $eventName = 'Message') |
||
1092 | |||
1093 | /** |
||
1094 | * Use this method to send invoices. On success, the sent Message is returned. |
||
1095 | * |
||
1096 | * @param int|string $chatId |
||
1097 | * @param string $title |
||
1098 | * @param string $description |
||
1099 | * @param string $payload |
||
1100 | * @param string $providerToken |
||
1101 | * @param string $startParameter |
||
1102 | * @param string $currency |
||
1103 | * @param array $prices |
||
1104 | * @param string|null $photoUrl |
||
1105 | * @param int|null $photoSize |
||
1106 | * @param int|null $photoWidth |
||
1107 | * @param int|null $photoHeight |
||
1108 | * @param bool $needName |
||
1109 | * @param bool $needPhoneNumber |
||
1110 | * @param bool $needEmail |
||
1111 | * @param bool $needShippingAddress |
||
1112 | * @param bool $isFlexible |
||
1113 | * @param int|null $replyToMessageId |
||
1114 | * @param Types\ReplyKeyboardMarkup|Types\ReplyKeyboardHide|Types\ForceReply|null $replyMarkup |
||
1115 | * @param bool $disableNotification |
||
1116 | * |
||
1117 | * @return Message |
||
1118 | */ |
||
1119 | public function sendInvoice( |
||
1164 | |||
1165 | /** |
||
1166 | * If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API |
||
1167 | * will send an Update with a shipping_query field to the bot. Use this method to reply to shipping queries. |
||
1168 | * On success, True is returned. |
||
1169 | * |
||
1170 | * @param string $shippingQueryId |
||
1171 | * @param bool $ok |
||
1172 | * @param array $shipping_options |
||
1173 | * @param null|string $errorMessage |
||
1174 | * |
||
1175 | * @return bool |
||
1176 | * |
||
1177 | */ |
||
1178 | public function answerShippingQuery($shippingQueryId, $ok = true, $shipping_options = [], $errorMessage = null) |
||
1187 | |||
1188 | /** |
||
1189 | * Use this method to respond to such pre-checkout queries. On success, True is returned. |
||
1190 | * Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent. |
||
1191 | * |
||
1192 | * @param string $preCheckoutQueryId |
||
1193 | * @param bool $ok |
||
1194 | * @param null|string $errorMessage |
||
1195 | * |
||
1196 | * @return mixed |
||
1197 | */ |
||
1198 | public function answerPreCheckoutQuery($preCheckoutQueryId, $ok = true, $errorMessage = null) |
||
1206 | |||
1207 | /** |
||
1208 | * Use this method to restrict a user in a supergroup. |
||
1209 | * The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. |
||
1210 | * Pass True for all boolean parameters to lift restrictions from a user. |
||
1211 | * |
||
1212 | * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup |
||
1213 | * (in the format @supergroupusername) |
||
1214 | * @param int $userId Unique identifier of the target user |
||
1215 | * @param null|integer $untilDate Date when restrictions will be lifted for the user, unix time. |
||
1216 | * If user is restricted for more than 366 days or less than 30 seconds from the current time, |
||
1217 | * they are considered to be restricted forever |
||
1218 | * @param bool $canSendMessages Pass True, if the user can send text messages, contacts, locations and venues |
||
1219 | * @param bool $canSendMediaMessages No Pass True, if the user can send audios, documents, photos, videos, |
||
1220 | * video notes and voice notes, implies can_send_messages |
||
1221 | * @param bool $canSendOtherMessages Pass True, if the user can send animations, games, stickers and |
||
1222 | * use inline bots, implies can_send_media_messages |
||
1223 | * @param bool $canAddWebPagePreviews Pass True, if the user may add web page previews to their messages, |
||
1224 | * implies can_send_media_messages |
||
1225 | * |
||
1226 | * @return bool |
||
1227 | */ |
||
1228 | public function restrictChatMember( |
||
1247 | |||
1248 | /** |
||
1249 | * Use this method to promote or demote a user in a supergroup or a channel. |
||
1250 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1251 | * Pass False for all boolean parameters to demote a user. |
||
1252 | * |
||
1253 | * @param string|int $chatId Unique identifier for the target chat or username of the target supergroup |
||
1254 | * (in the format @supergroupusername) |
||
1255 | * @param int $userId Unique identifier of the target user |
||
1256 | * @param bool $canChangeInfo Pass True, if the administrator can change chat title, photo and other settings |
||
1257 | * @param bool $canPostMessages Pass True, if the administrator can create channel posts, channels only |
||
1258 | * @param bool $canEditMessages Pass True, if the administrator can edit messages of other users, channels only |
||
1259 | * @param bool $canDeleteMessages Pass True, if the administrator can delete messages of other users |
||
1260 | * @param bool $canInviteUsers Pass True, if the administrator can invite new users to the chat |
||
1261 | * @param bool $canRestrictMembers Pass True, if the administrator can restrict, ban or unban chat members |
||
1262 | * @param bool $canPinMessages Pass True, if the administrator can pin messages, supergroups only |
||
1263 | * @param bool $canPromoteMembers Pass True, if the administrator can add new administrators with a subset of his |
||
1264 | * own privileges or demote administrators that he has promoted,directly or |
||
1265 | * indirectly (promoted by administrators that were appointed by him) |
||
1266 | * |
||
1267 | * @return bool |
||
1268 | */ |
||
1269 | public function promoteChatMember( |
||
1294 | |||
1295 | /** |
||
1296 | * Use this method to export an invite link to a supergroup or a channel. |
||
1297 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1298 | * |
||
1299 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1300 | * (in the format @channelusername) |
||
1301 | * @return string |
||
1302 | */ |
||
1303 | public function exportChatInviteLink($chatId) |
||
1309 | |||
1310 | /** |
||
1311 | * Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. |
||
1312 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1313 | * |
||
1314 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1315 | * (in the format @channelusername) |
||
1316 | * @param \CURLFile|string $photo New chat photo, uploaded using multipart/form-data |
||
1317 | * |
||
1318 | * @return bool |
||
1319 | */ |
||
1320 | public function setChatPhoto($chatId, $photo) |
||
1327 | |||
1328 | /** |
||
1329 | * Use this method to delete a chat photo. Photos can't be changed for private chats. |
||
1330 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1331 | * |
||
1332 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1333 | * (in the format @channelusername) |
||
1334 | * |
||
1335 | * @return bool |
||
1336 | */ |
||
1337 | public function deleteChatPhoto($chatId) |
||
1343 | |||
1344 | /** |
||
1345 | * Use this method to change the title of a chat. Titles can't be changed for private chats. |
||
1346 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1347 | * |
||
1348 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1349 | * (in the format @channelusername) |
||
1350 | * @param string $title New chat title, 1-255 characters |
||
1351 | * |
||
1352 | * @return bool |
||
1353 | */ |
||
1354 | public function setChatTitle($chatId, $title) |
||
1361 | |||
1362 | /** |
||
1363 | * Use this method to change the description of a supergroup or a channel. |
||
1364 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1365 | * |
||
1366 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1367 | * (in the format @channelusername) |
||
1368 | * @param string|null $description New chat description, 0-255 characters |
||
1369 | * |
||
1370 | * @return bool |
||
1371 | */ |
||
1372 | public function setChatDescription($chatId, $description = null) |
||
1379 | |||
1380 | /** |
||
1381 | * Use this method to pin a message in a supergroup. |
||
1382 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1383 | * |
||
1384 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1385 | * (in the format @channelusername) |
||
1386 | * @param int $messageId Identifier of a message to pin |
||
1387 | * @param bool $disableNotification |
||
1388 | * |
||
1389 | * @return bool |
||
1390 | */ |
||
1391 | public function pinChatMessage($chatId, $messageId, $disableNotification = false) |
||
1399 | |||
1400 | /** |
||
1401 | * Use this method to unpin a message in a supergroup chat. |
||
1402 | * The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. |
||
1403 | * |
||
1404 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1405 | * (in the format @channelusername) |
||
1406 | * |
||
1407 | * @return bool |
||
1408 | */ |
||
1409 | public function unpinChatMessage($chatId) |
||
1415 | |||
1416 | /** |
||
1417 | * Use this method to get up to date information about the chat |
||
1418 | * (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). |
||
1419 | * |
||
1420 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1421 | * (in the format @channelusername) |
||
1422 | * |
||
1423 | * @return Chat |
||
1424 | */ |
||
1425 | public function getChat($chatId) |
||
1431 | |||
1432 | /** |
||
1433 | * Use this method to get information about a member of a chat. |
||
1434 | * |
||
1435 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1436 | * (in the format @channelusername) |
||
1437 | * @param int $userId |
||
1438 | * |
||
1439 | * @return ChatMember |
||
1440 | */ |
||
1441 | public function getChatMember($chatId, $userId) |
||
1448 | |||
1449 | /** |
||
1450 | * Use this method for your bot to leave a group, supergroup or channel. |
||
1451 | * |
||
1452 | * @param string|int $chatId Unique identifier for the target chat or username of the target channel |
||
1453 | * (in the format @channelusername) |
||
1454 | * |
||
1455 | * @return bool |
||
1456 | */ |
||
1457 | public function leaveChat($chatId) |
||
1463 | } |
||
1464 |