danog / MadelineProto

Async PHP client API for the telegram MTProto protocol
https://docs.madelineproto.xyz
GNU Affero General Public License v3.0
2.79k stars 632 forks source link

Error: Trying to get property of non-object #364

Closed sallsabil closed 6 years ago

sallsabil commented 6 years ago

In the new version and this code:

class EventHandler extends \danog\MadelineProto\EventHandler
{
    public function __construct($MadelineProto)
    {
        parent::__construct($MadelineProto);
    }
    public function onAny($update)
    {
        \danog\MadelineProto\Logger::log("Received an update of type ".$update['_']);
    }
    public function onUpdateNewChannelMessage($update)
    {
        $this->onUpdateNewMessage($update);
    }
    public function onUpdateNewMessage($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' => "channel#1023456789", 'message' => "turu"]);
        } catch (\Exception $e) {
    print_r($e);
        }
        echo '0';
    }
}

I receive this error:

[previous:Exception:private] => [tl_trace] => APIFactory.php(130): ExceptionErrorHandler(8,"Trying to get property of non-object","\/root\/MadelineProtoBot\/MadelineProto\/src\/danog\/MadelineProto\/APIFactory.php",130,{"name":"sendMessage","arguments":[{"peer":"channel#1023456789","message":"turu"}]}) userbot.php(90):

What is the problem ?

danog commented 6 years ago

Please send me the full code.

sallsabil commented 6 years ago
<?php
set_time_limit(0);
ignore_user_abort(true);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
ob_end_clean();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
ob_implicit_flush(1);

require '/root/MadelineProtoBot/MadelineProto/vendor/autoload.php';

require __DIR__ . '/classes/setexpf.php';
require __DIR__ . '/classes/tg.php';

$setexpf = new setexpf();
$tg = new Tg();

require __DIR__ . '/settings.php';

    $mem = new Memcached();
    $mem->addServer("127.0.0.1", 11211);

        $fn = htmlspecialchars('547547');
    $phone = '+'.$fn;
    $code = '';

$settings = [
    'logger' => ['logger' => 0],
    'app_info' => [
        'api_id'          => 1,
        'api_hash'        => '5gg'
    ],
    'flood_timeout' => [
        'wait_if_lt' => 90000
    ],
    'serialization' => [
        'serialization_interval' => 10
    ]
        ];

$sessionf = __DIR__ . "/tmp/sess_".str_replace('+', '', $phone);

class EventHandler extends \danog\MadelineProto\EventHandler
{
    public function __construct($MadelineProto)
    {
        parent::__construct($MadelineProto);
    }
    public function onAny($update)
    {
        \danog\MadelineProto\Logger::log("Received an update of type ".$update['_']);
    }
    public function onUpdateNewChannelMessage($update)
    {
        $this->onUpdateNewMessage($update);
    }
    public function onUpdateNewMessage($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' => "channel#1023456789", 'message' => "turu"]);
        } catch (\Exception $e) {
    print_r($e);
        }
        echo '0';
    }
}

try {
    $MadelineProto = new \danog\MadelineProto\API($sessionf, $settings);
} catch (\danog\MadelineProto\Exception $e) {
    \danog\MadelineProto\Logger::log($e->getMessage());
    unlink($sessionf);
    $MadelineProto = new \danog\MadelineProto\API($sessionf, $settings);
}

$MadelineProto->start();
$MadelineProto->setEventHandler('\EventHandler');
$MadelineProto->loop();
danog commented 6 years ago

Update to the latest version.

sallsabil commented 6 years ago

It is the last version.

danog commented 6 years ago

@sallsabil Then delete the session and relogin.