PWRTelegram API channel
@pwrtelegram

Official channel for the PWRTelegram bot API. Installation instructions: https://pwrtelegram.xyz Creator: @danogentili Official support group: @pwrtelegramgroup Italian channel: @pwrtelegramita Source code: https://github.com/pwrtelegram
285  
PWRTelegram API channel
2019-06-05 

About this project: PWRTelegram might come back very soon with PWRTelegram 2.0 (now asynchronous!), thanks to the help of a friend ❤️❤️❤️

PWRTelegram API channel
2019-06-05 

What do you want me to implement first?

Anonymous Poll 17% Automatic asyncification (for parallelism and maximum speed) 8% Async file upload by url (1.5gb) 12% Get direct download url of any file (1.5gb) 12% TON 5% Group calls 10% Video calls 3% Native calls 3% #MadelineProtoForNode async | lua async 7% Layer 100 24% #phase1 🇮🇷🇷🇺
PWRTelegram API channel
2019-06-05 

Not related to MadelineProto: I'm also working on a new solution to permanently bypass ISP blocks and stop telegram censorship.

This will probably interest our Russian and Iranian users)
Stay tuned on this channel for updates.
#phase1🇮🇷🇷🇺
PWRTelegram API channel
2019-06-05 

You can start reading here :). P.S. If your code still relies on the old synchronous behaviour, don't worry, there is backward compatibility.

However, old synchronous behaviour is deprecated, and I highly recommend you switch to async, due to the huge performance and parallelism benefits.
In a few weeks I will set MadelineProto 4.0 as default with madeline.php : in the meantime, I do not provide support for the old version.
PWRTelegram API channel
2019-06-05 

Finally, I must thank my test pony Mattia ( @MattiaXBL ) for testing out the async version of MadelineProto:

I stil love you, even after all the bug reports <3<3<3
PWRTelegram API channel
2019-06-05 

To use MadelineProto 4.0 w/ async, you have to load the latest version of MadelineProto from the master branch by loading it through composer ( dev-master ) or with madeline.php:

if (!file_exists('madeline.php')) {
copy(' https://phar.madelineproto.xyz/madeline.php ', 'madeline.php');
}
define('MADELINE_BRANCH', '');
include 'madeline.php';
In a few weeks I will set MadelineProto 4.0 as default with madeline.php : in the meantime, I do not provide support for the old version.
PWRTelegram API channel
2019-06-05 

MadelineProto started as a hobby project, back when I knew nothing about cryptography, telegram's APIs, async or programming standards:

before, MadelineProto was created piece by piece as a single monolothic class composed of multiple traits;
now, MadelineProto is composed of multiple modular APIs that are well-structured, heavily commented, wrappable, extendable in any possible and immaginable way.
I am really happy with how MadelineProto async turned out.
I had an absolute blast working on this update, and implementing async really opened a whole sea of possible innovations and features I can implement in MadelineProto now:
- Automatically asyncify your scripts (w/ php-parser ).
- Async file upload by url (1.5gb)
- Get direct download url of any file (1.5gb)
- TON (this is actually going to be a lot of fun)
- group calls (the php-libtgvoip APIs are actually ready, I just need to wrap them in php-libtgvoip)
- video calls (~)
- native calls:
With MadelineProto async, I can finally properly implement native async phone calls in PHP:
this will allow handling phone calls on webhosts!
I already have some code I created a year ago for this backed up in a private gitlab repo :)
- async iterators:
I've been thinking of using AMPHP's async iterator API (after some modding obviously) to create async iterators for easily iterating over the messages of a group, and for doing other operations that would normally require using offsets:
foreach ($MadelineProto->getMessages('@group') as $message) {
// stuff
}
This shouldn't be too hard to implement, and with a proper (maybe separate OOP) API, it's going to be fun to make and use.
- snake_case => CamelCase conversion for all API methods:
Previously, MadelineProto's custom API methods ( get_info , download_to_dir ) used snake_case , which contrasted with the Telegram API methods ( sendMessage ), and is against PHP coding standards.
Soon, I plan to update MadelineProto's docs to only use CamelCase for method names.
The old method name will still be available after that; right now, you can already use both naming conventions for all MadelineProto methods:
$MadelineProto->get_pwr_chat('user'); // OK!
$MadelineProto->getPwrChat('user'); // OK!
However, I recommend you now use the CamelCase version of methods.
- ArrayAccess on promises (to be able to do yield $method()['result'] instead of (yield $method)['result'] )
- An openChat method, inspired by tdlib, to enable fetching updates from groups you aren't a member of
- Add support for Telegram passport in 2FA and write some wrapper APIs
- Write some simplified APIs for takeout (can be implemented using async iterators)
- #MadelineProtoForNode async and lua async (the second can already be done now, the first is also pretty easy now that async is here :)))))
- DNS over HTTPS everywhere
- Parallelize some methods like the download method, or getPwrChat (upload is already fully parallelized)
- Get sponsor of MTProxies
- Optional max_id and min_id params in methods
- Update to layer 100 (for global group permissions & more)
- #phase1 🇮🇷🇷🇺
You can expect to see the following features in the next relases of MadelineProto.
PWRTelegram API channel
2019-06-05 

Writing MadelineProto async, I really enjoyed working with the AMPHP framework:

it is very fast, has multiple packages to work asynchronously with HTTP requests, websockets, databases (MySQL, redis, postgres, DNS, sockets and much more )!
I chose AMPHP instead of the more famous ReactPHP due to its speed, rich set of libraries and extreme ease of use.
Working with its devs is also nice; I already contributed to the amphp's libraries with some improvements and bugfixes (I will soon also implement a DNS over HTTPS client for AMPHP, to implement in MadelineProto's artax ), and I invite you to do the same!
Even if you don't contribute to AMPHP, you can still use it: as I mentioned above, there are MANY libraries to work asynchronously with files, databases, DNS, HTTP; there's even an async windows registry client, used by the DNS client to fetch default DNS servers on windows!
When you use MadelineProto async, you have to also use an amphp async database client, artax instead of curl and guzzle, and so on: otherwise, the speed of MadelineProto async may be reduced by blocking behaviour of your code.
PWRTelegram API channel
2019-06-05 

- Async forking (does async green thread forking)

Useful if you need to start a process in the background and you want throwed exceptions to surface up.
These exceptions will exit the event loop, turning off the script unless you wrap $MadelineProto->loop() with a try-catch.
Use it when you do not need the result of a method (see ignored async ), but you want eventual errors to crash the script.
Otherwise, just use the method without yield.
// Exceptions will surface out of the event loop()
$MadelineProto->callFork($MadelineProto->messages->sendMessage([...]));
// Exceptions will be ignored
$MadelineProto->messages->sendMessage([...]);
// Like the first one, but the call will be deferred to the next event loop tick
$MadelineProto->callForkDefer($MadelineProto->messages->sendMessage([...]));
- I also created some wrapper functions to work asynchronously with console/browser output
Async sleep:
yield $MadelineProto->sleep(3);
Async readline:
$res = yield $MadelineProto->readLine('Optional prompt');
- Logging is now completely asynchronous and easier:
$MadelineProto->logger("Message");
No need to yield here, because the logging must be done in background.
- Simultaneous method calls:
yield $MadelineProto->messages->sendMessage([
'multiple' => true,
['peer' => '@danogentili', 'message' => 'hi'],
['peer' => '@apony', 'message' => 'hi']
]);
This is the preferred way of combining multiple method calls: this way, the MadelineProto async WriteLoop will combine all method calls in one container, making everything WAY faster.
The result of this will be an array of results, whose type is determined by the original return type of the method (see API docs ).
The order of method calls can be guaranteed (server-side, not by MadelineProto) by using call queues .
- Exceptions:
NOTE: Due to the async nature of MadelineProto 4.0, sometimes the exception that is thrown and logged may not be the actual exception that caused the crash of the script.
To let me properly debug the issue, when reporting issues you also have to provide full logs .
- Finally, async loops .
MadelineProto provides some very useful async loop APIs, for executing operations periodically or on demand.
They are the perfect solution for implementing async cron loops, signal threads and much more!
I'll just link you all to the documentation : it has full examples for each and every async API (you can also check out the code , it's full of PHPDOC comments).
PWRTelegram API channel
2019-06-05 

- Handling timeouts. These methods can be used to wait for a certain amount of time for a result, and then throw an Amp\TimeoutException or simply continue execution if no result was obtained.

// Waits for the result for 2 seconds and then throws an \Amp\TimeoutException
$result = yield $MadelineProto->timeout($promise, 2)
// Waits for the result for 2 seconds, returns the result or null (which is the result of sleep())
$result = yield $MadelineProto->first([$promise, $MadelineProto->sleep(2)]);