MadelineProtoDocs/docs/index.md
2019-12-27 21:25:13 +01:00

81 KiB

title description image
MadelineProto documentation PHP client/server for the telegram MTProto protocol (a better tg-cli) https://docs.madelineproto.xyz/favicons/android-chrome-256x256.png

MadelineProto, a PHP MTProto telegram client

Created by Daniil Gentili

Do join the official channel, @MadelineProto and the support groups!

Now with Telegram TON blockchain integration!

Approved by Telegram!

What's this?

This library can be used to easily interact with Telegram without the bot API, just like the official apps.

It can login with a phone number (MTProto API), or with a bot token (MTProto API, no bot API involved!).

It is now fully async!

Getting started (now fully async!)

<?php

if (!file_exists('madeline.php')) {
    copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
include 'madeline.php';

$MadelineProto = new \danog\MadelineProto\API('session.madeline');
$MadelineProto->async(true);
$MadelineProto->loop(function () use ($MadelineProto) {
    yield $MadelineProto->start();

    $me = yield $MadelineProto->getSelf();

    $MadelineProto->logger($me);

    if (!$me['bot']) {
        yield $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => "Hi!\nThanks for creating MadelineProto! <3"]);
        yield $MadelineProto->channels->joinChannel(['channel' => '@MadelineProto']);

        try {
            yield $MadelineProto->messages->importChatInvite(['hash' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg']);
        } catch (\danog\MadelineProto\RPCErrorException $e) {
            $MadelineProto->logger($e);
        }

        yield $MadelineProto->messages->sendMessage(['peer' => 'https://t.me/joinchat/Bgrajz6K-aJKu0IpGsLpBg', 'message' => 'Testing MadelineProto!']);
    }
    yield $MadelineProto->echo('OK, done!');
});

Try this code now! or run this code in a browser or in a console.

Tip: if you receive an error (or nothing), send us the error message and the MadelineProto.log file that was created in the same directory (if running from a browser).

Documentation

Very complex and complete examples

You can find examples for nearly every MadelineProto function in

  • magnaluna webradio - Multifeatured Telegram VoIP webradio
  • tests/testing.php - examples for making/receiving calls, making secret chats, sending secret chat messages, videos, audios, voice recordings, gifs, stickers, photos, sending normal messages, videos, audios, voice recordings, gifs, stickers, photos.
  • bot.php - examples for sending normal messages, downloading any media
  • secret_bot.php - secret chat bot
  • pipesbot.php - examples for creating inline bots and using other inline bots via a userbot