VISWESWARAN1998 / Simple-Yet-Hackable-WhatsApp-api

There is no official WhatsApp API. Here is a simple python class which satisfies the need.
Apache License 2.0
611 stars 153 forks source link

peculiar case ... sending to wrong recipient when recipeints have similar name #57

Closed aahnik closed 3 years ago

aahnik commented 3 years ago

see this Screenshot from 2020-08-19 09-33-30

when I send to B22 it goes to MCB22, it is because the way the program works

aahnik commented 3 years ago

started thinking

Screenshot from 2020-08-19 10-01-27

aahnik commented 3 years ago

the code structure here is vey diff., so it is very difficult to commit here

I have closed my past PRs in this repo and created my own version

if i am able to solve i will commit in my implementation which is similar to this one , but different in many aspects

my version has diff code structure and arranged in diff way as per my use cases

i have made my own implementation of this api, with features like updating variables (css and xpath selectors) from github raw usercontent, in runtime, without the need to update the entire repo

whatsapp website structure may change , so this is a safe gaurd

in my implementation, xpath and css selectors are not hardcoded, but latest are fetched from cdn (github gist) during first run and saved in system.

the developer can optionally run the fetch_vars() to update the variables every time( takes 2 to 3 seconds if updates availaible other wise less than 1 s)

my implementation doesnt have emojify, or picture or document. ( has very less features)

it has only messaging and trying to make is fast and unbreakable.

my needs are only sending dynamic bulk messaging.

you can try out my implementation by

pip install wappdriver

it is easy to use and setup(u can set chrome driver path and save it by a function call), but has less features

aahnik commented 3 years ago

hurray! i can prevent message being sent to wrong person by adding a SINGLE KEYWORD

if self.load_selected_person(to):

i just added the " if "

( IN MY IMPLEMENTATION)

https://aahnik.github.io/wappdriver/ or pip install wappdriver

FOR NOW: my implementation will not send message to wrong recipient and warn you with Unable message.

i am trying to bypass this problem and send message to correct person.

preventing sending to wrong person and producing an failed log is helpful

this case this very RARE...

so in case it occurs , u can message those persons later manually. (I am trying a workaround

VISWESWARAN1998 commented 3 years ago

@aahnik I am so sorry for not merging your PR this project is used by many including my employers, I have to think of backward compatibility as well in mind. They have used the older API calls and changing the xpath and selectors then and now when the API breaks. I cannot convince everyone to change the API calls immediately. Your contribution towards this repo is much appreciated!

Thanks and Regards, Visweswaran N

aahnik commented 3 years ago

I understand...

Every body has different needs ,

THATS A BEAUTY OF OPEN SOURCE

I learned a lot from your repo and have created my version serving my needs specifically....

Thanks a lot for such an wonderful project and for opensourcing it. 😍❤️❤️

It is extremely valuable.

There are chrome extentions which charge ₹3000 rs per year for the functionalities i require.

But with the help of your repo, i build my automations which makes my life easier for free...

Thanks you so much once again 🥰

bhavya32 commented 3 years ago

@aahnik @VISWESWARAN1998 I think if we make it more like API, like 127.0.0.1/send.py?to=aahnik&text=hello it could be integrated with business oriented software.

aahnik commented 3 years ago

@bhavya32 you are talking about web api It can be made with Django or flask

But to run on server, we have to eliminate the gui and use the skeleton of chrome

In that case, it will be difficult to know whether it is working correctly or not

bhavya32 commented 3 years ago

@aahnik See if you want to do this, I can tell you how. Chrome will not be started by selenium. It will be started by cmd with 2 arguments - headless and remote debugging. By headless, it will not show any UI and by remote debugging, you can see the gui for debugging purposes remotely. I know I couldn't explain remote debugging properly but you can google it out. , Selenium will connect to it, do its job and close without closing chrome.

aahnik commented 3 years ago

@bhavya32 I had seen this thing earlier in a video but i forgot, how to do.

I will try to do it

Without gui it will be faster to run.

And i think in headless mode you can even run it from Pydroid in android and also host it in a server 24 x 7.

bhavya32 commented 3 years ago

@aahnik I am myself owner of such code in c#. I can not provide the source code as it is being used for commercial purposes but I can help you out since the original I made was in python. Now I am working on auto-reply.

aahnik commented 3 years ago

The problem with unofficial api is that they operate on the browser and they do not talk to WhatsApp server directly.

WhatsApp official api requires you to register and they charge money to send messages. And that is for big businesses only.

WhatsApp charges no money for session messages, ie replying to user messages. But requires registration.

These unofficial api, which is very helpful to us, but are harmful to WhatsApp's business.

What will happen if WhatsApp puts a captcha in WhatsApp web?

Is these kind of solutions reliable in long run?

I am using these project to automate sending messages to my father's students.

But next year I am thinking to switch to telegram as its api is free and offers more Features.

70% of my target audience have telegram. And the rest can easily open an account

Telegram also allows hassle free sign in with telegram api, which I am planning to put in my father's website.

aahnik commented 3 years ago

@aahnik I am myself owner of such code in c#. I can not provide the source code as it is being used for commercial purposes but I can help you out since the original I made was in python. Now I am working on auto-reply.

I will be very glad to receive help.

aahnik commented 3 years ago

Finally, this issue #57 solved, solution of issue #48 enhanced

Same solution for both of our repos ( @VISWESWARAN1998 and @aahnik )

We have to replace this

search_box.send_keys(name+Keys.ENTER)

with this

search_box.send_keys(name)
person = WebDriverWait(driver, timeout).until(expCond.presence_of_element_located(
    (By.XPATH, f'//*[@title="{name}"]')))
person.click()

This will solve the old issue #48 as well

aahnik commented 3 years ago

I have thoroughly tested after making the changes. This issue is solved and things are working as expected All changes are made in https://github.com/aahnik/wappdriver