venomous0x / WhatsAPI

Interface to WhatsApp Messenger
2.59k stars 2.13k forks source link

Check online status #747

Closed mgp25 closed 10 years ago

mgp25 commented 10 years ago

Hello, im trying to check the user online/offline status every minute. I have this code:

Note: I tried both onGetPresence and onPresence

function onPresenceReceived($username, $from, $type)
{
    echo "The user is now" . $type;
}

...

$wa->eventManager()->bind("onGetPresence", "onPresenceReceived");
while(true){
    $wa->SendPresenceSubscription($dst);
    sleep(60);
    }

I was testing with an active number, going online and offline, and nothing happened, this is the output, every 60 seconds:

It does not noticed me when the user went online or offline.

tx  <presence type="subscribe" to="34*********@s.whatsapp.net"></presence>
tx  <presence type="subscribe" to="34*********@s.whatsapp.net"></presence>
tx  <presence type="subscribe" to="34*********@s.whatsapp.net"></presence>
....

Any ideas?

Thanks :)

shirioko commented 10 years ago

You only need to call SendPresenceSubscription once. Presence subscription is an async function which automatically notifies you when a user's presence changes:

$wa->SendPresenceSubscription($dst);
while(true){
    $wa->PollMessages();
    sleep(60);
}
mgp25 commented 10 years ago

@shirioko Yeah, i know, but it doesnt do anything, I tried that already :/ But it never notice me when the user goes online and that...

function onPresenceReceived($username, $from, $type)
{
    echo "The user is now" . $type;
}

...

$wa->eventManager()->bind("onGetPresence", "onPresenceReceived");
    $wa->SendPresenceSubscription($dst);
while(true){
    sleep(60);
    }
shirioko commented 10 years ago

You're missing a space in

echo "The user is now" . $type;
mgp25 commented 10 years ago

@shirioko Right, but if i use:

echo "Test";

instead, still not work. Maybe the while interfere to display the text?

jesussales commented 10 years ago

I think that the problem is inside into a while, because you make a sleep, the problem is in there...

I think is better try while (true){ limit(60); }

This method no make a pause in script... Or you can make a Ajax call from other page with interval that you want...

Saludos Jesús Sales

El 27/05/2014, a las 14:24, mgp25 notifications@github.com escribió:

@shirioko Right, but if i use:

echo "Test"; instead, still not work. Maybe the while interfere to display the text?

— Reply to this email directly or view it on GitHub.

mgp25 commented 10 years ago

@shirioko :+1: You are right :)