Receive 2 to 4 equal updates from bots
When any bot in private messaging with me send a message - there are 2 to 4 updates with UpdateNewMessage that are absolutly the same. (Only update_id is encrimenting). Why is it happening and how to handle it? With users, channels, groups, supergroups there's no such problem. Only messages that bots send appears to be duplicated.
How are you getting updates? Are you using the latest version? Is the pts of the messages different?
How are you getting updates?
$offset = 0;
while(1){
$updates = $MadelineProto->API->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0.5]);
foreach ($updates as $update) {
$offset = $update['update_id'] + 1;
switch ($update['update']['_']) {
case 'updateNewMessage':
//do stuff
case 'updateNewChannelMessage':
//do stuff
...
}
}
echo 'Wrote '.\danog\MadelineProto\Serialization::serialize('session.madeline', $MadelineProto).' bytes'.PHP_EOL;
}
Are you using the latest version?
Yes
Is the pts of the messages different?
pts is the same. Only update_id differes
P.S. And all this works perfectly for all messages in chats, supergroups, pm. Duplicate pts is just received from bots, when writing them directly. P.P.S. Today received duplicate updates for even privite message from user(updateNewMessage). It also had only different update_ids.
I've seen the same strange behavior. As a temporary workaround I'm filtering out duplicates (by message ID) with something like this:
while(1) {
$seen_ids = []; // array containing seen message IDs
$updates = $MadelineProto->API->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0.5]);
foreach ($updates as $update) {
$offset = $update['update_id'] + 1;
// -----------------------------------------
// skip already seen message IDs
if (!empty($update['update']['message']['id']) {
if (in_array($update['update']['message']['id'], $seen_ids)) {
continue;
}
// mark this message ID as seen
$seen_ids[] = $update['update']['message']['id'];
}
// -----------------------------------------
switch ($update['update']['_']) {
case 'updateNewMessage':
//do stuff
case 'updateNewChannelMessage':
//do stuff
...
}
}
}
Same problem for me. For now I use workaround proposed above. Actually not only messages from bots are duplicated, but sometimes messages in private chats are too.
Fixed