whatsapp-framework
whatsapp-framework copied to clipboard
Human behavior still too robotic
I added a little bit of logic to the project human behavior related.
The thing is to wait time relatively to your message length. Any human can write 200 characters in 0.4 secs. This is a section added in app/mac.py:50
This is the code in master
def prepate_answer(self, conversation, disconnect_after=True):
# Code before remains untouched
# Set is writing
start_typing(self, conversation)
time.sleep(random.uniform(0.5, 1.4))
# Set it not writing
stop_typing(self, conversation)
#time.sleep(random.uniform(0.1, 0.3))
# Code after remains untouched
This is the edited part
def prepate_answer(self, conversation, message_length, disconnect_after=True):
# Code before remains untouched
# Set is writing
start_typing(self, conversation)
def get_delay(msg_len):
# Measured seconds per character
rate = 0.2
# Estimated time per human writing
secs_to_write = rate * msg_len
return secs_to_write + random.uniform(-2,2)
if message_length < 150:
time.sleep(get_delay(message_length))
else:
while message_length > 0:
time.sleep(get_delay(message_length))
message_length -= 150
stop_typing(self, conversation)
time.sleep(random.uniform(2,5))
start_typing(self, conversation)
# Set it not writing
time.sleep(random.uniform(0.1, 0.3))
stop_typing(self, conversation)
# Code after remains untouched
The measured rate of time taken for writing a character is 0.2 seconds. If the message was shorter than 150 characters, it just calculates like 0.2 * 112 = 22.4
. But if the message is longer, maybe a person has to stop to think what to keep writing or rephrasing. So it loops for longer messages waiting 2-5 seconds each stop.
Notice the message length was added as a parameter. Just needing to call the function as len(message).
What do you guys think of a PR?
message_length referenced before assignment
Yes, that was a mockup. Check my edit, where I switched message_length
to be the third parameter because it can't go after an optional parameter.
def prepate_answer(self, conversation, message_length, disconnect_after=True):
...
Also you have to call that function as
# mac.py:149 (approx.)
def send_message(str_message, conversation, disconnect_after=True):
...
prepate_answer(entity, conversation, len(message), disconnect_after)
...
Particularily to your answer, it sounds like you forgot to add message_length
to the signature of the function.
Yep my mistake sorry!
This is great. Good job. Soon I'll be adding more functionality. Feel free to make a PR about this
@danielcardeenas Thank god you're still alive xD please make send_audio
feature dude! And please tell me how to do these things #165 #161
anywone can send me the mac.py modified??