mirror of
https://github.com/danog/TelegramApiServer.git
synced 2024-11-26 11:54:42 +01:00
Ref: remove redundant alias methods
This commit is contained in:
parent
dd9803e079
commit
79251fa81a
@ -116,7 +116,10 @@ It's recommended to use http_build_query, when using GET requests.
|
|||||||
Telegram is event driven platform. For example: every time your account receives a message you immediately get an update.
|
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:
|
There are multiple ways of [getting updates](https://docs.madelineproto.xyz/docs/UPDATES.html) in TelegramApiServer / MadelineProto:
|
||||||
1. [Websocket](#eventhandler-updates-webhooks)
|
1. [Websocket](#eventhandler-updates-webhooks)
|
||||||
2. Webhook:
|
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!
|
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 `
|
`curl "127.0.0.1:9503/api/setWebhook?url=http%3A%2F%2Fexample.com%2Fsome_webhook" -g `
|
||||||
Example uses urlencoded url in query.
|
Example uses urlencoded url in query.
|
||||||
@ -341,7 +344,6 @@ PHP websocket client example: [websocket-events.php](https://github.com/xtrime-r
|
|||||||
TelegramApiServer extends madelineProto with some handful methods.
|
TelegramApiServer extends madelineProto with some handful methods.
|
||||||
Full list of custom methods and their parameters available in [ApiExtensions class](https://github.com/xtrime-ru/TelegramApiServer/blob/master/src/MadelineProtoExtensions/ApiExtensions.php#L19)
|
Full list of custom methods and their parameters available in [ApiExtensions class](https://github.com/xtrime-ru/TelegramApiServer/blob/master/src/MadelineProtoExtensions/ApiExtensions.php#L19)
|
||||||
|
|
||||||
* `getHistory` - same as messages.getHistory, but all params exept peer is optional.
|
|
||||||
* `getHistoryHtml` - message entities converted to html
|
* `getHistoryHtml` - message entities converted to html
|
||||||
* `formatMessage` - converts entities to html
|
* `formatMessage` - converts entities to html
|
||||||
* `copyMessages` - copy message from one peer to onother. Like forwardMessages, but without the link to original.
|
* `copyMessages` - copy message from one peer to onother. Like forwardMessages, but without the link to original.
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace TelegramApiServer\Exceptions;
|
|
||||||
|
|
||||||
class MediaTooBig extends NoticeException
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -8,12 +8,10 @@ use Amp\Http\Server\FormParser\StreamedField;
|
|||||||
use Amp\Http\Server\Request;
|
use Amp\Http\Server\Request;
|
||||||
use Amp\Http\Server\Response;
|
use Amp\Http\Server\Response;
|
||||||
use danog\MadelineProto;
|
use danog\MadelineProto;
|
||||||
use danog\MadelineProto\PeerNotInDbException;
|
|
||||||
use danog\MadelineProto\StrTools;
|
use danog\MadelineProto\StrTools;
|
||||||
use http\Exception\InvalidArgumentException;
|
use http\Exception\InvalidArgumentException;
|
||||||
use TelegramApiServer\Client;
|
use TelegramApiServer\Client;
|
||||||
use TelegramApiServer\EventObservers\EventHandler;
|
use TelegramApiServer\EventObservers\EventHandler;
|
||||||
use TelegramApiServer\Exceptions\MediaTooBig;
|
|
||||||
use TelegramApiServer\Exceptions\NoMediaException;
|
use TelegramApiServer\Exceptions\NoMediaException;
|
||||||
use function Amp\delay;
|
use function Amp\delay;
|
||||||
|
|
||||||
@ -31,46 +29,9 @@ class ApiExtensions
|
|||||||
$this->file = $file;
|
$this->file = $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Получает последние сообщения из указанных каналов
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* <pre>
|
|
||||||
* [
|
|
||||||
* 'peer' => '',
|
|
||||||
* 'offset_id' => 0, // (optional)
|
|
||||||
* 'offset_date' => 0, // (optional)
|
|
||||||
* 'add_offset' => 0, // (optional)
|
|
||||||
* 'limit' => 0, // (optional)
|
|
||||||
* 'max_id' => 0, // (optional)
|
|
||||||
* 'min_id' => 0, // (optional)
|
|
||||||
* 'hash' => 0, // (optional)
|
|
||||||
* ]
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function getHistory(array $data)
|
|
||||||
{
|
|
||||||
$data = array_merge(
|
|
||||||
[
|
|
||||||
'peer' => '',
|
|
||||||
'offset_id' => 0,
|
|
||||||
'offset_date' => 0,
|
|
||||||
'add_offset' => 0,
|
|
||||||
'limit' => 0,
|
|
||||||
'max_id' => 0,
|
|
||||||
'min_id' => 0,
|
|
||||||
'hash' => [],
|
|
||||||
],
|
|
||||||
$data
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->madelineProto->messages->getHistory($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHistoryHtml(array $data): array
|
public function getHistoryHtml(array $data): array
|
||||||
{
|
{
|
||||||
$response = $this->getHistory($data);
|
$response = $this->madelineProto->messages->getHistory(...$data);
|
||||||
if (!empty($response['messages'])) {
|
if (!empty($response['messages'])) {
|
||||||
foreach ($response['messages'] as &$message) {
|
foreach ($response['messages'] as &$message) {
|
||||||
$message['message'] = $this->formatMessage($message['message'] ?? null, $message['entities'] ?? []);
|
$message['message'] = $this->formatMessage($message['message'] ?? null, $message['entities'] ?? []);
|
||||||
@ -208,9 +169,9 @@ class ApiExtensions
|
|||||||
];
|
];
|
||||||
if (static::hasMedia($message, false)) {
|
if (static::hasMedia($message, false)) {
|
||||||
$messageData['media'] = $message; //MadelineProto сама достанет все media из сообщения.
|
$messageData['media'] = $message; //MadelineProto сама достанет все media из сообщения.
|
||||||
$result[] = $this->sendMedia($messageData);
|
$result[] = $this->madelineProto->messages->sendMedia(...$messageData);
|
||||||
} else {
|
} else {
|
||||||
$result[] = $this->sendMessage($messageData);
|
$result[] = $this->madelineProto->messages->sendMessage(...$messageData);
|
||||||
}
|
}
|
||||||
if ($key > 0) {
|
if ($key > 0) {
|
||||||
delay(random_int(300, 2000) / 1000);
|
delay(random_int(300, 2000) / 1000);
|
||||||
@ -220,98 +181,6 @@ class ApiExtensions
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
* <pre>
|
|
||||||
* [
|
|
||||||
* 'peer' => '',
|
|
||||||
* 'message' => '', // Текст сообщения,
|
|
||||||
* 'media' => [], // MessageMedia, Update, Message or InputMedia
|
|
||||||
* 'reply_to_msg_id' => 0, // (optional)
|
|
||||||
* 'parse_mode' => 'HTML', // (optional)
|
|
||||||
* ]
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function sendMedia(array $data): array
|
|
||||||
{
|
|
||||||
$data = array_merge(
|
|
||||||
[
|
|
||||||
'peer' => '',
|
|
||||||
'message' => '',
|
|
||||||
'media' => [],
|
|
||||||
'reply_to_msg_id' => 0,
|
|
||||||
'parse_mode' => 'HTML',
|
|
||||||
],
|
|
||||||
$data
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!empty($this->file)) {
|
|
||||||
$data = array_merge(
|
|
||||||
$data,
|
|
||||||
$this->uploadMediaForm()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->madelineProto->messages->sendMedia(...$data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
* <pre>
|
|
||||||
* [
|
|
||||||
* 'peer' => '',
|
|
||||||
* 'message' => '', // Текст сообщения
|
|
||||||
* 'reply_to_msg_id' => 0, // (optional)
|
|
||||||
* 'parse_mode' => 'HTML', // (optional)
|
|
||||||
* ]
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function sendMessage(array $data)
|
|
||||||
{
|
|
||||||
$data = array_merge(
|
|
||||||
[
|
|
||||||
'peer' => '',
|
|
||||||
'message' => '',
|
|
||||||
'reply_to_msg_id' => 0,
|
|
||||||
'parse_mode' => 'HTML',
|
|
||||||
],
|
|
||||||
$data
|
|
||||||
);
|
|
||||||
|
|
||||||
return $this->madelineProto->messages->sendMessage($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
* <pre>
|
|
||||||
* [
|
|
||||||
* 'folder_id' => 0, // Id папки (optional)
|
|
||||||
* 'q' => '', //Поисковый запрос
|
|
||||||
* 'offset_rate' => 0, // (optional)
|
|
||||||
* 'offset_peer' => null, // (optional)
|
|
||||||
* 'offset_id' => 0, // (optional)
|
|
||||||
* 'limit' => 10, // (optional)
|
|
||||||
* ]
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function searchGlobal(array $data): array
|
|
||||||
{
|
|
||||||
$data = array_merge(
|
|
||||||
[
|
|
||||||
|
|
||||||
'q' => '',
|
|
||||||
'offset_rate' => 0,
|
|
||||||
'offset_id' => 0,
|
|
||||||
'limit' => 10,
|
|
||||||
],
|
|
||||||
$data
|
|
||||||
);
|
|
||||||
return $this->madelineProto->messages->searchGlobal(...$data);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Загружает медиафайл из указанного сообщения в поток
|
* Загружает медиафайл из указанного сообщения в поток
|
||||||
*
|
*
|
||||||
@ -325,7 +194,6 @@ class ApiExtensions
|
|||||||
'peer' => '',
|
'peer' => '',
|
||||||
'id' => [0],
|
'id' => [0],
|
||||||
'message' => [],
|
'message' => [],
|
||||||
'size_limit' => 0,
|
|
||||||
],
|
],
|
||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
@ -354,11 +222,6 @@ class ApiExtensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($data['size_limit'] && $info['size'] > $data['size_limit']) {
|
|
||||||
throw new MediaTooBig(
|
|
||||||
"Media exceeds size limit. Size: {$info['size']} bytes; limit: {$data['size_limit']} bytes"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->downloadToResponse($info);
|
return $this->downloadToResponse($info);
|
||||||
}
|
}
|
||||||
@ -442,10 +305,6 @@ class ApiExtensions
|
|||||||
return $this->downloadToResponse($info);
|
return $this->downloadToResponse($info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $data
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function getMessages(array $data): array
|
public function getMessages(array $data): array
|
||||||
{
|
{
|
||||||
$peerInfo = $this->madelineProto->getInfo($data['peer']);
|
$peerInfo = $this->madelineProto->getInfo($data['peer']);
|
||||||
|
Loading…
Reference in New Issue
Block a user