NoW fUlLY AsYNc

This commit is contained in:
Daniil Gentili 2019-06-01 18:08:28 +02:00
parent 279e3d0d66
commit ba08d57eed
23 changed files with 112 additions and 139 deletions

View File

@ -13,12 +13,9 @@ description: bot_login parameters, return type and example
### Return type: [auth.Authorization](API_docs/types/auth_Authorization.md)
### Example:
### Example ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)):
```php
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->async(true);
$authorization = [yield](ASYNC.html) $this->bot_login($token);
$authorization = yield $this->bot_login($token);
```

View File

@ -13,23 +13,20 @@ description: complete_2FA_login parameters, return type and example
### Return type: [auth.Authorization](API_docs/types/auth_Authorization.md)
### Example:
### Example ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)):
```php
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->async(true);
[yield](ASYNC.html) $MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = [yield](ASYNC.html) $MadelineProto->complete_phone_login(readline('Enter the code you received: '));
yield $MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = yield $MadelineProto->complete_phone_login(readline('Enter the code you received: '));
if ($authorization['_'] === 'account.noPassword') {
throw new \danog\MadelineProto\Exception('2FA is enabled but no password is set!');
}
if ($authorization['_'] === 'account.password') {
$authorization = [yield](ASYNC.html) $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
$authorization = yield $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
}
if ($authorization['_'] === 'account.needSignup') {
$authorization = [yield](ASYNC.html) $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
$authorization = yield $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
}
```

View File

@ -15,23 +15,20 @@ description: complete_phone_login parameters, return type and example
You must then use [complete_2FA_login](complete_2FA_login.md) or [complete_signup](complete_signup.md) to login or signup, or simply start using `$MadelineProto` if the result is a `auth.Authorization` object.
### Example:
### Example ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)):
```php
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->async(true);
[yield](ASYNC.html) $MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = [yield](ASYNC.html) $MadelineProto->complete_phone_login(readline('Enter the code you received: '));
yield $MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = yield $MadelineProto->complete_phone_login(readline('Enter the code you received: '));
if ($authorization['_'] === 'account.noPassword') {
throw new \danog\MadelineProto\Exception('2FA is enabled but no password is set!');
}
if ($authorization['_'] === 'account.password') {
$authorization = [yield](ASYNC.html) $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
$authorization = yield $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
}
if ($authorization['_'] === 'account.needSignup') {
$authorization = [yield](ASYNC.html) $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
$authorization = yield $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
}
```

View File

@ -14,23 +14,20 @@ description: complete_signup parameters, return type and example
### Return type: [auth.Authorization](API_docs/types/auth_Authorization.md)
### Example:
### Example ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)):
```php
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->async(true);
[yield](ASYNC.html) $MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = [yield](ASYNC.html) $MadelineProto->complete_phone_login(readline('Enter the code you received: '));
yield $MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = yield $MadelineProto->complete_phone_login(readline('Enter the code you received: '));
if ($authorization['_'] === 'account.noPassword') {
throw new \danog\MadelineProto\Exception('2FA is enabled but no password is set!');
}
if ($authorization['_'] === 'account.password') {
$authorization = [yield](ASYNC.html) $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
$authorization = yield $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
}
if ($authorization['_'] === 'account.needSignup') {
$authorization = [yield](ASYNC.html) $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
$authorization = yield $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
}

View File

@ -46,6 +46,9 @@ Once the file is downloaded, execution is automatically **resumed** from that ex
This means that you can handle multiple updates, download/upload multiple files all together in one process, as if you were writing normal synchronous code + making everything a lot faster.
If your code still relies on the old synchronous behaviour, don't worry, there is backward compatibility.
However, I highly recommend you switch to async, due to the huge performance and parallelism benefits.
## Loading the latest version of MadelineProto
In order to use the `yield` operator in MadelineProto, you have to load the **latest version** of MadelineProto from the **master** branch (alpha) by loading it through composer (`dev-master`) or with madeline.php:

View File

@ -13,7 +13,7 @@ if (!file_exists('input.raw')) {
echo 'Downloading example song'.PHP_EOL;
copy('https://github.com/danog/MadelineProto/raw/master/input.raw', 'input.raw');
}
$call = [yield](ASYNC.html) $MadelineProto->request_call('@danogentili')->play('input.raw')->then('input.raw')->playOnHold(['input.raw'])->setOutputFile('output.raw');
$call = yield $MadelineProto->request_call('@danogentili')->play('input.raw')->then('input.raw')->playOnHold(['input.raw'])->setOutputFile('output.raw');
// We need to receive updates in order to avoid closing the script before the call has ended
while ($call->getCallState() < \danog\MadelineProto\VoIP::CALL_STATE_ENDED) {

View File

@ -11,9 +11,9 @@ There are various methods that can be used to fetch info about chats, based on b
* [Full chat info](#get_full_info)
* [Reduced chat info (very fast)](#get_info)
## get_pwr_chat
## get_pwr_chat ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
```php
$pwr_chat = [yield](ASYNC.html) $MadelineProto->get_pwr_chat(-100214891824);
$pwr_chat = yield $MadelineProto->get_pwr_chat(-100214891824);
foreach ($pwr_chat['participants'] as $participant) {
\danog\MadelineProto\Logger::log($participant);
}
@ -25,9 +25,9 @@ Use `get_pwr_chat` to get full chat info, including the full list of members, se
* Speed: medium
* Caching: medium
## get_full_info
## get_full_info ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
```php
$full_chat = [yield](ASYNC.html) $MadelineProto->get_full_info(-10028941842);
$full_chat = yield $MadelineProto->get_full_info(-10028941842);
```
You can also use `get_full_info` to get full chat info, without the full list of members, see [here for the parameters and the result](https://docs.madelineproto.xyz/get_full_info.html).
@ -36,9 +36,9 @@ You can also use `get_full_info` to get full chat info, without the full list of
* Speed: medium-fast
* Caching: full
## get_info
## get_info ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
```php
$chat = [yield](ASYNC.html) $MadelineProto->get_info(-10028941842);
$chat = yield $MadelineProto->get_info(-10028941842);
```
You can also use `get_info` to get chat info, see [here for the parameters and the result](https://docs.madelineproto.xyz/get_info.html)

View File

@ -11,19 +11,19 @@ There are two ways to get a list of all chats, depending if you logged in as a u
* [Full dialog info](#user-get_full_dialogs)
* [As bot](#bot-internal-peer-database)
## User: get_dialogs
## User: get_dialogs ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
```php
$dialogs = [yield](ASYNC.html) $MadelineProto->get_dialogs();
$dialogs = yield $MadelineProto->get_dialogs();
foreach ($dialogs as $peer) {
[yield](ASYNC.html) $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => 'Hi! Testing MadelineProto broadcasting!']);
yield $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => 'Hi! Testing MadelineProto broadcasting!']);
}
```
`get_dialogs` will return a full list of all chats you're member of, see [here for the parameters and the result](https://docs.madelineproto.xyz/get_dialogs.html)
## User: get_full_dialogs
## User: get_full_dialogs ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
```php
$dialogs = [yield](ASYNC.html) $MadelineProto->get_full_dialogs();
$dialogs = yield $MadelineProto->get_full_dialogs();
foreach ($dialogs as $dialog) {
\danog\MadelineProto\Logger::log($dialog);
}
@ -35,7 +35,7 @@ foreach ($dialogs as $dialog) {
```php
foreach ($MadelineProto->API->chats as $bot_api_id => $chat) {
try {
[yield](ASYNC.html) $MadelineProto->messages->sendMessage(['peer' => $chat, 'message' => "Hi $bot_api_id! Testing MadelineProto broadcasting!"]);
yield $MadelineProto->messages->sendMessage(['peer' => $chat, 'message' => "Hi $bot_api_id! Testing MadelineProto broadcasting!"]);
} catch (\danog\MadelineProto\RPCErrorException $e) {
echo $e;
}

View File

@ -9,6 +9,8 @@ MadelineProto provides wrapper methods to upload and download files that support
Maximum file size is of 1.5 GB.
[Now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)
* [Uploading & sending files](#sending-files)
* [Security notice](#security-notice)
* [Photos](#inputmediauploadedphoto)
@ -46,7 +48,7 @@ To disable automatic uploads by file name, set `$MadelineProto->settings['upload
### [inputMediaUploadedPhoto](https://docs.madelineproto.xyz/API_docs/constructors/inputMediaUploadedPhoto.html)
```php
$sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
$sentMessage = yield $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
'_' => 'inputMediaUploadedPhoto',
@ -61,7 +63,7 @@ Can be used to upload photos: simply provide the photo's file path in the `file`
### [inputMediaUploadedDocument](https://docs.madelineproto.xyz/API_docs/constructors/inputMediaUploadedDocument.html)
```php
$sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
$sentMessage = yield $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
'_' => 'inputMediaUploadedDocument',
@ -83,7 +85,7 @@ To actually set the document type, provide one or more [DocumentAttribute](https
### [documentAttributeFilename](https://docs.madelineproto.xyz/API_docs/constructors/documentAttributeFilename.html) to send a document
```php
$sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
$sentMessage = yield $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
'_' => 'inputMediaUploadedDocument',
@ -100,7 +102,7 @@ $sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
### [documentAttributeImageSize](https://docs.madelineproto.xyz/API_docs/constructors/documentAttributeImageSize.html) to send a photo as document
```php
$sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
$sentMessage = yield $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
'_' => 'inputMediaUploadedDocument',
@ -117,7 +119,7 @@ $sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
### [documentAttributeAnimated](https://docs.madelineproto.xyz/API_docs/constructors/documentAttributeAnimated.html) to send a gif
```php
$sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
$sentMessage = yield $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
'_' => 'inputMediaUploadedDocument',
@ -133,7 +135,7 @@ $sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
### [documentAttributeVideo](https://docs.madelineproto.xyz/API_docs/constructors/documentAttributeVideo.html) to send a video
```php
$sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
$sentMessage = yield $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
'_' => 'inputMediaUploadedDocument',
@ -154,7 +156,7 @@ You might want to manually provide square `w` (width) and `h` (height) parameter
### [documentAttributeAudio](https://docs.madelineproto.xyz/API_docs/constructors/documentAttributeAudio.html) to send an audio file
```php
$sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
$sentMessage = yield $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
'_' => 'inputMediaUploadedDocument',
@ -174,7 +176,7 @@ Set the `voice` parameter to true to send a voice message.
## Uploading files
```php
$MessageMedia = [yield](ASYNC.html) $MadelineProto->messages->uploadMedia([
$MessageMedia = yield $MadelineProto->messages->uploadMedia([
'media' => [
'_' => 'inputMediaUploadedPhoto',
'file' => 'faust.jpg'
@ -189,7 +191,7 @@ The [$MadelineProto->messages->uploadMedia](https://docs.madelineproto.xyz/API_d
The returned [MessageMedia](https://docs.madelineproto.xyz/API_docs/types/MessageMedia.html) object can then be reused to resend the document using sendMedia.
```php
$sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
$sentMessage = yield $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => $MessageMedia,
'message' => '[This is the caption](https://t.me/MadelineProto)',
@ -206,7 +208,7 @@ $sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
Actual MessageMedia objects can also be converted to bot API file IDs like this:
```php
$botAPI_file = [yield](ASYNC.html) $MadelineProto->MTProto_to_botAPI($MessageMedia);
$botAPI_file = yield $MadelineProto->MTProto_to_botAPI($MessageMedia);
```
`$botAPI_file` now contains a [bot API message](https://core.telegram.org/bots/api#message), to extract the file ID from it use the following code:
@ -255,13 +257,13 @@ if (!isset($result['file_name'])) {
`$MadelineProto->messages->uploadMedia` and bot API file IDs do not allow you to modify the type of the file to send: however, MadelineProto provides a method that can generate a file object that can be resent with multiple file types.
```php
$inputFile = [yield](ASYNC.html) $MadelineProto->upload('filename.mp4');
$inputFile = yield $MadelineProto->upload('filename.mp4');
```
The generated `$inputFile` can later be reused thusly:
```php
$sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
$sentMessage = yield $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
'_' => 'inputMediaUploadedDocument',
@ -273,7 +275,7 @@ $sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
'message' => '[This is the caption](https://t.me/MadelineProto)',
'parse_mode' => 'Markdown'
]);
$sentMessageVideo = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
$sentMessageVideo = yield $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
'_' => 'inputMediaUploadedDocument',
@ -298,7 +300,7 @@ There are multiple download methods that allow you to download a file to a direc
### Extracting download info
```php
$info = [yield](ASYNC.html) $MadelineProto->get_download_info($MessageMedia);
$info = yield $MadelineProto->get_download_info($MessageMedia);
```
`$MessageMedia` can be a [MessageMedia](https://docs.madelineproto.xyz/API_docs/types/MessageMedia.html) object or a bot API file ID.
@ -310,7 +312,7 @@ $info = [yield](ASYNC.html) $MadelineProto->get_download_info($MessageMedia);
### Download to directory
```php
$output_file_name = [yield](ASYNC.html) $MadelineProto->download_to_dir($MessageMedia, '/tmp/');
$output_file_name = yield $MadelineProto->download_to_dir($MessageMedia, '/tmp/');
```
This downloads the given file to `/tmp`, and returns the full generated file path.
@ -319,7 +321,7 @@ This downloads the given file to `/tmp`, and returns the full generated file pat
### Download to file
```php
$output_file_name = [yield](ASYNC.html) $MadelineProto->download_to_file($MessageMedia, '/tmp/myname.mp4');
$output_file_name = yield $MadelineProto->download_to_file($MessageMedia, '/tmp/myname.mp4');
```
This downloads the given file to `/tmp/myname.mp4`, and returns the full file path.
@ -329,12 +331,12 @@ This downloads the given file to `/tmp/myname.mp4`, and returns the full file pa
### Download to browser with streams
```php
$info = [yield](ASYNC.html) $MadelineProto->get_download_info($MessageMedia);
$info = yield $MadelineProto->get_download_info($MessageMedia);
header('Content-Length: '.$info['size']);
header('Content-Type: '.$info['mime']);
$stream = fopen('php://output', 'w');
[yield](ASYNC.html) $MadelineProto->download_to_stream($MessageMedia, $stream, $cb, $offset, $endoffset);
yield $MadelineProto->download_to_stream($MessageMedia, $stream, $cb, $offset, $endoffset);
```
This downloads the given file to the browser, sending also information about the file's type and size.
@ -356,14 +358,14 @@ To get the upload/download progress in real-time, use the `\danog\MadelineProto\
```php
$peer = '@danogentili';
$sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
$sentMessage = yield $MadelineProto->messages->sendMedia([
'peer' => $peer,
'media' => [
'_' => 'inputMediaUploadedDocument',
'file' => new \danog\MadelineProto\FileCallback(
'video.mp4',
function ($progress) use ($MadelineProto, $peer) {
[yield](ASYNC.html) $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => 'Upload progress: '.$progress.'%']);
yield $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => 'Upload progress: '.$progress.'%']);
}
),
'attributes' => [
@ -374,12 +376,12 @@ $sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
'parse_mode' => 'Markdown'
]);
$output_file_name = [yield](ASYNC.html) $MadelineProto->download_to_file(
$output_file_name = yield $MadelineProto->download_to_file(
$sentMessage,
new \danog\MadelineProto\FileCallback(
'/tmp/myname.mp4',
function ($progress) use ($MadelineProto, $peer) {
[yield](ASYNC.html) $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => 'Download progress: '.$progress.'%']);
yield $MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => 'Download progress: '.$progress.'%']);
}
)
);
@ -408,11 +410,11 @@ class MyCallback implements \danog\MadelineProto\FileCallbackInterface
}
public function __invoke($progress)
{
[yield](ASYNC.html) $this->MadelineProto->messages->sendMessage(['peer' => $this->peer, 'message' => 'Progress: '.$progress.'%']);
yield $this->MadelineProto->messages->sendMessage(['peer' => $this->peer, 'message' => 'Progress: '.$progress.'%']);
}
}
$peer = '@danogentili';
$sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
$sentMessage = yield $MadelineProto->messages->sendMedia([
'peer' => $peer,
'media' => [
'_' => 'inputMediaUploadedDocument',
@ -425,7 +427,7 @@ $sentMessage = [yield](ASYNC.html) $MadelineProto->messages->sendMedia([
'parse_mode' => 'Markdown'
]);
$output_file_name = [yield](ASYNC.html) $MadelineProto->download_to_file(
$output_file_name = yield $MadelineProto->download_to_file(
$sentMessage,
new MyCallback('/tmp/myname.mp4', $peer, $MadelineProto)
);

View File

@ -3,7 +3,7 @@ title: Inline buttons
description: You can easily click inline buttons using MadelineProto, just access the correct button:
image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png
---
# Inline buttons
# Inline buttons ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
You can easily click inline buttons using MadelineProto, just access the correct button:
@ -23,7 +23,7 @@ class EventHandler extends \danog\MadelineProto\EventHandler
if (isset($update['message']['reply_markup']['rows'])) {
foreach ($update['message']['reply_markup']['rows'] as $row) {
foreach ($row['buttons'] as $button) {
[yield](ASYNC.html) $button->click();
yield $button->click();
}
}
}
@ -51,7 +51,7 @@ $text = $button['text'];
And click them:
```php
[yield](ASYNC.html) $button->click();
yield $button->click();
```
<a href="https://docs.madelineproto.xyz/docs/SECRET_CHATS.html">Next section</a>

View File

@ -12,10 +12,10 @@ There are many ways you can login with MadelineProto.
* [Manual (bot)](#manual-bot)
* [Logout](#logout)
## Automatic
## Automatic ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
```php
[yield](ASYNC.html) $MadelineProto->start();
yield $MadelineProto->start();
```
This will start an interactive login prompt via console (if running via CLI), or a login web UI (if running in the browser).
@ -25,13 +25,13 @@ You will get to choose if login as user, or as bot.
## Manual (user)
```php
[yield](ASYNC.html) $MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = [yield](ASYNC.html) $MadelineProto->complete_phone_login(readline('Enter the phone code: '));
yield $MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = yield $MadelineProto->complete_phone_login(readline('Enter the phone code: '));
if ($authorization['_'] === 'account.password') {
$authorization = [yield](ASYNC.html) $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
$authorization = yield $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
}
if ($authorization['_'] === 'account.needSignup') {
$authorization = [yield](ASYNC.html) $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
$authorization = yield $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
}
```
@ -46,7 +46,7 @@ If the account does not have an account, use `complete_signup` to signup, see [h
## Manual (bot)
```php
[yield](ASYNC.html) $MadelineProto->bot_login('34298141894:aflknsaflknLKNFS');
yield $MadelineProto->bot_login('34298141894:aflknsaflknLKNFS');
```
Use `bot_login` to login as a bot, see [here for the parameters and the result](https://docs.madelineproto.xyz/bot_login.html).
@ -57,7 +57,7 @@ Note that when you login as a bot, MadelineProto also logins using the [PWRTeleg
## Logout
```php
[yield](ASYNC.html) $MadelineProto->logout();
yield $MadelineProto->logout();
```
**If** you want to logout, you can use the logout function, see [here for the parameters and the result](https://docs.madelineproto.xyz/logout.html).

View File

@ -12,37 +12,37 @@ MadelineProto provides wrappers to work with secret chats.
* [Checking secret chat status](#checking-secret-chat-status)
* [Sending secret messages](#sending-secret-messages)
## Requesting secret chats
## Requesting secret chats ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
```php
$secret_chat = [yield](ASYNC.html) $MadelineProto->request_secret_chat($InputUser);
$secret_chat = yield $MadelineProto->request_secret_chat($InputUser);
```
[`request_secret_chat`](https://docs.madelineproto.xyz/request_secret_chat.html) requests a secret secret chat to the [InputUser](https://docs.madelineproto.xyz/API_docs/types/InputUser.html), ID, or username specified, and returns the secret chat ID.
## Accepting secret chats
## Accepting secret chats ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
Secret chats are accepted or refused automatically, based on a value in the [settings](SETTINGS.html#settingssecret_chatsaccept_chats) (by default MadelineProto is set to accept all secret chats).
Before sending any message, you must check if the secret chat was accepted by the other client with the following method:
## Checking secret chat status
## Checking secret chat status ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
```php
$status = [yield](ASYNC.html) $MadelineProto->secret_chat_status($chat);
$status = yield $MadelineProto->secret_chat_status($chat);
```
$status is 0 if the chat cannot be found in the local database, 1 if the chat was requested but not yet accepted, and 2 if it is a valid accepted secret chat.
## Sending secret messages
## Sending secret messages ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
[Full example](https://github.com/danog/MadelineProto/blob/master/secret_bot.php)
To send messages/files/service messages, simply use the sendEncrypted methods with objects that use the same layer used by the other client (specified by the number after the underscore in decryptedMessage object names, to obtain the layer that must be used for a secret chat use the following wrapper method).
```php
$secret_chat = [yield](ASYNC.html) $MadelineProto->get_secret_chat($chat);
$secret_chat = yield $MadelineProto->get_secret_chat($chat);
/*
[
'key' => [ // The authorization key

View File

@ -8,7 +8,7 @@ image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png
Here's how you can fetch info about the currently logged in user
```php
$me = [yield](ASYNC.html) $MadelineProto->get_self();
$me = yield $MadelineProto->get_self();
\danog\MadelineProto\Logger::log("Hi ".$me['first_name']."!");
```

View File

@ -8,7 +8,7 @@ image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png
You get the web template used for the `$MadelineProto->start()` web UI thusly:
```php
$template = [yield](ASYNC.html) $MadelineProto->get_web_template();
$template = yield $MadelineProto->get_web_template();
```
By default, it is equal to:
@ -31,7 +31,7 @@ By default, it is equal to:
To modify the web template, use:
```php
[yield](ASYNC.html) $MadelineProto->set_web_template($new_template);
yield $MadelineProto->set_web_template($new_template);
```
The new template must have a structure similar the the default template.

View File

@ -9,6 +9,8 @@ There are simplifications for many, if not all of, these methods.
A list of all of the methods that can be called with MadelineProto can be found here: [here (layer 97)](https://docs.madelineproto.xyz/API_docs/).
[Now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)
* [FULL API Documentation with descriptions](https://docs.madelineproto.xyz/API_docs/methods/)
* [Peers](#peers)
* [Files](https://docs.madelineproto.xyz/docs/FILES.html)
@ -25,12 +27,12 @@ A list of all of the methods that can be called with MadelineProto can be found
If an object of type User, InputUser, Chat, InputChannel, Peer or InputPeer must be provided as a parameter to a method, you can substitute it with the user/group/channel's username (`@username`), bot API id (`-1029449`, `1249421`, `-100412412901`), or update.
```php
[yield](ASYNC.html) $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'Testing MadelineProto...']);
yield $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'Testing MadelineProto...']);
```
If you want to check if a bot API id is a supergroup/channel ID:
```php
$Bool = [yield](ASYNC.html) $MadelineProto->is_supergroup($id);
$Bool = yield $MadelineProto->is_supergroup($id);
```
Uses logarithmic conversion to avoid problems on 32 bit systems.
@ -38,7 +40,7 @@ Uses logarithmic conversion to avoid problems on 32 bit systems.
If you want to convert an MTProto API id to a supergroup/channel bot API ID:
```php
$bot_api_id = [yield](ASYNC.html) $MadelineProto->to_supergroup($id);
$bot_api_id = yield $MadelineProto->to_supergroup($id);
```
Uses logarithmic conversion to avoid problems on 32 bit systems.
@ -49,7 +51,7 @@ Uses logarithmic conversion to avoid problems on 32 bit systems.
If an object of type InputSecretChat must be provided as a parameter to a method, you can substitute it with the secret chat's id, the updateNewEncrypted message or the decryptedMessage:
```php
[yield](ASYNC.html) $MadelineProto->messages->sendEncrypted(['peer' => $update, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => 'Hi']]);
yield $MadelineProto->messages->sendEncrypted(['peer' => $update, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => 'Hi']]);
```
@ -58,8 +60,8 @@ If an object of type InputSecretChat must be provided as a parameter to a method
Methods that allow sending message entities ([messages.sendMessage](http://docs.madelineproto.xyz/API_docs/methods/messages_sendMessage.html) for example) also have an additional `parse_mode` parameter that enables or disables html/markdown parsing of the message to be sent.
```php
[yield](ASYNC.html) $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => '[Testing Markdown in MadelineProto](https://docs.madelineproto.xyz)', 'parse_mode' => 'Markdown']);
[yield](ASYNC.html) $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => '<a href="https://docs.madelineproto.xyz">Testing HTML in MadelineProto</a>', 'parse_mode' => 'HTML']);
yield $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => '[Testing Markdown in MadelineProto](https://docs.madelineproto.xyz)', 'parse_mode' => 'Markdown']);
yield $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => '<a href="https://docs.madelineproto.xyz">Testing HTML in MadelineProto</a>', 'parse_mode' => 'HTML']);
```
@ -76,7 +78,7 @@ $bot_API_markup = ['inline_keyboard' =>
]
]
];
[yield](ASYNC.html) $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel', 'reply_markup' => $bot_API_markup]);
yield $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel', 'reply_markup' => $bot_API_markup]);
```
@ -84,7 +86,7 @@ $bot_API_markup = ['inline_keyboard' =>
To convert the results of methods to bot API objects you must provide a second parameter to method wrappers, containing an array with the `botAPI` key set to true.
```php
$bot_API_object = [yield](ASYNC.html) $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel'], ['botAPI' => true]);
$bot_API_object = yield $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel'], ['botAPI' => true]);
```
MadelineProto also [supports bot API file IDs when working with files](FILES.html)
@ -96,7 +98,7 @@ Also see [ignored async](https://docs.madelineproto.xyz/docs/ASYNC.html#ignored-
To disable fetching the result of a method, the array that must be provided as second parameter to method wrapper must have the `noResponse` key set to true.
```php
[yield](ASYNC.html) $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel'], ['noResponse' => true]);
yield $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel'], ['noResponse' => true]);
```
@ -104,7 +106,7 @@ To disable fetching the result of a method, the array that must be provided as s
Method calls may be executed at diferent times server-side: to avoid this, method calls can be queued (this is especially useful when using [ignored async](https://docs.madelineproto.xyz/docs/ASYNC.html#ignored-async)):
```php
[yield](ASYNC.html) $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel'], ['queue' => 'queue_name']);
yield $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel'], ['queue' => 'queue_name']);
```
If the queue if the specified queue name does not exist, it will be created.

View File

@ -8,14 +8,11 @@ Gets full list of dialogs
### Return type: Array of [Peer objects](API_docs/types/Peer.md)
### Example:
### Example ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)):
```php
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->start();
$Peers = [yield](ASYNC.html) $MadelineProto->get_dialogs();
$Peers = yield $MadelineProto->get_dialogs();
```
Or, if you're into Lua:

View File

@ -13,14 +13,11 @@ description: get_full_info parameters, return type and example
### Return type: [FullInfo](FullInfo.md)
### Example:
### Example ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)):
```php
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->start();
$Chat = [yield](ASYNC.html) $MadelineProto->get_full_info($id);
$Chat = yield $MadelineProto->get_full_info($id);
```
Or, if you're into Lua:

View File

@ -13,14 +13,11 @@ description: get_info parameters, return type and example
### Return type: [Info](Info.md)
### Example:
### Example ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)):
```php
$MadelineProto = new \danog\MadelineProto\API();
$MadelineProto->start();
$Chat = [yield](ASYNC.html) $MadelineProto->get_info($id);
$Chat = yield $MadelineProto->get_info($id);
```
Or, if you're into Lua:

View File

@ -14,14 +14,11 @@ description: get_pwr_chat parameters, return type and example
### Return type: [PWRTelegram Chat](Chat.md)
### Example:
### Example ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)):
```php
$MadelineProto = new \danog\MadelineProto\API();
$MadelineProto->start();
$Chat = [yield](ASYNC.html) $MadelineProto->get_pwr_chat($id);
$Chat = yield $MadelineProto->get_pwr_chat($id);
```
Or, if you're into Lua:

View File

@ -10,14 +10,11 @@ No parameters
### Return type: [User object](API_docs/types/User.md)
### Example:
### Example ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)):
```php
$MadelineProto = new \danog\MadelineProto\API();
$MadelineProto->start();
$User = [yield](ASYNC.html) $MadelineProto->get_self();
$User = yield $MadelineProto->get_self();
```
Or, if you're into Lua:

View File

@ -9,10 +9,10 @@ Logs you out
### Return type: boolean
### Example:
### Example ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)):
```php
[yield](ASYNC.html) $MadelineProto->logout();
yield $MadelineProto->logout();
```

View File

@ -16,23 +16,20 @@ description: phone_login parameters, return type and example
You must then use [complete_phone_login](complete_phone_login.md)
### Example:
### Example ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)):
```php
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->async(true);
[yield](ASYNC.html) $MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = [yield](ASYNC.html) $MadelineProto->complete_phone_login(readline('Enter the code you received: '));
yield $MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = yield $MadelineProto->complete_phone_login(readline('Enter the code you received: '));
if ($authorization['_'] === 'account.noPassword') {
throw new \danog\MadelineProto\Exception('2FA is enabled but no password is set!');
}
if ($authorization['_'] === 'account.password') {
$authorization = [yield](ASYNC.html) $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
$authorization = yield $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
}
if ($authorization['_'] === 'account.needSignup') {
$authorization = [yield](ASYNC.html) $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
$authorization = yield $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
}
```

View File

@ -15,14 +15,10 @@ description: request_secret_chat parameters, return type and example
Returns the secret chat ID
### Example:
### Example ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html)):
```php
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->start();
$MadelineProto->async(true);
$secret_chat_id = [yield](ASYNC.html) $MadelineProto->request_secret_chat('@danogentili');
$secret_chat_id = yield $MadelineProto->request_secret_chat('@danogentili');
```