Yowsup: Detect Online Presence with yowsup-cli

Created on 28 Sep 2016  路  15Comments  路  Source: tgalal/yowsup

I have some serious problem working with the yowsup-cli:

I'm in the interactive mode and did this:

1) Login
/L
2)
/contacts sync 49174xxxxxxxxx (this is the phone number of my real phone)
3)
/presence subscribe 49174xxxxxxxxx

Then I was going online on my real phone and I thought I get something in the client but it does not show a thing. What did I do wrong? Anything missing? Do I have to do "/presence available" (can't test it right now)?

What I really want is to exec some command on my machine once I go online on Whatsapp on my real phone. Anyone willing to help to create a python script for that? Maybe something similar already exists?

Most helpful comment

Hi! Could you provide full example with code that can subscribe to someone presence status (online/offline) &

All 15 comments

Hi ! Yes , actually you need to be available in order to get @ProtocolEntityCallback("presence")

@SorenJon have you found a solution?

@randomite already answered.
1) Login
/L
2)
/contacts sync 49174xxxxxxxxx (this is the phone number of my real phone)
3)
/presence subscribe 49174xxxxxxxxx

needs to be available in order to work.

@rodrigolopezguerra I am following that flow, as well as making myself available. But the only states I get back are "composing" and "paused" which refers to typing or not typing.

I want to know whether the contact is online or not.

Hi @randomite ,

it's been a while since i used yowsup, but i think you are confusing states and presence. In one hand you have the states :

Typing ...

if self.assertConnected():
            entity = OutgoingChatstateProtocolEntity(ChatstateProtocolEntity.**STATE_TYPING**, self.aliasToJid(jid))
            self.toLower(entity)

or

Paused

if self.assertConnected():
            entity = OutgoingChatstateProtocolEntity(ChatstateProtocolEntity.STATE_PAUSED, self.aliasToJid(jid))
            self.toLower(entity)

in the other hand , since by desing whatsapp is ALWAYS ONLINE , you can set your presence to AVAILABLE or UNAVAILABLE :

Available

if self.assertConnected():
            entity = AvailablePresenceProtocolEntity()
            self.toLower(entity)
            return True

Unavailable

if self.assertConnected():
            entity = UnavailablePresenceProtocolEntity()
            self.toLower(entity)
            return True

So in order to check if someone is online , you need to 1)Login 2)Become AVAILABLE (makes all the sense in the world . If you think about it , a user that wants to check if someone is online , its going to open the app , and become available) 3)Suscribe to the number

Hope it helps !

@rodrigolopezguerra Thank you this makes a lot of sense, I understand that I am able to set my own presence.

Is there any way that I can check if a contact is online using the CLI? Similar to what the official app shows underneath the contact name.

Ideally I can just figure it out using last seen time, but it seems to return a random number as pointed out in issue #2048 .

@randomite if you ask for the last seen time , with or without a bug you will get a timestamp. When you see a contact in whatsapp and is online , just says ONLINE or last seen time. So you are looking to get "online" if i didnt get it wrong. Just :

/presence available
/contacts sync <some_phone_number>
/presence subscribe <some_phone_number>

it enough , and will inform you each time user change from available to unavailable. If you want to capture this you can @ProtocolEntityCallback("presence") and def onPresenceChange. The entity type will tell you what time of change is informing you.

If you you need more pointers or help on your project give me a contact method , and we can discuss it.

Regards ,

@rodrigolopezguerra I tried your

/presence available
/contacts sync <some_phone_number>
/presence subscribe <some_phone_number>

sequence, but I am getting the same results as @SorenJon : only "composing" (typing) and "paused" (stopped typing) status updates.

Hello @rodrigolopezguerra

Please can tell me where should I put @protocolentitycallback("presence") and def onPresenceChange?

Thanks

Hi! Could you provide full example with code that can subscribe to someone presence status (online/offline) &

anyone can guide us where onPresenceChange is declared?

Hi , you should it in the layer.

@ProtocolEntityCallback("presence") def onPresenceChange(self, entity): now = datetime.datetime.now() if 'unavailable' in str(entity.getType()): print 'number'+str(entity.getFrom(False))+' not available at '+str(now) else: print 'number '+str(entity.getFrom(False))+' available at '+str(now)

try modifying /demos/cli/layer.py maybe to test. Remember that there're no ONLINE/OFFLINE schema in whatsapp. You're ALWAYS ONLINE as far i understand. You just come available or unavailable.

My pull request to fix that problem:
https://github.com/tgalal/yowsup/pull/2280

@karopass sure, my nickname at Gmail for mail or Hangouts. BR

b957249

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EliasinnKamachoo picture EliasinnKamachoo  路  3Comments

ikuraj picture ikuraj  路  5Comments

holgerschochwitz picture holgerschochwitz  路  3Comments

MauricioAHM picture MauricioAHM  路  5Comments

cyberp1983 picture cyberp1983  路  3Comments