Added mytelegramorg docs

This commit is contained in:
Daniil Gentili 2019-06-05 15:53:02 +02:00
parent 04a2ff69f3
commit 67df53f466
3 changed files with 59 additions and 5 deletions

View File

@ -20,6 +20,7 @@ Powered by [amphp](https://amphp.org), MadelineProto wraps the AMPHP APIs to pro
* [MadelineProto and AMPHP async APIs](#madelineproto-and-amphp-async-apis)
* [Helper methods](#helper-methods)
* [Async sleep](#async-sleep-does-not-block-the-main-thread)
* [Async readline](#async-readline-does-not-block-the-main-thread)
* [MadelineProto artax HTTP client](#madelineproto-artax-http-client)
* [Async forking](#async-forking-does-single-thread-forking)
* [Combining async operations](#combining-async-operations)
@ -184,7 +185,7 @@ $result = blocking_function();
Sometimes, you have to call non-async functions in your code: that is allowed in async MadelineProto, you just have to call your functions normally without `yield`.
However, you shouldn't do (or need to do) this, because this renders async completely useless.
AMPHP already provides async versions of curl, `file_get_contents`, MySQL, redis, postgres, and many more native PHP functions:
AMPHP and MadelineProto already provide async versions of curl, `file_get_contents`, MySQL, redis, postgres, and many more native PHP functions:
## MadelineProto and AMPHP async APIs
@ -201,6 +202,10 @@ MadelineProto also provides a few generic async helper methods: when possible, a
```php
yield $MadelineProto->sleep(3);
```
#### Async readline (does not block the main thread)
```php
$res = yield $MadelineProto->readLine('Optional prompt');
```
#### MadelineProto artax HTTP client

View File

@ -7,12 +7,16 @@ image: https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png
There are many ways you can login with MadelineProto.
* [Getting permission to use the telegram API](#getting-permission-to-use-the-telegram-api)
* [Automatic](#automatic-now-fully-async)
* [Manual (user)](#manual-user)
* [API ID](#api-id)
* [Manual (bot)](#manual-bot)
* [Logout](#logout)
* [Changing 2FA password](#changing-2fa-password)
## Getting permission to use the telegram API
## Automatic ([now fully async!](https://docs.madelineproto.xyz/docs/ASYNC.html))
```php
@ -25,14 +29,56 @@ You will get to choose if login as user, or as bot.
## Manual (user)
### API ID
Before logging in, you must obtain an [API ID](https://docs.madelineproto.xyz/docs/SETTINGS.html#settingsapp_info) (if you're using the [automatic mode you don't have to do this](#automatic-now-fully-async)).
You can do that either by logging in to [my.telegram.org](https://my.telegram.org) and getting your API ID/hash, or automatically, by using MadelineProto's `MyTelegramOrgWrapper` API:
```
use danog\MadelineProto\MyTelegramOrgWrapper;
$wrapper = new MyTelegramOrgWrapper($settings);
$wrapper->async(true);
yield $wrapper->login(yield $wrapper->readline('Enter your phone number (this number must already be signed up to telegram)'));
yield $wrapper->complete_login(yield $wrapper->readline('Enter the code'));
if (yield $wrapper->logged_in()) {
if (yield $wrapper->has_app()) {
$app = yield $wrapper->get_app();
} else {
$app_title = yield $wrapper->readLine('Enter the app\'s name, can be anything: ');
$short_name = yield $wrapper->readLine('Enter the app\'s short name, can be anything: ');
$url = yield $wrapper->readLine('Enter the app/website\'s URL, or t.me/yourusername: ');
$description = yield $wrapper->readLine('Describe your app: ');
$app = yield $wrapper->my_telegram_org_wrapper->create_app_async(['app_title' => $app_title, 'app_shortname' => $short_name, 'app_url' => $url, 'app_platform' => 'web', 'app_desc' => $description]);
}
\danog\MadelineProto\Logger::log($app);
}
```
This wrapper allows you to automatically login to [my.telegram.org](https://my.telegram.org) and create an app associated to the specified user (the specified phone number must be already signed up to telegram).
[Async](ASYNC.html) is handled exactly like in MadelineProto, with an `async` method that can be used to enable or disable async functionality.
The readline wrapper (see [Async](ASYNC.html)) can also be used with the the `MyTelegramOrgWrapper` API.
The constructor of the API is optional, and can be an array of [MadelineProto settings](https://docs.madelineproto.xyz/docs/SETTINGS.html): it can be used to set proxy info (only HTTP and SOCKS is supported for this).
After you provide an API ID, you can then login (if you're using the [automatic mode you don't have to do this](#automatic-now-fully-async)).
```php
yield $MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = yield $MadelineProto->complete_phone_login(readline('Enter the phone code: '));
yield $MadelineProto->phone_login(yield $MadelineProto->readline('Enter your phone number: '));
$authorization = yield $MadelineProto->complete_phone_login(yield $MadelineProto->readline('Enter the phone code: '));
if ($authorization['_'] === 'account.password') {
$authorization = yield $MadelineProto->complete_2fa_login(readline('Please enter your password (hint '.$authorization['hint'].'): '));
$authorization = yield $MadelineProto->complete_2fa_login(yield $MadelineProto->readline('Please enter your password (hint '.$authorization['hint'].'): '));
}
if ($authorization['_'] === 'account.needSignup') {
$authorization = yield $MadelineProto->complete_signup(readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
$authorization = yield $MadelineProto->complete_signup(yield $MadelineProto->readline('Please enter your first name: '), readline('Please enter your last name (can be empty): '));
}
```

View File

@ -70,6 +70,7 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro
* [MadelineProto and AMPHP async APIs](https://docs.madelineproto.xyz/docs/ASYNC.html#madelineproto-and-amphp-async-apis)
* [Helper methods](https://docs.madelineproto.xyz/docs/ASYNC.html#helper-methods)
* [Async sleep](https://docs.madelineproto.xyz/docs/ASYNC.html#async-sleep-does-not-block-the-main-thread)
* [Async readline](https://docs.madelineproto.xyz/docs/ASYNC.html#async-readline-does-not-block-the-main-thread)
* [MadelineProto artax HTTP client](https://docs.madelineproto.xyz/docs/ASYNC.html#madelineproto-artax-http-client)
* [Async forking](https://docs.madelineproto.xyz/docs/ASYNC.html#async-forking-does-single-thread-forking)
* [Combining async operations](https://docs.madelineproto.xyz/docs/ASYNC.html#combining-async-operations)
@ -81,8 +82,10 @@ Tip: if you receive an error (or nothing), [send us](https://t.me/pwrtelegramgro
* [GenericLoop](https://docs.madelineproto.xyz/docs/ASYNC.html#genericloop)
* [Creating a client](https://docs.madelineproto.xyz/docs/CREATING_A_CLIENT.html)
* [Logging in](https://docs.madelineproto.xyz/docs/LOGIN.html)
* [Getting permission to use the telegram API](https://docs.madelineproto.xyz/docs/LOGIN.html#getting-permission-to-use-the-telegram-api)
* [Automatic](https://docs.madelineproto.xyz/docs/LOGIN.html#automatic-now-fully-async)
* [Manual (user)](https://docs.madelineproto.xyz/docs/LOGIN.html#manual-user)
* [API ID](https://docs.madelineproto.xyz/docs/LOGIN.html#api-id)
* [Manual (bot)](https://docs.madelineproto.xyz/docs/LOGIN.html#manual-bot)
* [Logout](https://docs.madelineproto.xyz/docs/LOGIN.html#logout)
* [Changing 2FA password](https://docs.madelineproto.xyz/docs/LOGIN.html#changing-2fa-password)