Feat: mention getUpdates in docs

This commit is contained in:
Alexander Pankratov 2023-07-09 22:40:54 +02:00
parent 3c35d24129
commit 040f3472a3
3 changed files with 91 additions and 10 deletions

View File

@ -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` * 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 ## 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. ### Uploading files.
There are few options to upload and send media files: There are few options to upload and send media files:

77
composer.lock generated
View File

@ -2506,12 +2506,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/danog/MadelineProto.git", "url": "https://github.com/danog/MadelineProto.git",
"reference": "a157f277c15a793773a936c1882c2976bce955b9" "reference": "8fd4aa7e2d7e6b9bd201ac5f0717438740e5725d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/danog/MadelineProto/zipball/a157f277c15a793773a936c1882c2976bce955b9", "url": "https://api.github.com/repos/danog/MadelineProto/zipball/8fd4aa7e2d7e6b9bd201ac5f0717438740e5725d",
"reference": "a157f277c15a793773a936c1882c2976bce955b9", "reference": "8fd4aa7e2d7e6b9bd201ac5f0717438740e5725d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2544,6 +2544,7 @@
"ext-xml": "*", "ext-xml": "*",
"ext-zlib": "*", "ext-zlib": "*",
"league/uri": "^6", "league/uri": "^6",
"nikic/php-parser": "^4.16",
"php-64bit": ">=8.1", "php-64bit": ">=8.1",
"phpseclib/phpseclib": "^3", "phpseclib/phpseclib": "^3",
"psr/http-factory": "^1.0", "psr/http-factory": "^1.0",
@ -2627,7 +2628,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2023-07-04T17:48:23+00:00" "time": "2023-07-09T16:42:42+00:00"
}, },
{ {
"name": "danog/primemodule", "name": "danog/primemodule",
@ -3427,6 +3428,62 @@
}, },
"time": "2018-02-13T20:26:39+00:00" "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", "name": "paragonie/constant_time_encoding",
"version": "v2.6.3", "version": "v2.6.3",
@ -3621,16 +3678,16 @@
}, },
{ {
"name": "phpseclib/phpseclib", "name": "phpseclib/phpseclib",
"version": "3.0.20", "version": "3.0.21",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpseclib/phpseclib.git", "url": "https://github.com/phpseclib/phpseclib.git",
"reference": "543a1da81111a0bfd6ae7bbc2865c5e89ed3fc67" "reference": "4580645d3fc05c189024eb3b834c6c1e4f0f30a1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/543a1da81111a0bfd6ae7bbc2865c5e89ed3fc67", "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/4580645d3fc05c189024eb3b834c6c1e4f0f30a1",
"reference": "543a1da81111a0bfd6ae7bbc2865c5e89ed3fc67", "reference": "4580645d3fc05c189024eb3b834c6c1e4f0f30a1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3711,7 +3768,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/phpseclib/phpseclib/issues", "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": [ "funding": [
{ {
@ -3727,7 +3784,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-06-13T06:30:34+00:00" "time": "2023-07-09T15:24:48+00:00"
}, },
{ {
"name": "psr/http-factory", "name": "psr/http-factory",

View File

@ -517,4 +517,16 @@ class ApiExtensions
Client::getWrapper($this->madelineProto)->getAPI()->setEventHandler(EventHandler::class); 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);
}
} }