#!/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')) { echo 'You did not run composer update, using madeline.php'.PHP_EOL; 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; } $res = json_encode($update, JSON_PRETTY_PRINT); if ($res == '') { $res = var_export($update, true); } try { $this->messages->sendMessage(['peer' => $update, 'message' => $res, 'reply_to_msg_id' => isset($update['message']['id']) ? $update['message']['id'] : null, 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]); } catch (\danog\MadelineProto\RPCErrorException $e) { \danog\MadelineProto\Logger::log((string)$e, \danog\MadelineProto\Logger::FATAL_ERROR); } catch (\danog\MadelineProto\Exception $e) { \danog\MadelineProto\Logger::log((string)$e, \danog\MadelineProto\Logger::FATAL_ERROR); //$this->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]); } } } $settings = ['app_info' => ['api_id' => 6, 'api_hash' => 'eb06d4abfb49dc3eeb1aeb98ae0f581e'], 'updates' => ['handle_updates' => true]]; $MadelineProto = new \danog\MadelineProto\API('bot.madeline', $settings); $MadelineProto->start(); $MadelineProto->setEventHandler('\EventHandler'); $MadelineProto->loop();