MadelineProtoDocs/docs/docs/USING_METHODS.md
2019-06-01 18:08:28 +02:00

4.7 KiB

title description image
Using methods There are simplifications for many, if not all of, these methods. https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png

Using methods

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

Now fully async!

Peers

Full example

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.

yield $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'Testing MadelineProto...']);

If you want to check if a bot API id is a supergroup/channel ID:

$Bool = yield $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:

$bot_api_id = yield $MadelineProto->to_supergroup($id);

Uses logarithmic conversion to avoid problems on 32 bit systems.

Secret chats

Full example 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:

yield $MadelineProto->messages->sendEncrypted(['peer' => $update, 'message' => ['_' => 'decryptedMessage', 'ttl' => 0, 'message' => 'Hi']]);

Entities

Full example Methods that allow sending message entities (messages.sendMessage for example) also have an additional parse_mode parameter that enables or disables html/markdown parsing of the message to be sent.

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

reply_markup

reply_markup accepts bot API reply markup objects as well as MTProto ones.

$bot_API_markup = ['inline_keyboard' => 
    [
        [
            ['text' => 'MadelineProto docs', 'url' => 'https://docs.madelineproto.xyz'],
            ['text' => 'MadelineProto channel', 'url' => 'https://t.me/MadelineProto']
        ]
    ]
];
yield $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel', 'reply_markup' => $bot_API_markup]);

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.

$bot_API_object = yield $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel'], ['botAPI' => true]);

MadelineProto also supports bot API file IDs when working with files

No result

Also see ignored async.
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.

yield $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => 'lel'], ['noResponse' => true]);

Queues

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):

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.

Next section