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