From 79251fa81a307dcbdff86f949f44c6a16c6b742f Mon Sep 17 00:00:00 2001 From: Alexander Pankratov Date: Fri, 19 Apr 2024 00:49:15 +0200 Subject: [PATCH] Ref: remove redundant alias methods --- README.md | 14 +- src/Exceptions/MediaTooBig.php | 8 - src/MadelineProtoExtensions/ApiExtensions.php | 147 +----------------- 3 files changed, 11 insertions(+), 158 deletions(-) delete mode 100644 src/Exceptions/MediaTooBig.php diff --git a/README.md b/README.md index 8bc530e..9b8fb17 100644 --- a/README.md +++ b/README.md @@ -115,11 +115,14 @@ It's recommended to use http_build_query, when using GET requests. ### Get events/updates Telegram is event driven platform. For example: every time your account receives a message you immediately get an update. There are multiple ways of [getting updates](https://docs.madelineproto.xyz/docs/UPDATES.html) in TelegramApiServer / MadelineProto: - 1. [Websocket](#eventhandler-updates-webhooks) - 2. Webhook: - Redirect all updates to your endpoint, just like bot api! - `curl "127.0.0.1:9503/api/setWebhook?url=http%3A%2F%2Fexample.com%2Fsome_webhook" -g ` - Example uses urlencoded url in query. +1. [Websocket](#eventhandler-updates-webhooks) +2. Long Polling: +send request to getUpdates endpoint +`curl "127.0.0.1:9503/api/getUpdates?data[limit]=3&data[offset]=0&data[timeout]=10.0" -g` +3. Webhook: +Redirect all updates to your endpoint, just like bot api! +`curl "127.0.0.1:9503/api/setWebhook?url=http%3A%2F%2Fexample.com%2Fsome_webhook" -g ` +Example uses urlencoded url in query. ### Uploading files. @@ -341,7 +344,6 @@ PHP websocket client example: [websocket-events.php](https://github.com/xtrime-r TelegramApiServer extends madelineProto with some handful methods. Full list of custom methods and their parameters available in [ApiExtensions class](https://github.com/xtrime-ru/TelegramApiServer/blob/master/src/MadelineProtoExtensions/ApiExtensions.php#L19) -* `getHistory` - same as messages.getHistory, but all params exept peer is optional. * `getHistoryHtml` - message entities converted to html * `formatMessage` - converts entities to html * `copyMessages` - copy message from one peer to onother. Like forwardMessages, but without the link to original. diff --git a/src/Exceptions/MediaTooBig.php b/src/Exceptions/MediaTooBig.php deleted file mode 100644 index eedeaa3..0000000 --- a/src/Exceptions/MediaTooBig.php +++ /dev/null @@ -1,8 +0,0 @@ -file = $file; } - /** - * Получает последние сообщения из указанных каналов - * - * @param array $data - *
-     * [
-     *     'peer' => '',
-     *     'offset_id' => 0, // (optional)
-     *     'offset_date' => 0, // (optional)
-     *     'add_offset' => 0, // (optional)
-     *     'limit' => 0, // (optional)
-     *     'max_id' => 0, // (optional)
-     *     'min_id' => 0, // (optional)
-     *     'hash' => 0, // (optional)
-     * ]
-     * 
- * - */ - public function getHistory(array $data) - { - $data = array_merge( - [ - 'peer' => '', - 'offset_id' => 0, - 'offset_date' => 0, - 'add_offset' => 0, - 'limit' => 0, - 'max_id' => 0, - 'min_id' => 0, - 'hash' => [], - ], - $data - ); - - return $this->madelineProto->messages->getHistory($data); - } - public function getHistoryHtml(array $data): array { - $response = $this->getHistory($data); + $response = $this->madelineProto->messages->getHistory(...$data); if (!empty($response['messages'])) { foreach ($response['messages'] as &$message) { $message['message'] = $this->formatMessage($message['message'] ?? null, $message['entities'] ?? []); @@ -208,9 +169,9 @@ class ApiExtensions ]; if (static::hasMedia($message, false)) { $messageData['media'] = $message; //MadelineProto сама достанет все media из сообщения. - $result[] = $this->sendMedia($messageData); + $result[] = $this->madelineProto->messages->sendMedia(...$messageData); } else { - $result[] = $this->sendMessage($messageData); + $result[] = $this->madelineProto->messages->sendMessage(...$messageData); } if ($key > 0) { delay(random_int(300, 2000) / 1000); @@ -220,98 +181,6 @@ class ApiExtensions return $result; } - /** - * @param array $data - *
-     * [
-     *  'peer' => '',
-     *  'message' => '',      // Текст сообщения,
-     *  'media' => [],      // MessageMedia, Update, Message or InputMedia
-     *  'reply_to_msg_id' => 0,       // (optional)
-     *  'parse_mode' => 'HTML',  // (optional)
-     * ]
-     * 
- * - */ - public function sendMedia(array $data): array - { - $data = array_merge( - [ - 'peer' => '', - 'message' => '', - 'media' => [], - 'reply_to_msg_id' => 0, - 'parse_mode' => 'HTML', - ], - $data - ); - - if (!empty($this->file)) { - $data = array_merge( - $data, - $this->uploadMediaForm() - ); - } - - return $this->madelineProto->messages->sendMedia(...$data); - } - - /** - * @param array $data - *
-     * [
-     *  'peer' => '',
-     *  'message' => '',      // Текст сообщения
-     *  'reply_to_msg_id' => 0,       // (optional)
-     *  'parse_mode' => 'HTML',  // (optional)
-     * ]
-     * 
- * - */ - public function sendMessage(array $data) - { - $data = array_merge( - [ - 'peer' => '', - 'message' => '', - 'reply_to_msg_id' => 0, - 'parse_mode' => 'HTML', - ], - $data - ); - - return $this->madelineProto->messages->sendMessage($data); - } - - /** - * @param array $data - *
-     * [
-     *  'folder_id' => 0, // Id папки (optional)
-     *  'q'  => '',  //Поисковый запрос
-     *  'offset_rate' => 0,   // (optional)
-     *  'offset_peer' => null, // (optional)
-     *  'offset_id' => 0,   // (optional)
-     *  'limit' => 10,  // (optional)
-     * ]
-     * 
- * - */ - public function searchGlobal(array $data): array - { - $data = array_merge( - [ - - 'q' => '', - 'offset_rate' => 0, - 'offset_id' => 0, - 'limit' => 10, - ], - $data - ); - return $this->madelineProto->messages->searchGlobal(...$data); - } - /** * Загружает медиафайл из указанного сообщения в поток * @@ -325,7 +194,6 @@ class ApiExtensions 'peer' => '', 'id' => [0], 'message' => [], - 'size_limit' => 0, ], $data ); @@ -354,11 +222,6 @@ class ApiExtensions } } - if ($data['size_limit'] && $info['size'] > $data['size_limit']) { - throw new MediaTooBig( - "Media exceeds size limit. Size: {$info['size']} bytes; limit: {$data['size_limit']} bytes" - ); - } return $this->downloadToResponse($info); } @@ -442,10 +305,6 @@ class ApiExtensions return $this->downloadToResponse($info); } - /** - * @param array $data - * - */ public function getMessages(array $data): array { $peerInfo = $this->madelineProto->getInfo($data['peer']);