Custom settings in addSession

This commit is contained in:
Alexander Pankratov 2020-02-06 02:52:47 +03:00
parent e593d5cc1d
commit 58510aca4a
4 changed files with 9 additions and 6 deletions

View File

@ -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:

View File

@ -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;

View File

@ -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();
}

View File

@ -30,8 +30,8 @@ class Server
->withHttp2Timeout(600)
);
$server->start();
$client->connect($sessionFiles);
yield $server->start();
$this->registerShutdown($server);
});