Add async echo
This commit is contained in:
parent
1e24296268
commit
3a4325f691
42
CHANGELOG.md
42
CHANGELOG.md
@ -25,15 +25,15 @@ Just `yield $MadelineProto->messages->sendMessage` instead of `$MadelineProto->m
|
|||||||
|
|
||||||
And now, on to the **API changes**:
|
And now, on to the **API changes**:
|
||||||
* First of all, we've got several bucketloads of telegram API changes, that can be viewed in the first posts.
|
* First of all, we've got several bucketloads of telegram API changes, that can be viewed in the first posts.
|
||||||
* Dropped support for PHP 5 and PHP 7.0: these versions of PHP have [officially reached their EOL](http://php.net/eol.php), so MadelineProto will not support them anymore.
|
* **Very important**, I wrote [documentation](https://docs.madelineproto.xyz/docs/LOGIN.html#getting-permission-to-use-the-telegram-api) on what to do if your account gets banned. * Dropped support for PHP 5 and PHP 7.0: these versions of PHP have [officially reached their EOL](http://php.net/eol.php), so MadelineProto will not support them anymore.
|
||||||
You can use MadelineProto with PHP 7.3 (or PHP 7.2, PHP 7.1 is supported but not recommended).
|
You should use MadelineProto with PHP 7.3 (or PHP 7.2; PHP 7.1 is supported but not recommended).
|
||||||
* **Dropped support for get_updates**: it won't work properly on async, and I really recommend you stop using it
|
* **Dropped support for get_updates**: it won't work properly on async, and I really recommend you stop using it
|
||||||
* You can now use the `@support` username in sendMessage and other methods to send messages to the support user!
|
* You can now use the `@support` username in sendMessage and other methods to send messages to the support user!
|
||||||
* Now MadelineProto will automatically try to get the access hash of users not present in the internal peer database (this should reduce errors)!
|
* Now MadelineProto will automatically try to get the access hash of users not present in the internal peer database (this should reduce errors)!
|
||||||
* If any file cannot be downloaded to due issues with the tg media server that is hosting it, it will be automatically sent to the `@support` user ([settings](https://docs.madelineproto.xyz/docs/SETTINGS.html#settingsdownloadreport_broken_media)).
|
* If any file cannot be downloaded to due issues with the tg media server that is hosting it, it will be automatically sent to the `@support` user ([settings](https://docs.madelineproto.xyz/docs/SETTINGS.html#settingsdownloadreport_broken_media)).
|
||||||
* Documented the [MyTelegramOrgWrapper](https://docs.madelineproto.xyz/docs/LOGIN.html#api-id) API, that can be used to login programmaticaly to the [my.telegram.org](https://my.telegram.org management page).
|
* Documented the [MyTelegramOrgWrapper](https://docs.madelineproto.xyz/docs/LOGIN.html#api-id) API, that can be used to login programmaticaly to the [my.telegram.org](https://my.telegram.org management page).
|
||||||
* Added an [update_2fa](https://docs.madelineproto.xyz/update_2fa.html) method to update the login password
|
* Added an [update_2fa](https://docs.madelineproto.xyz/update_2fa.html) method to update the login password
|
||||||
* Added a [get_full_dialogs](https://docs.madelineproto.xyz/docs/DIALOGS.html#get_full_dialogs-now-fully-async) method to get a full list of all chats you’re member of, including dialog info (such as the pinned/last message ID, unread count, tag count, notification settings and message drafts).
|
* Added a [get_full_dialogs](https://docs.madelineproto.xyz/docs/DIALOGS.html#get_full_dialogs-now-fully-async) method to get a full list of all chats you’re member of, including **dialog info** (such as the pinned/last message ID, unread count, tag count, notification settings and message drafts).
|
||||||
* [Added support for automatic file uploads by name in secret chats (as with normal chats); you can also now send secret chat messages using the sendMessage method as if it were a normal chat](https://github.com/danog/MadelineProto/blob/master/secret_bot.php)
|
* [Added support for automatic file uploads by name in secret chats (as with normal chats); you can also now send secret chat messages using the sendMessage method as if it were a normal chat](https://github.com/danog/MadelineProto/blob/master/secret_bot.php)
|
||||||
* Added a [resetUpdateState](https://docs.madelineproto.xyz/docs/UPDATES.html#fetch-all-updates-from-the-beginning) method to reset the update state and fetch ALL updates from the beginning
|
* Added a [resetUpdateState](https://docs.madelineproto.xyz/docs/UPDATES.html#fetch-all-updates-from-the-beginning) method to reset the update state and fetch ALL updates from the beginning
|
||||||
* Improved chat message splitting algorithm (if the message you're trying to send is too long): performance improvements, and it will now notify you via the logs if there are too many entities in the logs, or if the entities are too long.
|
* Improved chat message splitting algorithm (if the message you're trying to send is too long): performance improvements, and it will now notify you via the logs if there are too many entities in the logs, or if the entities are too long.
|
||||||
@ -96,7 +96,7 @@ The update state is now stored using a custom `UpdatesState` API, that will simp
|
|||||||
Possibly the most __exciting__ thing to work on in this version of MadelineProto was the new **update management system**: I whipped it up in merely two days a few weeks ago, and it has **absolutely improved** the overall reliability of MadelineProto.
|
Possibly the most __exciting__ thing to work on in this version of MadelineProto was the new **update management system**: I whipped it up in merely two days a few weeks ago, and it has **absolutely improved** the overall reliability of MadelineProto.
|
||||||
Huge thanks to Aliaksei Levin, the developer of tdlib, for explaining to me how exactly does the MTProto update API work: he saved me a lot of time, and was really nice <3<3<3.
|
Huge thanks to Aliaksei Levin, the developer of tdlib, for explaining to me how exactly does the MTProto update API work: he saved me a lot of time, and was really nice <3<3<3.
|
||||||
|
|
||||||
While thinking of an easy way I could implement the new update system, I had an inspiration:
|
While thinking of an easy way I could implement the new update system, **I had an inspiration**:
|
||||||
|
|
||||||
I created a **unique**, **reliable**, **fast** and **extremely simple** update handling system based on [MadelineProto's loop API](https://docs.madelineproto.xyz/docs/ASYNC.html#async-loop-apis), **not present in any** other MTProto client, **not even tdlib**.
|
I created a **unique**, **reliable**, **fast** and **extremely simple** update handling system based on [MadelineProto's loop API](https://docs.madelineproto.xyz/docs/ASYNC.html#async-loop-apis), **not present in any** other MTProto client, **not even tdlib**.
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ The same cached method mapping system is also used for the **event handler**, wh
|
|||||||
***
|
***
|
||||||
|
|
||||||
And now, let's elaborate on async:
|
And now, let's elaborate on async:
|
||||||
With **MadelineProto 4.0**, each update is handled in **parallel** using a separate **thread**, and everything is done in **parallel** (even on restricted webhosts!).
|
With **MadelineProto 4.0**, each update is handled in **parallel** using a separate **thread**, and everything is done in **parallel** (even on restricted webhosts, perfect for creating **file downloader bots**!).
|
||||||
|
|
||||||
When I say **thread**, I actually mean **green thread** ([wikipedia](https://en.wikipedia.org/wiki/Green_threads)), often called **strand**.
|
When I say **thread**, I actually mean **green thread** ([wikipedia](https://en.wikipedia.org/wiki/Green_threads)), often called **strand**.
|
||||||
**Strands** are behave exactly like normal **threads**, except that they're implemented in user-space, and they're much **faster**, **more reliable**, and **do not suffer** from synchronization issues present with normal threads.
|
**Strands** are behave exactly like normal **threads**, except that they're implemented in user-space, and they're much **faster**, **more reliable**, and **do not suffer** from synchronization issues present with normal threads.
|
||||||
@ -144,34 +144,32 @@ In
|
|||||||
* async construct
|
* async construct
|
||||||
* async readline
|
* async readline
|
||||||
* async filegetco
|
* async filegetco
|
||||||
|
* async echo
|
||||||
|
|
||||||
Things to expect in the next releases:
|
Things to expect in the next releases:
|
||||||
docs for get mime funcs
|
ton
|
||||||
docs for HTML parser (div to avoid escaping)
|
video calls
|
||||||
docs for update_2fa
|
group calls
|
||||||
|
native calls
|
||||||
|
DNS over HTTPS
|
||||||
optional max_id and min_id
|
optional max_id and min_id
|
||||||
async iterators
|
async iterators
|
||||||
|
#phase1
|
||||||
|
|
||||||
|
telegram passport
|
||||||
|
get sponsor of proxies
|
||||||
|
docs for get mime funcs
|
||||||
|
docs for HTML parser
|
||||||
Method name changes
|
Method name changes
|
||||||
#MadelineProtoForNode async
|
#MadelineProtoForNode async
|
||||||
lua async
|
lua async
|
||||||
improved get_pwr_chat
|
improved get_pwr_chat
|
||||||
gzip
|
gzip
|
||||||
no defer logs
|
no defer logs
|
||||||
recover@tg docs
|
|
||||||
startedLoop docs
|
startedLoop docs
|
||||||
|
arrayaccess on promises
|
||||||
|
web files
|
||||||
no error setting, madelineproto does that for you
|
no error setting, madelineproto does that for you
|
||||||
|
|
||||||
|
tell about restart
|
||||||
do not use manual
|
|
||||||
tell about madeline.php loading in the same dire
|
tell about madeline.php loading in the same dire
|
||||||
arrayaccess on promises
|
|
||||||
get sponsor of
|
|
||||||
ton
|
|
||||||
video calls
|
|
||||||
group calls
|
|
||||||
native calls
|
|
||||||
dnssec
|
|
||||||
mytelegramorg docs
|
|
||||||
web files
|
|
||||||
telegram passport
|
|
32
README.md
32
README.md
@ -14,7 +14,7 @@ It can login with a phone number (MTProto API), or with a bot token (MTProto API
|
|||||||
|
|
||||||
[It is now fully async](https://docs.madelineproto.xyz/docs/ASYNC.html)!
|
[It is now fully async](https://docs.madelineproto.xyz/docs/ASYNC.html)!
|
||||||
|
|
||||||
## Getting started
|
## Getting started ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
|
||||||
|
|
||||||
```php
|
```php
|
||||||
<?php
|
<?php
|
||||||
@ -25,24 +25,28 @@ if (!file_exists('madeline.php')) {
|
|||||||
include 'madeline.php';
|
include 'madeline.php';
|
||||||
|
|
||||||
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
|
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
|
||||||
$MadelineProto->start();
|
$MadelineProto->async(true);
|
||||||
|
$MadelineProto->loop(function () use ($MadelineProto) {
|
||||||
|
yield $MadelineProto->start();
|
||||||
|
|
||||||
$me = $MadelineProto->get_self();
|
$me = yield $MadelineProto->get_self();
|
||||||
|
|
||||||
\danog\MadelineProto\Logger::log($me);
|
$MadelineProto->logger($me);
|
||||||
|
|
||||||
if (!$me['bot']) {
|
if (!$me['bot']) {
|
||||||
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for creating MadelineProto! <3"]);
|
yield $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for creating MadelineProto! <3"]);
|
||||||
$MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']);
|
yield $MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']);
|
yield $MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']);
|
||||||
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
} catch (\danog\MadelineProto\RPCErrorException $e) {
|
||||||
|
$MadelineProto->logger($e);
|
||||||
|
}
|
||||||
|
|
||||||
|
yield $MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']);
|
||||||
}
|
}
|
||||||
|
yield $MadelineProto->echo('OK, done!');
|
||||||
$MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']);
|
});
|
||||||
}
|
|
||||||
echo 'OK, done!'.PHP_EOL;
|
|
||||||
```
|
```
|
||||||
|
|
||||||
[Try this code now!](https://try.madelineproto.xyz) or run this code in a browser or in a console.
|
[Try this code now!](https://try.madelineproto.xyz) or run this code in a browser or in a console.
|
||||||
|
2
docs
2
docs
@ -1 +1 @@
|
|||||||
Subproject commit 67df53f4660009faa7e01fb5cfce2a9751c8ac72
|
Subproject commit 4aa913bc973371c46295b2dd6cb87ab07f8bdf1a
|
@ -30,6 +30,7 @@ use danog\MadelineProto\MTProtoTools\UpdatesState;
|
|||||||
use danog\MadelineProto\Stream\MTProtoTransport\HttpsStream;
|
use danog\MadelineProto\Stream\MTProtoTransport\HttpsStream;
|
||||||
use danog\MadelineProto\Stream\MTProtoTransport\HttpStream;
|
use danog\MadelineProto\Stream\MTProtoTransport\HttpStream;
|
||||||
use danog\MadelineProto\TL\TLCallback;
|
use danog\MadelineProto\TL\TLCallback;
|
||||||
|
use function Amp\ByteStream\getOutputBufferStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages all of the mtproto stuff.
|
* Manages all of the mtproto stuff.
|
||||||
@ -233,7 +234,6 @@ class MTProto extends AsyncConstruct implements TLCallback
|
|||||||
{
|
{
|
||||||
return $this->logger->logger(...$params);
|
return $this->logger->logger(...$params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isAltervista()
|
public function isAltervista()
|
||||||
{
|
{
|
||||||
return Magic::$altervista;
|
return Magic::$altervista;
|
||||||
|
@ -31,6 +31,7 @@ use function Amp\Promise\timeout;
|
|||||||
use function Amp\Promise\wait;
|
use function Amp\Promise\wait;
|
||||||
use function Amp\ByteStream\getStdin;
|
use function Amp\ByteStream\getStdin;
|
||||||
use function Amp\ByteStream\getStdout;
|
use function Amp\ByteStream\getStdout;
|
||||||
|
use function Amp\ByteStream\getOutputBufferStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some tools.
|
* Some tools.
|
||||||
@ -353,6 +354,11 @@ trait Tools
|
|||||||
|
|
||||||
return array_shift($lines);
|
return array_shift($lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function echo($string)
|
||||||
|
{
|
||||||
|
return getOutputBufferStream()->write($string);
|
||||||
|
}
|
||||||
public function is_array_or_alike($var)
|
public function is_array_or_alike($var)
|
||||||
{
|
{
|
||||||
return is_array($var) ||
|
return is_array($var) ||
|
||||||
|
Loading…
Reference in New Issue
Block a user