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)
- Return Type In Read Method From Mesage Object HOT 1
- I've this error when i try to use InviteToChannel function HOT 2
- Not working with stable amphp v2 version HOT 2
- getFullInfo() error HOT 2
- How to avoid "This peer is not present in the internal peer database" HOT 1
- This block breaks integration with Symfony HOT 2
- How filter incoming messages: all messages without Scheduled HOT 2
- RPC error with getFullInfo() HOT 2
- getPropicInfo() returns NULL HOT 4
- > pray for daniil 🙏🙏🙏
- > pray for daniil 🙏🙏🙏
- Telegram+
- Redis Settings overrides database number and password when URI contains these values HOT 3
- בוט בדיקה HOT 1
- How to send messages to the robot through MadelineProto, please give a successful example HOT 1
- Install error / difficulties HOT 1
- messages.sendMessage needs random_id parametr HOT 1
- How to read messages from public channel HOT 1
- Update of channel message send twice when we dont use IsNotEdited Filter
- PHP - fpm fall down in infinitive loop 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.