mukulhase / WebWhatsapp-Wrapper

An API for sending and receiving messages over web.whatsapp [Working as of 18th May 2018]
https://webwhatsapi.readthedocs.io/en/latest/
MIT License
2.02k stars 795 forks source link

How to check if number has WhatsApp or not #389

Open mehmetcanfarsak opened 5 years ago

mehmetcanfarsak commented 5 years ago

Hi, I tried to send message nonsense number with driver.send_message_to_id function and it was sent :)

When I tried check_number_status the error below occurs.

$driver.check_number_status(number_id="XXXXX")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/app/webwhatsapi/__init__.py", line 705, in check_number_status
    return NumberStatus(number_status, self)
  File "/app/webwhatsapi/objects/number_status.py", line 10, in __init__
    super(NumberStatus, self).__init__(js_obj, driver)
  File "/app/webwhatsapi/objects/whatsapp_object.py", line 77, in __init__
    self.id = js_obj["id"]["_serialized"]

So that preventing this issue how can I check if the number has whatsapp or not? Thanks in advance for such a great repo.

brunosoaresds commented 5 years ago

You’re in the right way. You can check it using the check_number_status function. I don’t understand the error, because you have applied the #380. Here I’m using this function without a problem. Try to update your selenium, geckodriver and Firefox containers.

lfdelphino commented 5 years ago

I guess you are asking fot the status of only the number alone, you should always use the following format: [country code][city code][number]@c.us,

e.g.

$driver.check_number_status("5511912345678@c.us").status
#404
mehmetcanfarsak commented 5 years ago

Hi, Thanks you very much @lfdelphino and @brunosoaresds driver.check_number_status("5511912345678@c.us").status returns 200 if the number is registered and

if the number is not registered

$ driver.check_number_status(number_id="9053723463932@c.us")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/app/webwhatsapi/__init__.py", line 705, in check_number_status
    return NumberStatus(number_status, self)
  File "/app/webwhatsapi/objects/number_status.py", line 10, in __init__
    super(NumberStatus, self).__init__(js_obj, driver)
  File "/app/webwhatsapi/objects/whatsapp_object.py", line 77, in __init__
    self.id = js_obj["id"]["_serialized"]
TypeError: 'NoneType' object is not subscriptable

returns error so with a try except I solved the problem again thanks a lot @lfdelphino and @brunosoaresds