mirror of
https://github.com/danog/TelegramApiServer.git
synced 2024-11-26 20:04:45 +01:00
Api request format unification
This commit is contained in:
parent
f62f1077af
commit
d280820557
@ -98,10 +98,10 @@ Fast, simple, async php telegram client and parser: MadelineProto + Swoole Serve
|
||||
You can add client ip in .env file to `API_CLIENT_WHITELIST` (use json format)
|
||||
|
||||
Examples:
|
||||
* get_info about channel/user: `http://127.0.0.1:9503/api/getInfo/?id=@xtrime`
|
||||
* repost: `http://127.0.0.1:9503/api/forwardMessages/?fromPeer=@xtrime&toPeer=@xtrime&messageId=1234`
|
||||
* get_info about channel/user: `http://127.0.0.1:9503/api/getInfo/?data[id]=@xtrime`
|
||||
* repost: `http://127.0.0.1:9503/api/forwardMessages/?data[fromPeer]=@xtrime&data[toPeer]=@xtrime&data[messageId]=1234`
|
||||
* get messages from channel/user: `http://127.0.0.1:9503/api/getHistory/?data[peer]=@breakingmash&data[limit]=10`
|
||||
* search: `http://127.0.0.1:9503/api/searchGlobal/?q=Hello%20World&limit=10`
|
||||
* search: `http://127.0.0.1:9503/api/searchGlobal/?data[q]=Hello%20World&data[limit]=10`
|
||||
* sendMessage: `http://127.0.0.1:9503/api/sendMessage/?data[peer]=@xtrime&data[message]=Hello!`
|
||||
|
||||
**Contacts**
|
||||
|
@ -34,13 +34,21 @@ class Client {
|
||||
/**
|
||||
* Получает данные о канале/пользователе по логину
|
||||
*
|
||||
* @param array|string|id $id
|
||||
* Например логин в формате '@xtrime'
|
||||
* @param array $data
|
||||
* <pre>
|
||||
* $data = [
|
||||
* 'id' => , array|string, Например логин в формате '@xtrime'
|
||||
* ];
|
||||
* </pre>
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getInfo($id): array
|
||||
public function getInfo($data): array
|
||||
{
|
||||
return $this->MadelineProto->get_info((string)$id);
|
||||
$data = array_merge([
|
||||
'id' => '',
|
||||
], $data);
|
||||
return $this->MadelineProto->get_info($data['id']);
|
||||
}
|
||||
|
||||
|
||||
@ -81,33 +89,32 @@ class Client {
|
||||
/**
|
||||
* Пересылает сообщения
|
||||
*
|
||||
* @param string $fromPeer
|
||||
* @param string $toPeer
|
||||
* @param array|int $messageId
|
||||
* @param array $data
|
||||
* Id сообщения, или нескольких сообщений
|
||||
*/
|
||||
public function forwardMessages($fromPeer, $toPeer, $messageId): void
|
||||
public function forwardMessages($data): void
|
||||
{
|
||||
$this->MadelineProto->messages->forwardMessages([
|
||||
'from_peer' => $fromPeer,
|
||||
'to_peer' => $toPeer,
|
||||
'id' => (array) $messageId,
|
||||
]);
|
||||
$data = array_merge([
|
||||
'from_peer' => '',
|
||||
'to_peer' => '',
|
||||
'id' => [],
|
||||
],$data);
|
||||
$this->MadelineProto->messages->forwardMessages($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $q
|
||||
* @param int $limit
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
public function searchGlobal($q = '', $limit = 10): array
|
||||
public function searchGlobal(array $data): array
|
||||
{
|
||||
return $this->MadelineProto->messages->searchGlobal([
|
||||
'q' => $q,
|
||||
$data = array_merge([
|
||||
'q' => '',
|
||||
'offset_id' => 0,
|
||||
'offset_date' => 0,
|
||||
'limit' => $limit,
|
||||
]);
|
||||
'limit' => 10,
|
||||
],$data);
|
||||
return $this->MadelineProto->messages->searchGlobal($data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,6 +165,9 @@ class RequestCallback
|
||||
if (!in_array($request->server['remote_addr'], $this->ipWhiteList, true)) {
|
||||
throw new \Exception('API not available');
|
||||
}
|
||||
if (!method_exists($this->parser->client,$this->api)) {
|
||||
throw new \Exception('api not found');
|
||||
}
|
||||
$this->page['response'] = $this->parser->client->{$this->api}(...$this->parameters);
|
||||
break;
|
||||
case 'json':
|
||||
|
Loading…
Reference in New Issue
Block a user