1
0
mirror of https://github.com/danog/MadelineProto.git synced 2024-11-30 04:08:59 +01:00

Fixes to docs

This commit is contained in:
Daniil Gentili 2018-03-20 12:04:44 +00:00
parent 7a0153a139
commit e21fa6b884
19 changed files with 126 additions and 111 deletions

View File

@ -11,7 +11,7 @@ It can login with a phone number (MTProto API), or with a bot token (MTProto API
## Getting started
```
```php
<?php
if (!file_exists('madeline.php')) {
@ -50,13 +50,13 @@ Run this code in a browser or in a console.
* [Composer from existing project](https://docs.madelineproto.xyz/docs/INSTALLATION.html#composer-from-existing-project)
* [Git](https://docs.madelineproto.xyz/docs/INSTALLATION.html#git)
* [Handling updates](https://docs.madelineproto.xyz/docs/UPDATES.html)
* [Event driven](https://docs.madelineproto.xyz/docs/UPDATES.html#event-handler)
* [Event driven multithreaded](https://docs.madelineproto.xyz/docs/UPDATES.html#multithreaded-event-handler)
* [Event driven](https://docs.madelineproto.xyz/docs/UPDATES.html#event-driven)
* [Event driven multithreaded](https://docs.madelineproto.xyz/docs/UPDATES.html#event-driven-multithreaded)
* [Webhook](https://docs.madelineproto.xyz/docs/UPDATES.html#webhook)
* [Webhook multithreaded](https://docs.madelineproto.xyz/docs/UPDATES.html#multithreaded-webhook)
* [Long polling (getupdates)](https://docs.madelineproto.xyz/docs/UPDATES.html#getupdates)
* [Webhook multithreaded](https://docs.madelineproto.xyz/docs/UPDATES.html#webhook-multithreaded)
* [Long polling (getupdates)](https://docs.madelineproto.xyz/docs/UPDATES.html#long-polling)
* [Callback](https://docs.madelineproto.xyz/docs/UPDATES.html#callback)
* [Callback multithreaded](https://docs.madelineproto.xyz/docs/UPDATES.html#multithreaded-callback)
* [Callback multithreaded](https://docs.madelineproto.xyz/docs/UPDATES.html#callback-multithreaded)
* [Settings](https://docs.madelineproto.xyz/docs/SETTINGS.html)
* [Getting info about the current user](https://docs.madelineproto.xyz/docs/SELF.html)
* [Exceptions](https://docs.madelineproto.xyz/docs/EXCEPTIONS.html)

View File

@ -1,6 +1,6 @@
# Calls
```
```php
if (!file_exists('input.raw')) {
echo 'Downloading example song'.PHP_EOL;
copy('https://github.com/danog/MadelineProto/raw/master/input.raw', 'input.raw');
@ -22,7 +22,7 @@ The wrapper consists in the `\danog\MadelineProto\VoIP` class, that can be insta
## Requesting a call
```
```php
$call = $MadelineProto->request_call('@danogentili');
```
@ -35,7 +35,7 @@ MadelineProto works using raw signed PCM audio with the sample rate and the bit
Input/output audio can be converted from/to any audio/video file using ffmpeg:
```
```bash
ffmpeg -i anyaudioorvideo.mp3 -f s16le -ac 1 -ar 48000 -acodec pcm_s16le mysong.raw
```
@ -43,7 +43,7 @@ ffmpeg -i anyaudioorvideo.mp3 -f s16le -ac 1 -ar 48000 -acodec pcm_s16le mysong.
You can also play streams:
```
```bash
mkfifo mystream.raw
ffmpeg -i http://icestreaming.rai.it/1.mp3 -f s16le -ac 1 -ar 48000 -acodec pcm_s16le pipe:1 > mystream.raw
```
@ -57,7 +57,7 @@ The best way to raise the bitrate is to let libtgvoip do it automatically, based
However, the usual outgoing bitrate used by telegram for ethernet networks is around 20kbps. That is clearly not enough.
To increase it, you must modify the shared settings:
```
```php
$controller->configuration['shared_config']['audio_init_bitrate'] = 60 * 1000; // Audio bitrate set when the call is started
$controller->configuration['shared_config']['audio_max_bitrate'] => 70 * 1000; // Maximum audio bitrate
$controller->configuration['shared_config']['audio_min_bitrate'] => 15 * 1000; // Minimum audio bitrate
@ -80,7 +80,7 @@ If you manually set the network type to NET_TYPE_GPRS, NET_TYPE_EDGE, or enabled
Requesting calls is easy, just run the `request_call` method.
```
```php
$controller = $MadelineProto->request_call('@danogentili')->play('input.raw')->then('inputb.raw')->playOhHold(['hold.raw'])->setOutputFile('output.raw');
$controller->configuration['log_file_path'] = $controller->getOtherID().'.log';
@ -97,8 +97,7 @@ Accepting calls is just as easy: you will receive an [updatePhoneCall](https://d
This array will contain a VoIP object under the `phone_call` key.
```
```php
$updates = $MadelineProto->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout
foreach ($updates as $update) {
\danog\MadelineProto\Logger::log([$update]);

View File

@ -7,7 +7,7 @@ There are various methods that can be used to fetch info about chats, based on b
* [Reduced chat info (very fast)](#get_info)
## get_pwr_chat
```
```php
$pwr_chat = $MadelineProto->get_pwr_chat(-100214891824);
foreach ($pwr_chat['participants'] as $participant) {
\danog\MadelineProto\Logger::log($participant);
@ -21,7 +21,7 @@ Use `get_pwr_chat` to get full chat info, including the full list of members, se
* Caching: medium
## get_full_info
```
```php
$full_chat = $MadelineProto->get_full_info(-10028941842);
```
@ -32,7 +32,7 @@ You can also use `get_full_info` to get full chat info, without the full list of
* Caching: full
## get_info
```
```php
$chat = $MadelineProto->get_info(-10028941842);
```

View File

@ -12,7 +12,7 @@ You can help by translating MadelineProto in your language.
Fork github.com/danog/MadelineProto, then run
```
```php
git clone https://github.com/youruser/MadelineProto
php translate.php
git commit -am 'Added yourlanguage'
@ -27,7 +27,7 @@ Then create a pull request from branch `localization-yourlanguage`
You can use this scheme of the structure of this project to help yourself:
```
```php
build_docs.php - Builds API docs from TL scheme file
src/danog/MadelineProto/
MTProtoTools/

View File

@ -5,17 +5,17 @@ To store information about an account session and avoid re-logging in, serializa
A MadelineProto session is automatically serialized every `$MadelineProto->settings['serialization']['serialization_interval']` seconds (by default 30 seconds), and on shutdown. If the scripts shutsdown normally (without ctrl+c or fatal errors/exceptions), the session will also be serialized automatically.
To create the session and set the serialization destination file, do the following:
```
```php
$MadelineProto = new \danog\MadelineProto\API('session.madeline', $settings); // The session will be serialized to session.madeline
```
Do the same to load a serialized session:
```
```php
$MadelineProto = new \danog\MadelineProto\API('session.madeline', $settings); // The session will be loaded from session.madeline
```
To change the session file after starting MadelineProto, do the following:
```
```php
$MadelineProto->session = 'newsession.madeline';
```

View File

@ -6,7 +6,7 @@ There are two ways to get a list of all chats, depending if you logged in as a u
* [As bot](#bot-internal-peer-database)
## User: get_dialogs
```
```php
$dialogs = $MadelineProto->get_dialogs();
foreach ($dialogs as $peer) {
$MadelineProto->messages->sendMessage(['peer' => $peer, 'message' => 'Hi! Testing MadelineProto broadcasting!']);
@ -16,7 +16,7 @@ foreach ($dialogs as $peer) {
`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)
## Bot: internal peer database
```
```php
foreach ($MadelineProto->API->chats as $bot_api_id => $chat) {
try {
$MadelineProto->messages->sendMessage(['peer' => $chat, 'message' => "Hi $bot_api_id! Testing MadelineProto broadcasting!"]);
@ -27,4 +27,4 @@ foreach ($MadelineProto->API->chats as $bot_api_id => $chat) {
```
Since bots cannot run `get_dialogs`, you must make use of the internal MadelineProto database to get a list of all users, chats and channels MadelineProto has seen.
`$MadelineProto->API->chats` contains a list of [Chat](../API_docs/types/Chat.md) and [User](../API_docs/types/User.md) objects, indexed by bot API id.
`$MadelineProto->API->chats` contains a list of [Chat](../API_docs/types/Chat.md) and [User](../API_docs/types/User.md) objects, indexed by bot API id.

View File

@ -1,6 +1,6 @@
# Exceptions
```
```php
try {
$MadelineProto->get_dialogs();
} catch (\danog\MadelineProto\RPCErrorException $e) {
@ -39,7 +39,7 @@ MadelineProto can throw lots of different exceptions.
## Pretty TL trace
Every exception features a custom stack trace called `pretty TL trace`, that makes finding bugs **really** easy:
```
```php
php > $MadelineProto->messages->sendMessage(['peer' => '@dd', 'message' => 'hi']);
Uncaught \danog\MadelineProto\Exception: This peer is not present in the internal peer database in /home/pwrtelegram/cleanMadeline/src/danog/MadelineProto/MTProtoTools/PeerHandler.php:330
@ -83,7 +83,7 @@ This part is supposed to be read from bottom to top, the most important parts ar
`While serializing: messages.sendMessage`: this means the error was thrown while serializing the method call for messages->sendMessage
`['peer']`: this means the error was thrown while trying to serialize the `peer` parameter, so **you should fix that part of your code**:
```
```php
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'hi']);
```
@ -91,7 +91,7 @@ $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'h
To get the whole TL trace as string, cast the exception object to string:
```
```php
try {
//
} catch (\danog\MadelineProto\Exception $e) {
@ -100,4 +100,4 @@ try {
$estring3 = "So does this: $e";
// use $estring to report the error using sendMessage or log
}
```
```

View File

@ -40,7 +40,7 @@ To disable automatic uploads by file name, set `$MadelineProto->settings['upload
### [inputMediaUploadedPhoto](https://docs.madelineproto.xyz/API_docs/constructors/inputMediaUploadedPhoto.html)
```
```php
$sentMessage = $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
@ -55,7 +55,7 @@ $sentMessage = $MadelineProto->messages->sendMedia([
Can be used to upload photos: simply provide the photo's file path in the `file` field, and optionally provide a `ttl_seconds` field to set the self-destruction period of the photo, even for normal chats
### [inputMediaUploadedDocument](https://docs.madelineproto.xyz/API_docs/constructors/inputMediaUploadedDocument.html)
```
```php
$sentMessage = $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
@ -77,7 +77,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 = $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
@ -94,7 +94,7 @@ $sentMessage = $MadelineProto->messages->sendMedia([
### [documentAttributeImageSize](https://docs.madelineproto.xyz/API_docs/constructors/documentAttributeImageSize.html) to send a photo as document
```
```php
$sentMessage = $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
@ -111,7 +111,7 @@ $sentMessage = $MadelineProto->messages->sendMedia([
```
### [documentAttributeAnimated](https://docs.madelineproto.xyz/API_docs/constructors/documentAttributeAnimated.html) to send a gif
```
```php
$sentMessage = $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
@ -127,7 +127,7 @@ $sentMessage = $MadelineProto->messages->sendMedia([
```
### [documentAttributeVideo](https://docs.madelineproto.xyz/API_docs/constructors/documentAttributeVideo.html) to send a video
```
```php
$sentMessage = $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
@ -148,7 +148,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 = $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
@ -168,7 +168,7 @@ Set the `voice` parameter to true to send a voice message.
## Uploading files
```
```php
$MessageMedia = $MadelineProto->messages->uploadMedia([
'media' => [
'_' => 'inputMediaUploadedPhoto',
@ -183,7 +183,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 = $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => $MessageMedia,
@ -200,13 +200,13 @@ $sentMessage = $MadelineProto->messages->sendMedia([
Actual MessageMedia objects can also be converted to bot API file IDs like this:
```
```php
$botAPI_file = $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:
```
```php
foreach (['audio', 'document', 'photo', 'sticker', 'video', 'voice', 'video_note'] as $type) {
if (isset($botAPI_file[$type]) && is_array($botAPI_file[$type])) {
$method = $type;
@ -249,13 +249,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 = $MadelineProto->upload('filename.mp4');
```
The generated `$inputFile` can later be reused thusly:
```
```php
$sentMessage = $MadelineProto->messages->sendMedia([
'peer' => '@danogentili',
'media' => [
@ -292,7 +292,7 @@ The concept is easy: where you would usually provide a file path, simply provide
There are multiple download methods that allow you to download a file to a directory, to a file or to a stream.
### Extracting download info
```
```php
$info = $MadelineProto->get_download_info($MessageMedia);
```
@ -304,7 +304,7 @@ $info = $MadelineProto->get_download_info($MessageMedia);
* `$info['size']` - The file size
### Download to directory
```
```php
$output_file_name = $MadelineProto->download_to_dir($MessageMedia, '/tmp/');
```
@ -313,7 +313,7 @@ This downloads the given file to `/tmp`, and returns the full generated file pat
`$MessageMedia` can be either a [Message](https://docs.madelineproto.xyz/API_docs/types/Message.html), an [Update](https://docs.madelineproto.xyz/API_docs/types/Update.html), a [MessageMedia](https://docs.madelineproto.xyz/API_docs/types/MessageMedia.html) object, or a bot API file ID.
### Download to file
```
```php
$output_file_name = $MadelineProto->download_to_file($MessageMedia, '/tmp/myname.mp4');
```
@ -323,7 +323,7 @@ This downloads the given file to `/tmp/myname.mp4`, and returns the full file pa
### Download to browser with streams
```
```php
$info = $MadelineProto->get_download_info($MessageMedia);
header('Content-Length: '.$info['size']);
header('Content-Type: '.$info['mime']);
@ -349,7 +349,7 @@ This downloads the given file to the browser, sending also information about the
To get the upload/download progress in real-time, use the `\danog\MadelineProto\FileCallback` class:
```
```php
$peer = '@danogentili';
$sentMessage = $MadelineProto->messages->sendMedia([
'peer' => $peer,
@ -385,7 +385,7 @@ This will send the file `video.mp4` to [@danogentili](https://t.me/danogentili):
A FileCallback object can be provided to `uploadMedia`, `sendMedia`, `uploadProfilePicture`, `upload`, `upload_encrypted`, `download_to_*`: the first parameter to its constructor must be the file path/object that is usually accepted by the function, the second must be a callable function or object.
You can also write your own callback class, just implement `\danog\MadelineProto\FileCallbackInterface`:
```
```php
class MyCallback implements \danog\MadelineProto\FileCallbackInterface
{
private $file;

View File

@ -2,7 +2,7 @@
You can easily click inline buttons using MadelineProto, just access the correct button:
```
```php
class EventHandler extends \danog\MadelineProto\EventHandler
{
public function onUpdateNewChannelMessage($update)
@ -40,13 +40,13 @@ This peice of code will automatically click all buttons in all keyboards sent in
You can then access properties of `$button` (they vary depending on the [type of button](https://docs.madelineproto.xyz/API_docs/types/KeyboardButton.html)):
```
```php
$text = $button['text'];
```
And click them:
```
```php
$button->click();
```

View File

@ -70,7 +70,7 @@ composer update
```
Put the following code in your PHP file:
```
```php
<?php
require_once 'vendor/autoload.php';
```
@ -79,7 +79,7 @@ require_once 'vendor/autoload.php';
Once you have all the requirements installed properly (on dev as well as production), add this to the ```composer.json``` file:
```
```json
"repositories": [
{
"type": "git",
@ -90,13 +90,13 @@ Once you have all the requirements installed properly (on dev as well as product
Make sure you also have these set in the composer.json:
```
```json
"minimum-stability": "dev",
```
Then you can require the package by addding the following line to the require section:
```
```json
"danog/madelineproto":"dev-master"
```
@ -106,7 +106,7 @@ Then you can require the package by addding the following line to the require se
Run the following commands in a console:
```
```bash
mkdir MadelineProtoBot
cd MadelineProtoBot
git init .

View File

@ -2,7 +2,7 @@
MadelineProto provides a unified class for logging messages to the logging destination defined in [settings](SETTINGS.md).
```
```php
\danog\MadelineProto\Logger::log($message, $level);
```

View File

@ -9,7 +9,7 @@ There are many ways you can login with MadelineProto.
## Automatic
```
```php
$MadelineProto->start();
```
@ -19,7 +19,7 @@ You will get to choose if login as user, or as bot.
## Manual (user)
```
```php
MadelineProto->phone_login(readline('Enter your phone number: '));
$authorization = $MadelineProto->complete_phone_login(readline('Enter the phone code: '));
if ($authorization['_'] === 'account.password') {
@ -40,7 +40,7 @@ If the account does not have an account, use `complete_signup` to signup, see [h
## Manual (bot)
```
```php
$MadelineProto->bot_login('34298141894:aflknsaflknLKNFS');
```
@ -51,7 +51,7 @@ Note that when you login as a bot, MadelineProto also logins using the [PWRTeleg
## Logout
```
```php
$MadelineProto->logout();
```

View File

@ -12,7 +12,7 @@ Just send 10$ to paypal.me/danog, specifying the the proxy you wish to receive a
## Building a proxy class
```
```php
class MyProxy implements \danog\MadelineProto\Proxy
{
//...
@ -29,93 +29,93 @@ Your proxy class can also have a setExtra method that accepts an array as the fi
The `\Socket` class has the following methods (all of the following methods must also be implemented by your proxy class):
```public function __construct(int $domain, int $type, int $protocol);```
`public function __construct(int $domain, int $type, int $protocol);`
Works exactly like the [socket_connect](http://php.net/manual/en/function.socket-connect.php) function.
```public function setOption(int $level, int $name, $value);```
`public function setOption(int $level, int $name, $value);`
Works exactly like the [socket_set_option](http://php.net/manual/en/function.socket-set-option.php) function.
```public function getOption(int $name, $value);```
`public function getOption(int $name, $value);`
Works exactly like the [socket_get_option](http://php.net/manual/en/function.socket-get-option.php) function.
```public function setBlocking(bool $blocking);```
`public function setBlocking(bool $blocking);`
Works like the [socket_block](http://php.net/manual/en/function.socket-set-block.php) or [socket_nonblock](http://php.net/manual/en/function.socket-set-nonblock.php) functions.
```public function bind(string $address, [ int $port = 0 ]);```
`public function bind(string $address, [ int $port = 0 ]);`
Works exactly like the [socket_bind](http://php.net/manual/en/function.socket-bind.php) function.
```public function listen([ int $backlog = 0 ]);```
`public function listen([ int $backlog = 0 ]);`
Works exactly like the [socket_listen](http://php.net/manual/en/function.socket-listen.php) function.
```public function accept();```
`public function accept();`
Works exactly like the [socket_accept](http://php.net/manual/en/function.socket-accept.php) function.
```public function connect(string $address, [ int $port = 0 ]);```
`public function connect(string $address, [ int $port = 0 ]);`
Works exactly like the [socket_accept](http://php.net/manual/en/function.socket-connect.php) function.
```public function select(array &$read, array &$write, array &$except, int $tv_sec, int $tv_usec = 0);```
`public function select(array &$read, array &$write, array &$except, int $tv_sec, int $tv_usec = 0);`
Works exactly like the [socket_select](http://php.net/manual/en/function.socket-select.php) function.
```public function read(int $length, [ int $flags = 0 ]);```
`public function read(int $length, [ int $flags = 0 ]);`
Works exactly like the [socket_read](http://php.net/manual/en/function.socket-read.php) function.
```public function write(string $buffer, [ int $length ]);```
`public function write(string $buffer, [ int $length ]);`
Works exactly like the [socket_read](http://php.net/manual/en/function.socket-write.php) function.
```public function send(string $data, int $length, int $flags);```
`public function send(string $data, int $length, int $flags);`
Works exactly like the [socket_send](http://php.net/manual/en/function.socket-send.php) function.
```public function close();```
`public function close();`
Works exactly like the [socket_close](http://php.net/manual/en/function.socket-close.php) function.
```public function getPeerName(bool $port = true);```
`public function getPeerName(bool $port = true);`
Works like [socket_getpeername](http://php.net/manual/en/function.socket-getpeername.php): the difference is that it returns an array with the `host` and the `port`.
```public function getSockName(bool $port = true);```
`public function getSockName(bool $port = true);`
Works like [socket_getsockname](http://php.net/manual/en/function.socket-getsockname.php): the difference is that it returns an array with the `host` and the `port`.
`public function getProxyHeaders();`
Can return additional HTTP headers to use when the HTTP protocol is being used.
Can return additional HTTP headers to use when the HTTP protocol is being used.

View File

@ -4,7 +4,7 @@ MadelineProto requires the `xml`, `gmp` extensions to function properly.
To install MadelineProto dependencies on `Ubuntu`, `Debian`, `Devuan`, or any other `Debian-based` distro, run the following command in your command line:
```
```bash
sudo apt-get install python-software-properties software-properties-common
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get update

View File

@ -9,7 +9,7 @@ MadelineProto provides wrappers to work with secret chats.
## Requesting secret chats
```
```php
$secret_chat = $MadelineProto->request_secret_chat($InputUser);
```
@ -24,7 +24,7 @@ Before sending any message, you must check if the secret chat was accepted by th
## Checking secret chat status
```
```php
$status = $MadelineProto->secret_chat_status($chat);
```
@ -36,7 +36,7 @@ $status is 0 if the chat cannot be found in the local database, 1 if the chat wa
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 = $MadelineProto->get_secret_chat($chat);
/*
[

View File

@ -1,6 +1,6 @@
# Getting info about the current user
```
```php
$me = $MadelineProto->get_self();
\danog\MadelineProto\Logger::log("Hi ".$me['first_name']."!");

View File

@ -1,6 +1,6 @@
# Settings
```
```php
$MadelineProto = new \danog\MadelineProto\API('session.madeline', $settings);
$MadelineProto->settings = $settings;
```
@ -374,7 +374,7 @@ Description: Serialization will be made automatically every N seconds
You can provide part of any subsetting array, that way the remaining arrays will be automagically set to default and undefined values of specified subsetting arrays will be set to the default values.
Example:
```
```php
$MadelineProto->settings = [
'authorization' => [ // Authorization settings
'default_temp_auth_key_expires_in' => 86400, // a day
@ -384,6 +384,6 @@ $MadelineProto->settings = [
The settings array can be accessed and modified in the instantiated class by accessing the `settings` attribute of the API class:
```
```php
$MadelineProto->settings['updates']['handle_updates'] = true; // reenable update fetching
```

View File

@ -2,22 +2,22 @@
Update handling can be done in different ways:
* [Event driven](#event-handler)
* [Event driven multithreaded](#multithreaded-event-handler)
* [Event driven](#event-driven)
* [Event driven multithreaded](#event-driven-multithreaded)
* [Webhook](#webhook)
* [Webhook multithreaded](#multithreaded-webhook)
* [Long polling (getupdates)](#getupdates)
* [Webhook multithreaded](#webhook-multithreaded)
* [Long polling (getupdates)](#long-polling)
* [Callback](#callback)
* [Callback multithreaded](#multithreaded-callback)
* [Callback multithreaded](#callback-multithreaded)
IMPORTANT: Note that you should turn off update handling if you don't plan to use it because the default get_updates update handling stores updates in an array inside the MadelineProto object, without deleting old ones unless they are read using get_updates.
```
```php
$MadelineProto->settings['updates']['handle_updates'] = false;
```
## Event driven
```
```php
class EventHandler extends \danog\MadelineProto\EventHandler
{
public function onAny($update)
@ -69,7 +69,7 @@ try {
$MadelineProto->start();
$MadelineProto->setEventHandler('\EventHandler');
$MadelineProto->loop();
```
```php
This will create an event handler class `EventHandler`, create a MadelineProto session, and set the event handler class to our newly created event handler.
@ -78,7 +78,7 @@ If such a method does not exist, the `onAny` event handler method is called.
If the `onAny` event handler method does not exist, the update is ignored.
To access the `$MadelineProto` instance inside of the event handler, simply access `$this`:
```
```php
$this->messages->sendMessage(['peer' => '@danogentili', 'message' => 'hi']);
```
@ -89,7 +89,7 @@ The update handling loop is started by the `$MadelineProto->loop()` method, and
## Event driven multithreaded
To enable multithreaded update handling, pass `-1` to the `$MadelineProto->loop` method:
```
```php
$MadelineProto->loop(-1);
```
@ -98,7 +98,7 @@ Note that multiprocessing is not the same as multithreading, and should be avoid
## Webhook
```
```php
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
try {
@ -115,16 +115,16 @@ $MadelineProto->loop();
When an [Update](https://docs.madelineproto.xyz/types/Update.html) is received, a POST request is made to the provided webhook URL, with json-encoded payload containing the Update. To get a list of all possible update types, [click here](https://docs.madelineproto.xyz/types/Update.html).
The webhook can also respond with a JSON payload containing the name of a method to call and the arguments:
```
```json
{"method":"messages->sendMessage", "peer":"@danogentili", "message":"hi"}
```
The loop method will automatically restart the script if execution time runs out.
## Event driven multithreaded
## Webhook multithreaded
To enable multithreaded update handling, pass `-1` to the `$MadelineProto->loop` method:
```
```php
$MadelineProto->loop(-1);
```
@ -132,7 +132,7 @@ This way, each update could be managed faster.
## Long polling
```
```php
while (true) {
$updates = $MadelineProto->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout
\danog\MadelineProto\Logger::log($updates);
@ -165,7 +165,7 @@ The get_updates function accepts an array of options as the first parameter, and
## Callback
```
```php
$settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e']];
try {
@ -186,7 +186,7 @@ The update handling loop is started by the `$MadelineProto->loop()` method, and
## Callback multithreaded
To enable multithreaded update handling, pass `-1` to the `$MadelineProto->loop` method:
```
```php
$MadelineProto->loop(-1);
```

View File

@ -18,15 +18,31 @@ There are simplifications for many, if not all of, these methods.
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
$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 = $MadelineProto->is_supergroup($id);
```
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 = $MadelineProto->to_supergroup($id);
```
Uses logarithmic conversion to avoid problems on 32 bit systems.
## Secret chats
[Full example](https://github.com/danog/MadelineProto/blob/master/secret_bot.php)
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
$MadelineProto->messages->sendEncrypted(['peer' => $update, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => 'Hi']]);
```
@ -35,7 +51,7 @@ $MadelineProto->messages->sendEncrypted(['peer' => $update, 'message' => ['_' =>
[Full example](https://github.com/danog/MadelineProto/blob/master/tests/testing.php)
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
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => '[Testing Markdown in MadelineProto](https://docs.madelineproto.xyz)', 'parse_mode' => 'Markdown']);
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => '<a href="https://docs.madelineproto.xyz">Testing HTML in MadelineProto</a>', 'parse_mode' => 'HTML']);
```
@ -45,7 +61,7 @@ $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => '<
## reply_markup
reply_markup accepts bot API reply markup objects as well as MTProto ones.
```
```php
$bot_API_markup = ['inline_keyboard' => [
['text' => 'MadelineProto docs', 'url' => 'https://docs.madelineproto.xyz'],
['text' => 'MadelineProto channel', 'url' => 'https://t.me/MadelineProto']
@ -58,7 +74,7 @@ $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'l
## Bot API objects
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 = $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel'], ['botAPI' => true]);
```
@ -68,7 +84,7 @@ MadelineProto also [supports bot API file IDs when working with files](FILES.md)
## No result
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
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel'], ['noResponse' => true]);
```
@ -76,7 +92,7 @@ $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'l
## Call queues
Method calls may be executed at diferent times server-side: to avoid this, method calls can be queued:
```
```php
$MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel'], ['queue' => 'queue_name']);
```