Comments (21)
Yes, use callbacks.
You must run $MadelineProto->get_updates_difference() in a loop to get updates with the callback.
from madelineproto.
Nope, Google "telegram bot API documentation"
from madelineproto.
I use pthreads for multithreading, but to enable it a ZTS version of PHP must be installed, along with the pthreads extension.
from madelineproto.
@nicorac I implement it with my custom event manager
If dear @danog allows it, I will publish it here
from madelineproto.
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.
You must increment the offset like with the bot API.
from madelineproto.
thanks.
after that ( increment the offset ) old updates will remove?
from madelineproto.
@shakibonline Yep, exactly like in the bot API
from madelineproto.
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.
@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.
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.
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.
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.
thanks for answers.
Nope, please check the official bot API documentation.
did you mean this page?
http://daniil.it/MadelineProto/
from madelineproto.
Hi @danog
Is it possible get updates near real time?
from madelineproto.
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.
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.
@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.
@Amirjan is clearly using a custom event manager, a pull request would be nice :3
from madelineproto.
@Amirjan Sure, send a pr!
from madelineproto.
@Amirjan, your event manager looks so awesome!
from madelineproto.
Related Issues (20)
- PHP Version 8.2.0RC7 but still not working HOT 1
- AUTH_KEY_DUPLICATED HOT 1
- inviteToChannel (This peer is not present in the internal peer database) HOT 2
- readStories always return null HOT 2
- How to get the story content? HOT 1
- TypeError: EventHandler\Media\Sticker::__construct(): Argument #4 ($width) must be of type int, null given
- Undefined array key "sizes" in danog\MadelineProto\MTProtoTools\Files.php:838
- Madeline Proto getSelf() HOT 4
- Compatibility Issue with Symfony Components Due to nikic/php-parser Upgrade HOT 1
- Make the session portable and independent of paths, code, classes and php version HOT 3
- Sometimes have auth error HOT 3
- Graceful Shutdown of MadelineProto Event Handler via Symfony Command HOT 1
- Memory leaks in handling updates loop HOT 5
- Sending a message to the chat topic does not work HOT 1
- $message->read() return type issue HOT 1
- missing feature sendMediaGroup itβs very important but not available HOT 1
- Class Naming Mismatch in `danog\MadelineProto\EventHandler\Pinned` HOT 1
- upload mp4 to group, something error HOT 6
- inputMediaUploadedVideo is not available for sendMultiMedia HOT 1
- getHistory generate exception MSG_ID_INVALID HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from madelineproto.