Skip to content

Commit

Permalink
Feat: mention getUpdates in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrime-ru committed Jul 9, 2023
1 parent 3c35d24 commit 040f347
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 10 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
77 changes: 67 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/MadelineProtoExtensions/ApiExtensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,16 @@ public function setEventHandler(): void
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);
}

}

0 comments on commit 040f347

Please sign in to comment.