#!/usr/bin/env php . */ set_include_path(get_include_path().':'.realpath(dirname(__FILE__).'/MadelineProto/')); /* * Various ways to load MadelineProto */ if (!file_exists(__DIR__.'/vendor/autoload.php')) { if (!file_exists('madeline.php')) { copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php'); } include 'madeline.php'; } else { require_once 'vendor/autoload.php'; } class EventHandler extends \danog\MadelineProto\EventHandler { public function onAny($update) { if (isset($update['message']['out']) && $update['message']['out']) { return; } if ($update['_'] === 'updateReadChannelOutbox') { return; } if (isset($update['message']['_']) && $update['message']['_'] === 'messageEmpty') { return; } $res = json_encode($update, JSON_PRETTY_PRINT); try { yield $this->messages->sendMessage(['peer' => $update, 'message' => "$res", 'reply_to_msg_id' => isset($update['message']['id']) ? $update['message']['id'] : null, 'parse_mode' => 'HTML']); //'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]); if (isset($update['message']['media']) && $update['message']['media']['_'] !== 'messageMediaGame') { yield $this->messages->sendMedia(['peer' => $update, 'message' => $update['message']['message'], 'media' => $update]); //yield $this->download_to_dir($update, '/tmp'); } } catch (\danog\MadelineProto\RPCErrorException $e) { $this->logger((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR); } catch (\danog\MadelineProto\Exception $e) { if (stripos($e->getMessage(), 'invalid constructor given') === false) { $this->logger((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR); } //$this->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]); } } } $settings = ['logger' => ['logger_level' => 5]]; $MadelineProto = new \danog\MadelineProto\API('testing.madeline', $settings); $MadelineProto->async(true); $MadelineProto->loop(function () use ($MadelineProto) { yield $MadelineProto->start(); yield $MadelineProto->setEventHandler('\EventHandler'); }); $MadelineProto->loop();