diff --git a/README.md b/README.md index 36d997e..201c0b4 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,9 @@ Fast, simple, async php telegram api server: Also options can be set in .env file (see .env.example) ``` 1. Access telegram api directly with simple GET/POST requests. - - Its recommended to use http_build_query for GET requests. + + Regular and application/json POST supported. + Its recommended to use http_build_query when using GET requests. **Rules:** * All methods from MadelineProto supported: [Methods List](https://docs.madelineproto.xyz/API_docs/methods/) @@ -109,6 +110,7 @@ Fast, simple, async php telegram api server: **Examples:** * Session list: `http://127.0.0.1:9503/system/getSessionList` * Adding session: `http://127.0.0.1:9503/system/addSession?session=users/xtrime` + * [optional] Adding session with custom settings: `http://127.0.0.1:9503/system/addSession?session=users/xtrime&settings[app_info][app_id]=xxx&&settings[app_info][app_hash]=xxx` * Removing session: `http://127.0.0.1:9503/system/removeSession?session=users/xtrime` If there is no authorization in session, or session file is blank, authorization required: diff --git a/src/Client.php b/src/Client.php index 0d97309..453f364 100644 --- a/src/Client.php +++ b/src/Client.php @@ -79,10 +79,11 @@ class Client ; } - public function addSession(string $session, bool $startSession = false) + public function addSession(string $session, array $settings = []): void { $settings = (array) Config::getInstance()->get('telegram'); $file = static::getSessionFile($session); + $settings = array_replace_recursive((array) Config::getInstance()->get('telegram'), $settings); $instance = new MadelineProto\API($file, $settings); $instance->async(true); $this->instances[$session] = $instance; diff --git a/src/MadelineProtoExtensions/SystemApiExtensions.php b/src/MadelineProtoExtensions/SystemApiExtensions.php index 41e152a..1c2bdb3 100644 --- a/src/MadelineProtoExtensions/SystemApiExtensions.php +++ b/src/MadelineProtoExtensions/SystemApiExtensions.php @@ -15,9 +15,9 @@ class SystemApiExtensions $this->client = $client; } - public function addSession(string $session) + public function addSession(string $session, array $settings = []): array { - $this->client->addSession($session); + $this->client->addSession($session, $settings); return $this->getSessionList(); } diff --git a/src/Server/Server.php b/src/Server/Server.php index f9ee115..98eb429 100644 --- a/src/Server/Server.php +++ b/src/Server/Server.php @@ -30,8 +30,8 @@ class Server ->withHttp2Timeout(600) ); + $server->start(); $client->connect($sessionFiles); - yield $server->start(); $this->registerShutdown($server); });