From 040f3472a38bd3066d7987a14e438f9f60bb2539 Mon Sep 17 00:00:00 2001 From: Alexander Pankratov Date: Sun, 9 Jul 2023 22:40:54 +0200 Subject: [PATCH] Feat: mention getUpdates in docs --- README.md | 12 +++ composer.lock | 77 ++++++++++++++++--- src/MadelineProtoExtensions/ApiExtensions.php | 12 +++ 3 files changed, 91 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 61e37a9..b4a5629 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,18 @@ docker compose pull * copy message from one channel to another (not repost): `http://127.0.0.1:9503/api/copyMessages/?data[from_peer]=@xtrime&data[to_peer]=@xtrime&data[id][0]=1` ## Advanced features +### 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. 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. There are few options to upload and send media files: diff --git a/composer.lock b/composer.lock index 441b424..898b2d9 100644 --- a/composer.lock +++ b/composer.lock @@ -2506,12 +2506,12 @@ "source": { "type": "git", "url": "https://github.com/danog/MadelineProto.git", - "reference": "a157f277c15a793773a936c1882c2976bce955b9" + "reference": "8fd4aa7e2d7e6b9bd201ac5f0717438740e5725d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/danog/MadelineProto/zipball/a157f277c15a793773a936c1882c2976bce955b9", - "reference": "a157f277c15a793773a936c1882c2976bce955b9", + "url": "https://api.github.com/repos/danog/MadelineProto/zipball/8fd4aa7e2d7e6b9bd201ac5f0717438740e5725d", + "reference": "8fd4aa7e2d7e6b9bd201ac5f0717438740e5725d", "shasum": "" }, "require": { @@ -2544,6 +2544,7 @@ "ext-xml": "*", "ext-zlib": "*", "league/uri": "^6", + "nikic/php-parser": "^4.16", "php-64bit": ">=8.1", "phpseclib/phpseclib": "^3", "psr/http-factory": "^1.0", @@ -2627,7 +2628,7 @@ "type": "github" } ], - "time": "2023-07-04T17:48:23+00:00" + "time": "2023-07-09T16:42:42+00:00" }, { "name": "danog/primemodule", @@ -3427,6 +3428,62 @@ }, "time": "2018-02-13T20:26:39+00:00" }, + { + "name": "nikic/php-parser", + "version": "v4.16.0", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "19526a33fb561ef417e822e85f08a00db4059c17" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/19526a33fb561ef417e822e85f08a00db4059c17", + "reference": "19526a33fb561ef417e822e85f08a00db4059c17", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.16.0" + }, + "time": "2023-06-25T14:52:30+00:00" + }, { "name": "paragonie/constant_time_encoding", "version": "v2.6.3", @@ -3621,16 +3678,16 @@ }, { "name": "phpseclib/phpseclib", - "version": "3.0.20", + "version": "3.0.21", "source": { "type": "git", "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "543a1da81111a0bfd6ae7bbc2865c5e89ed3fc67" + "reference": "4580645d3fc05c189024eb3b834c6c1e4f0f30a1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/543a1da81111a0bfd6ae7bbc2865c5e89ed3fc67", - "reference": "543a1da81111a0bfd6ae7bbc2865c5e89ed3fc67", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/4580645d3fc05c189024eb3b834c6c1e4f0f30a1", + "reference": "4580645d3fc05c189024eb3b834c6c1e4f0f30a1", "shasum": "" }, "require": { @@ -3711,7 +3768,7 @@ ], "support": { "issues": "https://github.com/phpseclib/phpseclib/issues", - "source": "https://github.com/phpseclib/phpseclib/tree/3.0.20" + "source": "https://github.com/phpseclib/phpseclib/tree/3.0.21" }, "funding": [ { @@ -3727,7 +3784,7 @@ "type": "tidelift" } ], - "time": "2023-06-13T06:30:34+00:00" + "time": "2023-07-09T15:24:48+00:00" }, { "name": "psr/http-factory", diff --git a/src/MadelineProtoExtensions/ApiExtensions.php b/src/MadelineProtoExtensions/ApiExtensions.php index 19fd221..a2f2ed5 100644 --- a/src/MadelineProtoExtensions/ApiExtensions.php +++ b/src/MadelineProtoExtensions/ApiExtensions.php @@ -517,4 +517,16 @@ class ApiExtensions Client::getWrapper($this->madelineProto)->getAPI()->setEventHandler(EventHandler::class); } + public function getUpdates(array $params): array { + foreach ($params as $key => $value) { + $params[$key] = match($key) { + 'offset', 'limit' => (int) $value, + 'timeout' => (float) $value, + default => throw new \InvalidArgumentException("Unknown parameter: {$key}"), + }; + } + + return $this->madelineProto->getUpdates($params); + } + } \ No newline at end of file