skip to Main Content

I need to add the Telegram madelineproto library to my Laravel project. How can I do it via composer and How can I call it in my controllers

3

Answers


  1. You can’t add it via composer.
    https://packagist.org/packages/danog/madelineproto
    It’s not a package. It’s whole project.

    If you look at https://github.com/danog/MadelineProto/blob/master/composer.json
    You will see it’s not a package.

    {
        "name": "danog/madelineproto",
        "description": "PHP implementation of telegram's MTProto protocol.",
        "type": "project",
    }
    
    Login or Signup to reply.
  2. for faster code, use these steps:

    Step 1:

    download the danog/MadelineProto as a zip file, export the content of the zip file on a folder named ‘lib/MadelineProto-master’,

    Step 2:

    use terminal to compose the MadelineProto venders

    cd lib/MadelineProto-master
    composer install --ignore-platform-reqs
    

    --ignore-platform-reqs is needed to ignore the PHP version and so on.
    the composer will download all the vender on lib/MadelineProto-master/vendor

    Step 3:

    on your controller call the project lib like this:

    
    
    require_once '../lib/MadelineProto-master/vendor/autoload.php';
    
    //*/
    class TelegramController extends Controller
    {
    
        private function sendMessage()
        {
    
            $settings['app_info']['api_id'] = '##';
            $settings['app_info']['api_hash'] = '####';
    
    
            $MadelineProto = new danogMadelineProtoAPI('session.madeline', $settings);
    
            $MadelineProto->start();
    
            $me = $MadelineProto->getSelf();
    
            if (!$me['bot']) {
    
                $sendMessage =  $MadelineProto->messages->sendMessage([
                    'peer' => '@mansourcodes',
                    'message' => "Hi! <3"
                ]);
    
            }
    
        }
    }
    

    Slow Solution:

    this solution will take 3-4s per call:

    if (!file_exists('madeline/madeline.php')) {
        copy('https://phar.madelineproto.xyz/madeline.php', 'madeline/madeline.php');
    }
    require_once 'madeline/madeline.php';
    
    class TelegramController extends Controller
    {
    // ....
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search