Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change sleep times to follow core functions (for sendwhatmsg_instantly function) #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dzonimn
Copy link

@dzonimn dzonimn commented Nov 15, 2021

Hi, I was recently trying to use this library but found that the instant version of the sendwhatmsg function didn't seem to work.

It would type in the message in the text box, but it didn't seem to click into the text box before pressing enter. The original functions worked, so after some digging into how the original functions did it, I noticed that there were a difference in sleep times. Adjusting the instant function with the non-instant function led to the instant function working as expected.

On a different note, in my gut feeling, I feel like this part of the code seems like code that should exist in the core file, but I can't say I'm too familiar with the codebase to go refactoring things in a big way right now.

Do let me know if I should provide more information. Keep up the good work! :)

@codewithpom
Copy link
Contributor

@dzonimn Thanks for pointing it out but can you explain how it does not work as you said it does not click on the box but it should not even click.

With Regards and Thanks
Padmashree Jha

@dzonimn
Copy link
Author

dzonimn commented Nov 16, 2021

If I understood the code correctly, the following code opens a web browser with the intended
recipient and message in the text box, then calls a click function and presses Enter to send.

web.open(f"https://web.whatsapp.com/send?phone={phone_no}&text={quote(message)}")
time.sleep(7)
pg.click(core.WIDTH / 2, core.HEIGHT / 2)
time.sleep(wait_time - 7)
pg.press("enter")

With time.sleep(4), it turned out to be too short of a time for WhatsApp web to load before the click function is called. My guess is that setting it to a longer 7 resolved the issue.

The L31 change was mostly just following how the normal sendwhatmsg function does: https://github.com/Ankit404butfound/PyWhatKit/blob/master/pywhatkit/core/core.py#L62-L72

@codewithpom
Copy link
Contributor

codewithpom commented Nov 16, 2021

@dzonimn You are awesome it was a bug that we shipped early but we did not notice in that function you need to comment that line out to make it work.So please remove it to make it work and then commit it.

@dzonimn
Copy link
Author

dzonimn commented Nov 16, 2021

@codewithpom I removed the lines involving sleep and click. By doing that, it works fine now! Thanks!

(I'm guessing that the click removed the focus from the message box and so the enter command wouldn't do anything. However, I'm still not sure how the non-instant functions worked at here)

_web(receiver=receiver, message=message)
time.sleep(7)
click(WIDTH / 2, HEIGHT / 2)
time.sleep(wait_time - 7)
if not check_number(number=receiver):
for char in message:
if char == "\n":
hotkey("shift", "enter")
else:
typewrite(char)
press("enter")

@aaryanrr aaryanrr added the bug Something isn't working label Nov 16, 2021
@aaryanrr
Copy link
Collaborator

Hey @dzonimn, thanks for submitting the fix. Can you confirm that is the function working for you after removing those lines. Make sure you don't use your mouse or keyboard while the function is running.

@dzonimn
Copy link
Author

dzonimn commented Nov 17, 2021

Hey @aaryanrr I can confirm that it works on my side after I removed those lines.

@aaryanrr
Copy link
Collaborator

Thanks for the response. I have tried doing it on Ubuntu LTS but it isn't working there and we need to ensure cross platform support. I'll ask other maintainers to test this.

@dzonimn
Copy link
Author

dzonimn commented Nov 18, 2021

@aaryanrr I could also try to test out on my Linux machine. I don't really have any idea why it wouldn't work as the methods seem to implement the same logic, with the instant version not including any clicks

@aaryanrr
Copy link
Collaborator

It would be great if you can try it out on your system.

@aaryanrr
Copy link
Collaborator

@dzonimn Is there any update on this PR?

@dzonimn
Copy link
Author

dzonimn commented Dec 29, 2021

Hi, I haven't been very free unfortunately but the last discovery I think I stumbled across was that it was fine on Linux, and back on Windows, there was at least one other function that had a similar problem sending (it might have been screenshot sending). It would be helpful if someone could also check.

@aaryanrr
Copy link
Collaborator

No problem, take your time. I'll check it on windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants