Skip to content

Instantly share code, notes, and snippets.

@dkdndes
Created September 20, 2013 14:21
Show Gist options
  • Save dkdndes/6638341 to your computer and use it in GitHub Desktop.
Save dkdndes/6638341 to your computer and use it in GitHub Desktop.
whatsapp user presense - Pasindu Perera <notifications@github.com> via mailing list. Note to myself.
How to subscribe to users presence via events. I use the following code
#!/usr/bin/python
from Yowsup.connectionmanager import YowsupConnectionManager
import time, datetime, sys, base64
target = "****"
uid = "%s@s.whatsapp.net" % target
username = "***"
pw = "***"
connectionManager = YowsupConnectionManager()
connectionManager.setAutoPong(True)
methodsInterface = connectionManager.getMethodsInterface()
signalsInterface = connectionManager.getSignalsInterface()
def onPresenceUpdated(jid, lastSeen):
formattedDate = datetime.datetime.fromtimestamp(long(time.time()) - lastSeen).strftime('%d-%m-%Y %H:%M')
print jid, formattedDate
def onPresenceUnavailable(jid):
print "*********************"
print "unavailable ", jid
def onPresenceAvailable(jid):
print "*********************"
print "available ", jid
def onAuthSuccess(username):
print "*********************"
print username
methodsInterface.call("ready")
def onAuthFailed(username, err):
print "*********************"
print("Auth Failed!")
signalsInterface.registerListener("presence_updated", onPresenceUpdated)
signalsInterface.registerListener("presence_unavailable", onPresenceAvailable)
signalsInterface.registerListener("presence_available", onPresenceUnavailable)
signalsInterface.registerListener("auth_success", onAuthSuccess)
signalsInterface.registerListener("auth_fail", onAuthFailed)
methodsInterface.call("auth_login", (username, base64.b64decode(bytes(pw.encode('utf-8')))))
after the above code I use methodsInterface.call("presence_request", (uid,)) to get the user presence. I tried using methodsInterface.call("presence_subscribe", (uid,)) but it doenst seems to work. ( callbacks are never called). Is there any other way to do it? how to get the users presence rather than the lastseen (like typing, online)?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment