Open alesantosp opened 10 years ago
Sendpong is a deprecated function, wa servers no longer use that. There is a issue in WhatsApiNet where @shirioko explained a way to keep online, and then use while(true) (for example) to pollMessages. As you are in php repo remember that pho doesnt support multi threading. But there are other ways to do it.
Thanks @mgp25 , i'll find this issui in WhatsApiNet, but do you have any suggestion to do that in PHP?
while(1) { $w->sendActiveStatus(); $w->pollMessage(); sleep(1); }
@Amirjan i'm already did that, but after some time (1 hour, 2 hour... it's variable) i received rx < stream:error > rx < >< / > rx < /stream:error > With this return were not generated any exceptions on whatsprot.class.php or fired any event...
Basically i have:
while ( 1 ) { list ( $usec, $sec ) = explode ( ' ', microtime () ); $script_start = ( float ) $sec + ( float ) $usec;
$this->processaComandos(); //get image profile if i have one to do this $this->processaMsgsSaida(); //send msg the operator typed $this->processaMsgsEntrada(); //receive new msgs $script_end = ( float ) $sec + ( float ) $usec; $this->tempoTotal += ($script_end - $script_start); if ($this->tempoTotal > rand( 47,56 ) ) { $this->tempoTotal = 0; $this->sendGetGroups(); // @mgp25 told about 'There is a issue in WhatsApiNet where @shirioko explained a way to keep online' and i'm trying do this every 60 seconds //$this->sendPong(); //my old code if ( $this->online ){ $this->sendOfflineStatus(); } }
processaMsgsSaida basically has $this->sendActiveStatus(); $this->online = true; $this->sendPresenceSubscription ( $destino ); $this->sendMessageComposing( $destino ); $this->poolMessage(); sleep( 1 ); $this->sendMessagePaused( $destino ); $ret = $this->sendMessage ( $destino, utf8_encode ( $val ['dsc_msg'] ) );
@alesantosp If you get my email, i can send you useful code, but i think that has already been answered in other issue (you can send it in spanish if you want)
@mgp25 thanks, i sent you an e-mail
For example this:
$t=0;
while (1) {
$msgs = $w->getMessages();
foreach ($msgs as $m) {
# process inbound messages
//print($m->NodeString("") . "\n");
}
if( ($t == 15)){
$w->sendPresence();
$t=0;
}
$t++;
}
This worked for me to keep bot online 24 hours 2 months ago, i dont know if still working. There are better ways. You also can have a look to ajaxDemo.
@mgp25 thanks, i'll try this again (had trying something like that) and i'll be check ajaxDemo again. But my problemn isn't to stay online, it's receive msgs all the time. I don't know why sometimes i still connected, i can send messages but i can't get the answers. On mobile phone they stay with 1 ticket (they were not delivered to the whats number). When this happens if i kill my php script and execute it again all of messages will delivered to my script.
Use a loop polling messages, if you have latest whatsprot.class just do pollMessage instead of pollMessages. It will work ;) Check whatsapp.php file from /tests folder
@mgp25 thanks again, i'll be check. But today i use a loop pooling messages and sometimes the pooling doesn't get messages... the most stranger is when this occurs all of commands/messages i sent still working.because of this I have to disconnect at times and connect again, but i think this is not the correct way and i need to find a way to avoid this.
@mgp25 i will, thanks.
@mgp25 I had the same problem using whatsapp.php. I downloaded the latest version and put my data and started the script. Sometimes it worked normally, other times I sent the message the phone and it did not come. To try to understand where the problem occurred, measure the time the method pollMessage and saw that it usually takes 2 seconds, but when I can not download the messages it does not take even a second to process. When this occurs, I need to disconnect and connect again for messages to be downloaded.
In ajaxDemo.php there is a method w- $> pollMessages (); at line 113, when possible please update the code.
Its because of sometimes the messages are stuck in the queue thats why you need to see how to implement it right way
@mgp25 sorry but I understood what you meant. If I start the script in listener mode and it can not fetch messages, how can we have a correct mode if the only thing that was done was call the poolMessage? If I monitor with debug, I see only composing, chatpause coming from the phone, but the message does not arrive.
tempo: 2.02512 - 15.894909381866 -- 15.894909381866
readStanza: 01/09/2014 16:26:30
string(3) "Ç\000↑"
rx <presence from="5534XXXXXXXX@s.whatsapp.net"></presence>
tempo: 1.25507 - 17.149981498718 -- 17.149981498718
readStanza: 01/09/2014 16:26:31
string(3) "Ç\000↔"
rx <chatstate from="5534XXXXXXXX@s.whatsapp.net">
rx <composing></composing>
rx </chatstate>
tempo: 0.53103 - 17.68101143837 -- 17.68101143837
readStanza: 01/09/2014 16:26:32
string(0) ""
tempo: 2.02612 - 19.707127332687 -- 19.707127332687
readStanza: 01/09/2014 16:26:34
string(3) "Ç\000↔"
rx <chatstate from="5534XXXXXXXX@s.whatsapp.net">
rx <paused></paused>
rx </chatstate>
tempo: 0.77904 - 20.486172199249 -- 20.486172199249
readStanza: 01/09/2014 16:26:35
string(0) ""
tempo: 2.02412 - 22.510288238525 -- 22.510288238525
readStanza: 01/09/2014 16:26:37
string(3) "Ç\000↔"
rx <chatstate from="5534XXXXXXXX@s.whatsapp.net">
rx <paused></paused>
rx </chatstate>
tempo: 0.74804 - 23.258330345154 -- 23.258330345154
readStanza: 01/09/2014 16:26:37
string(0) ""
tempo: 2.02612 - 25.28444647789 -- 25.28444647789
readStanza: 01/09/2014 16:26:39
string(0) "
I do have the same problem. No idea how to avoid it. Some login sessions are ok - mesages arrives. Some broken - messages will not arrive all the session (need reconnect). I still see composing and pause statuses from users, but only them.
I have no idea how to check this out with script itself, to decide when i do need reconnect.
Any suggestions?
I'm developing a tool for a contact center (customers needs to contact company to resolve their issues). I'm connecting to WA server and sometimes the system (still connected, i sending pongs to keep connection alive) stops to receive messages. I see customer's typing message, paused, but message doesn't arrive to system. If i kill my script and connect again, sometimes works, sometimes i need stay disconnected for more than 1 minute to receive messages again. Do you know what i'm doing wrong?
rx chatstate from="5534XXXXXXX@s.whatsapp.net" rx paused /paused rx /chatstate
rx chatstate from="5534XXXXXXX@s.whatsapp.net" rx composing /composing rx /chatstate
rx chatstate from="5534XXXXXXX@s.whatsapp.net" rx paused /paused rx /chatstate>