Yowsup: Collection layer.py

Created on 18 Jun 2016  路  18Comments  路  Source: tgalal/yowsup

I invite all users to put in download here their layer.py

It 'very interesting this project and it would be nice to learn new things from all of us

My project is here

Thank you all :+1:

All 18 comments

I think most of your time.sleep() are unnecessary.

No, it emulates the human, no slip not see, online, you are writing etc etc.

Too much haste? :)

Put here your "layer.py" :+1:

Yeah, but it is not needed I think, I don't use them. (Not banned or anything)

self.toLower(messageProtocolEntity.ack())
self.toLower(messageProtocolEntity.ack(True)) 

Uppon receiving a message

messageProtocolEntity.setBody(string)
self.onTextMessage(messageProtocolEntity)
self.toLower(messageProtocolEntity.forward(messageProtocolEntity.getFrom()))

For sending a message.

My layer.py would be a bit large.

        self.toLower(messageProtocolEntity.ack()) #Set received (double v)
        time.sleep(0.5)
        self.toLower(PresenceProtocolEntity(name = name)) #Set name Presence
        time.sleep(0.5)
        self.toLower(AvailablePresenceProtocolEntity()) #Set online
        time.sleep(0.5)
        self.toLower(messageProtocolEntity.ack(True)) #Set read (double v blue)

In this logical order, when accessing whatsapp first is the dual v Gray then double v blue, not together

If you are not online before how can you have read the message?

Put in your project download here.. :+1:

I am online.

After that you're online
self.toLower(messageProtocolEntity.ack(True)) #Set read (double v blue)
Not before

You are always online 24/7 ?

Yes.

I am online before that too, I could not receive messages if I were not.

Not setting presence will show my number as last seen 27/4/2016 although it is online. It might be good however to set presence.

v04
Added log unauthorized phone number
Is logged: Sender, Number sender, Message text received

Put in download here your layer.py

https://gist.github.com/schoerg/330a5d7520034801bd9a93915def78a7

If you are interested. I removed the functions, but you get the idea I guess. Needs some refactoring and cleanup too. Sending the message is handled inside the functions.

you have removed the the most beautiful part.... :)

It was not really beautiful, that's why I removed it. :/

can I ask you a question?

if I put a ping too long, waiting to run a script

        if message.lower() == 'ciao':
            answer = "Ciao "+namemitt+" "
            os.system('Find_SMS_SIM_CARD.sh')
            time.sleep(180)
            answer = "Ciao "+namemitt+" "
            self.toLower(textmsg(answer, to = recipient ))
            print answer

At the end of 180 seconds the answer "Ciao " will not is sent to me

but at the terminal I see the print answer, then the .py is not blocked

Now I send a new whatsapp the number does not respond until I do not kill and restart python

Max time.sleep(120) wotk

how do I fix?

Thanks

time.sleep() will block, and I don't know if yowsup uses threads to do something different in the meantime, so keepalives might not be sent.

I don't know what Find_SMS_SIM_CARD.sh does but you could rearrenge stuff a bit.
Use Popen(), which will not block on waiting for the output and just send the "Ciao" message immediateley. Also you have answer = "Cia..." two times in there.

such high values are not necessary.

I occupy something like this in my script:

       self.toLower(messageProtocolEntity.ack())
        time.sleep(random.randrange(4,13))
        self.toLower(AvailablePresenceProtocolEntity())
        time.sleep(random.randrange(2,3))
        self.toLower(messageProtocolEntity.ack(True))
        time.sleep(random.randrange(3,4))

        self.toLower(OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_TYPING, Jid.normalize(messageProtocolEntity.getFrom(False)) ))
        time.sleep(random.randrange(4,5))
        self.toLower(OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_PAUSED, Jid.normalize(messageProtocolEntity.getFrom(False)) ))
        time.sleep(random.randrange(2,3))
        self.toLower(OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_TYPING, Jid.normalize(messageProtocolEntity.getFrom(False)) ))
        time.sleep(random.randrange(5,6))
        self.toLower(OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_PAUSED, Jid.normalize(messageProtocolEntity.getFrom(False)) ))
        time.sleep(random.randrange(2,3))

        self.toLower(enviar)
        time.sleep(random.randrange(2,3))
        self.toLower(UnavailablePresenceProtocolEntity())

although it is true, it is not necessary to occupy "time.sleep" and "presence states".
But if I want to humanize responses bot, certainly they are.

@langioletto Fork yowsup with your code in order to show here, should be better than using mega.nz :+1:

Better to download the files, they avoid formatting errors

Dear All, Could someone please add function to upload image/video file. eg If I send Photo then it should upload a file on specific path.

We'll see when we have some time here

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cyberp1983 picture cyberp1983  路  3Comments

MauricioAHM picture MauricioAHM  路  5Comments

Realitaetsverlust picture Realitaetsverlust  路  4Comments

abhiroock picture abhiroock  路  5Comments

mathslimin picture mathslimin  路  4Comments