pwrtelegram | Саморазвитие

Telegram-канал pwrtelegram - PWRTelegram API channel

885

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

Подписаться на канал

PWRTelegram API channel

> What is AMPHP (https://amphp.org)?

Amp is a non-blocking concurrency framework for PHP providing primitives to manage concurrency such as an event loop, promises, and asynchronous iterators.

> OK, in simpler words?

AMPHP is a high-performance, parallelized PHP library that allows you to write extremely fast, efficient programs that work in parallel using green threads.

> * b r a i n m e l t *

Y E S

———

MadelineProto is not written in PHP: MadelineProto is written using AMPHP.
What this means is that when you using MadelineProto (and async is enabled), all incoming messages are handled in parallel, each in a separate thread, even on webhosts.

This allow your bots to always be responsive, even while executing complex tasks.

However, it is vital that you also use AMPHP (not PHP!) when writing your bot.
What this means is that the following PHP functions and extensions cannot be used in MadelineProto bots (otherwise, all the benefits of AMPHP would be nullified): instead, you must use the correct AMPHP library (automatically included in madeline.php).

file_get_contents
amphp/file for files, amphp/http-client and $MadelineProto->fileGetContents for URLs

curl, guzzle
amphp/http-client is async, much faster than other libraries, and also supports HTTP/2!

mysqli, PDO, sqlite
amphp/mysql supports both MySQL and SQLite backends, and is fully async!
❔You can also use amphp/postgres and amphp/redis for PostgreSQL and Redis!

php-fpm
amphp/http-server is a high-performance async HTTP/2 server, that can be interfaced with MadelineProto to create file download servers!

include, require
❓ Don't use this function very often, and most importantly, don't use it inside of the event handler code.
❔ You should use it only once on bot startup, or else when reloading the bot (plugin source coming soon!)

———

In short, AMPHP is an awesome framework for using async PHP in 2020: you can join the official Telegram support group @amphpchat if you have any questions or suggestions on what else to add to AMPHP!

Читать полностью…

PWRTelegram API channel

MadelineProto was updated!
MadelineProto 5.1 introduces several new features aimed at slashing boilerplate and obliterating bugs.

Features:
* Native error reporting: all errors surfacing from the event handler or MadelineProto will be automatically reported to the admin of the bot!
* Support for bot API file IDs with the sendMedia and download* methods thanks to the new tg-file-decoder library (can also be used standalone!).
* Fixes for bot API object conversion, now you can convert MTProto results to bot API objects using the MTProtoToBotAPI method (and the other way around with BotAPIToMTProto)!

Slashing boilerplate!
* Use the new startAndLoop(EventHandler::class) method to automatically initialize MadelineProto, event handling, error reporting and the event loop, all in a single call!
* Use the new onStart method of the event handler to execute async operations on bot (re)startup!

New settings!
* Use the new async updateSettings and getSettings methods to change settings, the old $MadelineProto->settings behavior is not supported anymore.

New download methods: both methods support parallel downloads, resuming and partial downloads, all chosen automatically depending on headers!
* downloadToResponse downloads files to an async http-server: this is perfect for creating file download bots!
* downloadToBrowser downloads files directly to the browser.

Among other internal changes:
* yield from everything: all internal MadelineProto methods now use yield from for maximum performance!
* Packagist install reports! Now all MadelineProto downloads through madeline.php are reported to packagist!


!!! Thank you for 130.000 downloads !!!

Читать полностью…

PWRTelegram API channel

FREEBIES

Here's a fully parallelized file rename + URL download bot based on MadelineProto.

Max file size: 1.5GB

A working instance can be found here: @pwrtelegrambot

Читать полностью…

PWRTelegram API channel

This is not all: there are still some very cool projects I've yet to finalize and release, eventually you'll see them.

I wish you all a Merry Christmas, and a very happy new year!

❤️❤️❤️

Читать полностью…

PWRTelegram API channel

Instantiation

use danog\MadelineProto\TON\API;

$API = new API(
[
'logger' => [
'logger' => Logger::ECHO_LOGGER
]
]
);


Usage:

$API->async(true);
$API->loop(
function () use ($API) {
yield $API->connect(__DIR__.'/ton-lite-client-test1.config.json');
var_dump(yield $API->liteServer->getTime());
}
);


For a full overview of async in MadelineProtoTon, take a look at the MadelineProto async docs.

For a full list of methods that can be used, simply look at the PHPDOC suggestions in your favorite IDE, or take a look at the ---functions--- section of the lite TL scheme (HTML docs coming soon).

This API can be used to build web-facing HTTP APIs that query the TON blockchain (using the async http-server), off-chain elements for TON applications and so much more!

Since it's in PHP & integrated in MadelineProto, you can also use it in free webhosts (aka use the blockchain on 000webhost AAAAAAAAA ❤️❤️❤️❤️❤️)

Читать полностью…

PWRTelegram API channel

madelineTon.js is actually based on yet another project of mine, a pure JS Telegram MTProto client (madeline.js) which will be released soon ™️™️™️.

Читать полностью…

PWRTelegram API channel

First of all, madelineTon.js:

A pure JS client-side implementation of the Telegram TON blockchain protocol.

Interact directly with the TON blockchain with no middlemans, directly from your browser!

This is possible thanks to a client-side implementation of the ADNL P2P protocol (whitepaper).
Connection to the liteservers is made through a simple websocket proxy that simply acts as a TCP <=> websocket proxy.

All cryptography is done exclusively in the browser, allowing fully secure interaction with the chosen TON node.

The client is fully asynchronous, making use of workers and/or browser webcrypto APIs for cryptography (curves & AES).

TL, ECC w/ TON ADNL, BOC deserialization is implemented.

Possible applications are entirely client-side off-chain components for a distributed TON project; API explorers; and much more!

Читать полностью…

PWRTelegram API channel

The PWRTelegram app has been updated!

Features:
-
skip (private) messages download (add :f after token)

Fixes:
-
chat gallery
- scroll photos
- channels randomly disappear
- private chats with more than 100 messages do not load

Release Notes:
-
now is based on telegram 5.10
- some internal functions have been
rewrited to be more efficient with bots


source code: https://bit.ly/2lwO0um
apk: https://bit.ly/2kulsBB

Читать полностью…

PWRTelegram API channel

MadelineProto 4.0 was released!

100x speed improvement + parallel processing of each update, and much more!

You don't have to change your code to use the new version.
You don't have to define('MADELINE_BRANCH', ''); in your scripts to use the new version anymore, it will be loaded automatically!
By default, the latest stable release of MadelineProto 4.0 will be loaded: to load the latest alpha version, use define('MADELINE_BRANCH', ''); or define('MADELINE_BRANCH', 'master');.

MadelineProto 4.0 async does not support all webhosts, due to their highly modified PHP stacks (000webhost does not seem to work properly, altervista surprisingly works).

To load the deprecated v3 version on these webhosts, write define('MADELINE_BRANCH', 'deprecated'); before including madeline.php.
Note: I will not provide support for the deprecated version of MadelineProto: I will not fix bugs or write documentation for the old version.
The documentation will not contain info about API methods present in the old version, and eventually the old version may stop working: I invite you to switch to a better webhost using MadelineProto 4.0 to avoid these issues.

Breaking changes:
- Removed the old Serialization APIs: now serialization is done automatically by MadelineProto!

Deprecations:
- Deprecated get_updates: it's still working, but I recommend you switch to event handler for 100x speed improvements and parallel processing


Changes:
- Documented the MyTelegramOrgWrapper API, that can be used to login programmaticaly to the my.telegram.org management page and get the API ID of your app.
- Improved chat message splitting algorithm
- Removed all dependencies to curl: now all HTTP requests are made asynchronously using a custom version of artax
- Updated php-libtgvoip and introduced a common API for changing phone call settings
- Improved the madeline.php loader
- Increased the default flood wait limit to 10 minutes, since with async waiting for the flood wait isn't blocking anymore
- When running from web, MadelineProto will also automatically enable logging of PHP errors (not MadelineProto logs) to a MadelineProto.log file located in the same directory as the script that loaded MadelineProto.

New API features:
- Fully async logic!
- MTProxy and dynamic proxy support!
- Very important, I wrote documentation on what to do if your account gets banned.
- I commited a few crimes by bringing back support for PHP 5.6 and PHP 7.0 using a heavily modified version of 7to5 and 7to70 if you load MadelineProto using madeline.php: async is supported on PHP 5.6!
However, I do not recommend you use PHP 5 or 7.0: I did this only to support async logic on webhosts, if you're running on your own machine install PHP 7.3+ (PHP 7.1 isn't recommended due to some socket bugs).

- Shutdown API, for executing operations on shutdown
- Built-in locking, to prevent multiple instances of the bot from running together
- 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)!
- 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).
- Added a resetUpdateState method to reset the update state and fetch ALL updates from the beginning
- Added a __magic_sleep substitute for __sleep in the CombinedEventHandler
- 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
- Rewritten the APIFactory, the abstraction layer that stands between you and MadelineProto when you do $MadelineProto->method(): it is now fully async, and MUCH faster thanks to a new cached method mapping system.
- The same cached method mapping system is also used for the event handler, which means that now the event handler is the fastest update management method.

Читать полностью…

PWRTelegram API channel

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

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

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

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

- 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)]);

Читать полностью…

PWRTelegram API channel

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, perfect for creating file downloader bots!).

When I say thread, I actually mean green thread (wikipedia), 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.

Each update you receive using the event handler or the callback handler is managed in parallel in separate green threads: the only thing you have to do to enable async with green threads is add a yield before calling MadelineProto methods.

Full async documentation with examples.

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.

Читать полностью…

PWRTelegram API channel

I'm also announcing some updates for the MadelineProto social channels.

- Introducing separate OT chat groups, to allow chatting about tech, politics and memes.
- Introducing a new international MadelineProto support group, for MadelineProto help and support.
- Finally introducing the official MadelineProto meme channel, full of only the dankest based memes!
- Introducing an official discussion group for AMPHP, the async, high-performance parallelized PHP library!

Also, finally introducing an official farsi MadelineProto channel: @madeline_farsi.
This channel will post farsi translations of the posts sent on the main channel, along with MadelineProto sources, AMPHP tips and much more!

Also, check out the official arabic MadelineProto channel: @madelineArabic

Читать полностью…

PWRTelegram API channel

I wish you all a very happy new year!
❤️❤️❤️

Читать полностью…

PWRTelegram API channel

MadelineProto was updated to v5!

Introducing upload by URL, file renaming, parallelized downloads and uploads!

You can now use MadelineProto to rename Telegram files or upload them by URL: all uploads and downloads will be made 100% in parallel, 20 chunks at a time for maximum speed (value tweakable in the settings).
For more info, see the new file documentation.

Also introducing:
- Strictly typed, camelCase public API, now all methods can also be called in camelCase, with PHP type hinting for most parameters and return values.
- Full PHPDOC documentation for all the public API, for perfect documentation in your favorite IDE :)
- Several internal bugfixes, refactoring and general performance and stability improvements.
- Improved tests, to avoid backwards compatiblity issues with previous sessions when pushing.
- Clean composer dependencies, now you just have to require danog/madelineproto ^5.0 and nothing else in your composer.json!

Breaking changes:
- NONE :D; you don't have to change your code!

Читать полностью…

PWRTelegram API channel

Finally, feel free to take a look at my submission to the TON contest: https://github.com/danog/toncontest

The repository contains well-documented code for multiple TON smart contracts, a testing suite based on the official TON validator, and a build toolchain for TON.

Читать полностью…

PWRTelegram API channel

Next, I am proud to announce support for the TON protocol in MadelineProto.

MadelineProto is now capable of integrating with the Telegram TON blockchain, thanks to a fully native implementation of ADNL and the lite-client protocol.

It allows async interaction with liteservers in the same manner as the official lite-client, only with way more abstractions and ease of use.

Читать полностью…

PWRTelegram API channel

Installation:

yarn add madeline-ton

Читать полностью…

PWRTelegram API channel

I am extremely proud to announce the release of some projects I've been working on for the last three months, in the context of the Telegram Contests.

Читать полностью…

PWRTelegram API channel

Internal API improvements:
- I created a unique, reliable, fast and extremely simple update handling system based on MadelineProto's loop API, not present in any other MTProto client, not even tdlib.
- Brand new async Stream connection stack
- Unique async message handler stack
- Abstract TLCallback API
- File reference database
- DNS over HTTPS


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!).

To learn more about parallel processing with async, see the following tutorials:
- Async basics
- Async HTTP (file_get_contents)
- Async helper functions (p. 1, 2)
- Async forking
- Async background loops
- Async libraries by AMPHP


I am really happy with how MadelineProto 4.0 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.

(this is just a TL;DR of the full changelog, see the original posts for the full feature list)

Читать полностью…

PWRTelegram API channel

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

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

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:

<?php

if (!file_exists('madeline.php')) {
copy('<a href="https://phar.madelineproto.xyz/madeline.php">https://phar.madelineproto.xyz/madeline.php&lt;/a&gt;', '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

In case you missed it, quick reminder that MadelineProto now supports MTProxy!

Читать полностью…

PWRTelegram API channel

- 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

To implement async, I wrote loads of new async APIs in MadelineProto, as you may have seen above.
I used the awesome amphp async framework as base, on which to build the new MadelineProto APIs.
I heavily modified amphp coroutines and wrapped all of the AMPHP event loop methods to add native support for yielding generators.

I have also wrapped multiple amphp async libraries for ease of use and compatiblity with MadelineProto settings:
- MadelineProto artax HTTP client:
I wrapped the amphp artax HTTP library for greater security, and to add support for socks5 and HTTP proxies: the proxy settings are automatically extracted from MadelineProto settings.
Soon, MadelineProto's artax will support DNS over HTTPS by default.

I also provided a wrapper version of file_get_contents:

$file = yield $MadelineProto->file_get_contents('https://url');


You can use this library to asynchronously download files from the web.

- ALL internal MadelineProto methods were converted to async automatically using an automatic script: with some changes and conversion to use php-parser, it can be used to automatically asyncify any script (will implement in a future version of MadelineProto).
- I created a custom async API to asynchronously construct objects:
This allows you to create multiple instances of MadelineProto asynchronously, because each instantiation will be done asynchronously.

$com = new \danog\MadelineProto\CombinedAPI('combined_session.madeline', ['bot.madeline' => $settings, 'user.madeline' => $settings, 'user2.madeline' => $settings]);
$com->async(true);
$com->loop(function () use ($com) {
$res = [];
foreach (['bot.madeline', 'user.madeline', 'user2.madeline'] as $session) {
$res []= $com->instances[$session]->start();
}
yield $com->all($res);
yield $com->setEventHandler('\EventHandler');
}
$com->loop();


Internally, the combined event handler does new \danog\MadelineProto\API, but it isn't blocking:
this means that later, when I combine all the async `start()`s into one array and yield it using the async combinator function, initialization of sessions is done in parallel, and not one after the other.
A side effect of this is that you must not access or modify the settings property, at least not until the instance is ready; also, only non-namespaced methods can be called while the instance is still initializing.
To avoid these problems, simply yield $MadelineProto->start() before doing anything else (put a $MadelineProto->async(true) before that, though).

- I wrapped amphp's helper functions, and created some more:

The all function you saw above is one of the many combinator functions that can be used to execute multiple async operations simultaneously and wait for the result of all of them.
Each method has different error handling techniques, see the amphp docs.
Note that if you just take the result of these methods without yielding it, you can use it as a normal promise/generator.

Note: this is not the recommended method to make multiple method calls on the same instance of MadelineProto; use this only for non-API methods like start(); for API methods, use multiple async.

$promise1 = $MadelineProto->messages->sendMessage(...);
$promise2 = $MadelineProto->messages->sendMessage(...);
// $promise3 = ...;

// Equivalent to Amp\Promise\all(), but works with generators, too
$results = yield $MadelineProto->all([$promise1, $promise2, $generator3]);

// Equivalent to Amp\Promise\first(), but works with generators, too
$results = yield $MadelineProto->first([$promise1, $promise2, $generator3]);

// Equivalent to Amp\Promise\any(), but works with generators, too
$results = yield $MadelineProto->any([$promise1, $promise2, $generator3]);

// Equivalent to Amp\Promise\some(), but works with generators, too
$results = yield $MadelineProto->some([$promise1, $promise2, $generator3]);

Читать полностью…

PWRTelegram API channel

Even if most of MadelineProto's logic is now concentrated in the new loop and stream APIs, some parts like the TL parser are still there, albeit with many changes.
For example: now the TL parser is fully asynchronous (that may sound a bit weird to some of you, but for dynamic TL parsers, this greatly increases performances and allows parallelism).

The TL deserializer now uses yet another well-structured API called the TLCallback API to automatically populate internal databases directly on deserialization: again, this paradigm greatly reduces complexity, increases performance and is absolutely unique to MadelineProto; no other MTProto client has it, not even official clients.

One of the completely new modules that I created for MadelineProto async is the file reference database: a very complex module, required to handle files in the newer versions of the Telegram API.
It makes full use of the TLCallback API to map files to their origins, to be able to refetch them at any given time when the file reference expires.

Another new module I've implemented is the PasswordCalculator, that is used to calculate the new password hashes for the 2FA login, really cool.

I've also rewritten the APIFactory, the abstraction layer that stands between you and MadelineProto when you do $MadelineProto->method(): it is now fully async, and MUCH faster thanks to a new cached method mapping system.
The same cached method mapping system is also used for the event handler, which means that now the event handler is the fastest update management method.

Читать полностью…
Подписаться на канал