Whatsapp tailored notifications

I always mute WhatsApp group chat notifications (don’t we all?). But
I still wanted to get a notification when someone mentions my name.

Did a little bit of googling and found out Yowsup, a Python API for WhatsApp.
You can install it with
pip install yowsup2

Then register it with a new number. Keep in mind that you can’t use your existing WhatsApp number. I used Ammamma’s (aka grandma)number (pretty sure she won’t come to WhatsApp)

Once it’s done I modified the sample app given in Yowsup’s github to track some keywords.

I also used pushbullet as mentioned in one of my previous posts to issue push notifications.

from yowsup.layers.interface                           import YowInterfaceLayer, ProtocolEntityCallback
from yowsup.layers.protocol_messages.protocolentities  import TextMessageProtocolEntity
from yowsup.layers.protocol_receipts.protocolentities  import OutgoingReceiptProtocolEntity
from yowsup.layers.protocol_acks.protocolentities      import OutgoingAckProtocolEntity
from Push import Push

pb = Push('KEY')

KEYWORDS = ['list', 'of', 'keywords']

class EchoLayer(YowInterfaceLayer):

    @ProtocolEntityCallback("message")
    def onMessage(self, messageProtocolEntity):
        #send receipt otherwise we keep receiving the same message over and over

        if True:
            receipt = OutgoingReceiptProtocolEntity(messageProtocolEntity.getId(), messageProtocolEntity.getFrom(), 'read', messageProtocolEntity.getParticipant())

            body, frm = messageProtocolEntity.getBody(), messageProtocolEntity.getFrom()
            if any(kw in body.lower() for kw in KEYWORDS):
                pb.notify(body, 'WhatsApp')

    @ProtocolEntityCallback("receipt")
    def onReceipt(self, entity):
        ack = OutgoingAckProtocolEntity(entity.getId(), "receipt", "delivery", entity.getFrom())
        self.toLower(ack)

Hosted the scripts on the Raspberry pi and now it sends me notifications whenever someone mentions my name :)

whatsappbot2.png

p.s. Okay that’s a bad example and it’s not what it means.

 
0
Kudos
 
0
Kudos

Now read this

Harry Potter, P versus NP and time travel

Sorry for the clickbait of a title. Disclaimer: Might contain HPMOR spoilers. In the last KopiJS session, I came to know about Harry Potter and the Methods of Rationality. It’s a fanfic based on HP universe. I’m not a fanfic kind of guy... Continue →