Giter VIP home page Giter VIP logo

Comments (21)

danog avatar danog commented on May 17, 2024 2

Yes, use callbacks.
You must run $MadelineProto->get_updates_difference() in a loop to get updates with the callback.

from madelineproto.

danog avatar danog commented on May 17, 2024 1

Nope, Google "telegram bot API documentation"

from madelineproto.

danog avatar danog commented on May 17, 2024 1

I use pthreads for multithreading, but to enable it a ZTS version of PHP must be installed, along with the pthreads extension.

from madelineproto.

Amirjan avatar Amirjan commented on May 17, 2024 1

@nicorac I implement it with my custom event manager
If dear @danog allows it, I will publish it here

from madelineproto.

Amirjan avatar Amirjan commented on May 17, 2024 1

ApiEventsManager.php:

listeners[$event][] = $callback; } public function fire($event, array $parameters) { if (!empty($this->listeners[$event])) { foreach ($this->listeners[$event] as $listener) { call_user_func_array($listener, $parameters); } } } } ?>

in MTProto.php:

protected $eventManager;

public function __construct($settings = []){

......
$this->should_serialize = true;
$this->eventManager = new ApiEventsManager();
}

public function eventManager()
{
    return $this->eventManager;
}

/MTProtoTools/UpdateHandler.php
public function get_updates_update_handler($update)
{
if (!$this->settings['updates']['handle_updates']) {
return;
}
switch ($update['_']) {
case 'updateNewChannelMessage':
$this->eventManager()->fire('NewChannelMessage',[$update]);
break;
case 'updateNewMessage':
if (isset($update['message']['out']) && $update['message']['out']) {
break;
}
$this->eventManager()->fire('NewMessage',[$update]);
break;
}
$this->eventManager()->fire('onUpdate',[$update]);
$this->updates[$this->updates_key++] = $update;
$this->should_serialize = true;
}

from madelineproto.

danog avatar danog commented on May 17, 2024

You must increment the offset like with the bot API.

from madelineproto.

abbas980301 avatar abbas980301 commented on May 17, 2024

thanks.
after that ( increment the offset ) old updates will remove?

from madelineproto.

danog avatar danog commented on May 17, 2024

@shakibonline Yep, exactly like in the bot API

from madelineproto.

abbas980301 avatar abbas980301 commented on May 17, 2024

I use this code

$offset = 0;
while (1) {

    $updates = $MadelineProto->API->get_updates(['offset' => $offset, 'limit' => 10, 'timeout' => 1]); // Just like in the bot API, you can specify an offset, a limit and a timeout
    echo "\n\n";
    echo "===============[update]===========\n";
    echo json_encode($updates);
    echo "\n\n";

    foreach ($updates as $update) {
        $offset = $update['update_id']; // Just like in the bot API, the offset must be set to the last update_id
        // Parse $update['update'], that is an object of type Update
        if ($update['update']['_'] == 'updateNewMessage') {
            $messages_AffectedMessages = $MadelineProto->messages->readMessageContents(['id' => [$update['update']['message']['id']],]);
        }
    }
}

but it it didn't mark as read messages! what is wrong??

from madelineproto.

danog avatar danog commented on May 17, 2024

@shakibonline Of course not, you aren't using the offset properly. Read the bot API documentation or take a look at the examples in the repo.

from madelineproto.

abbas980301 avatar abbas980301 commented on May 17, 2024

what about this one?

        $offset = 0;
        while (true) {
        $updates = $MadelineProto->API->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 1]); // Just like in the bot API, you can specify an offset, a limit and a timeout
        foreach ($updates as $update) {
            $offset = $update['update_id']; // Just like in the bot API, the offset must be set to the last update_id
            // Parse $update['update'], that is an object of type Update
        }
        var_dump($updates);
        }

is it true?

ps : i should store last offset for next run time?

from madelineproto.

abbas980301 avatar abbas980301 commented on May 17, 2024

what is this error on running ( before load env & setting )

    An error getting response of method updates.getChannelDifference: WARNING: Wrong length was read (should've read 4, read 0)! in Connection on line 174. Retrying...

from madelineproto.

danog avatar danog commented on May 17, 2024

is it true?

Nope, please check the official bot API documentation.

ps : i should store last offset for next run time?

Nope, please check the official bot API documentation.

what is this error on running

It sometimes happens, ignore it.

from madelineproto.

abbas980301 avatar abbas980301 commented on May 17, 2024

thanks for answers.

Nope, please check the official bot API documentation.

did you mean this page?
http://daniil.it/MadelineProto/

from madelineproto.

Amirjan avatar Amirjan commented on May 17, 2024

Hi @danog
Is it possible get updates near real time?

from madelineproto.

Amirjan avatar Amirjan commented on May 17, 2024

I implement it:

function onNewChannelMessage($update){
file_put_contents('ChannelMessage.txt',print_r($update,true) , FILE_APPEND);
}

function onNewMessage($update){
file_put_contents('NewMessage.txt',print_r($update,true) , FILE_APPEND);
}

$MadelineProto->eventManager()->bind('NewChannelMessage', 'onNewChannelMessage');
$MadelineProto->eventManager()->bind('NewMessage', 'onNewMessage');

while(true){
$MadelineProto->get_updates_difference();
}

from madelineproto.

vahidvdn avatar vahidvdn commented on May 17, 2024

You must run $MadelineProto->get_updates_difference() in a loop to get updates with the callback

@danog Hi. How did you implement non-blocking in php?

from madelineproto.

nicorac avatar nicorac commented on May 17, 2024

@Amirjan: I'm trying to use your sample code:
#67 (comment)

but the line
$MadelineProto->eventManager()->bind('NewChannelMessage', 'onNewChannelMessage');

throws an exception:
PHP Fatal error: Uncaught danog\MadelineProto\TL\Exception: Could not find method: eventManager in madelineProto/src/danog/MadelineProto/TL/TL.php:357

I've also searched for "eventManager" in the whole source tree unsuccessfully.
Where is it supposed to be defined?

from madelineproto.

danog avatar danog commented on May 17, 2024

@Amirjan is clearly using a custom event manager, a pull request would be nice :3

from madelineproto.

danog avatar danog commented on May 17, 2024

@Amirjan Sure, send a pr!

from madelineproto.

Cojad avatar Cojad commented on May 17, 2024

@Amirjan, your event manager looks so awesome!

from madelineproto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.