9

How can I programmatically check if a contact number is online on WhatsApp or not on ?

I've searched on Google, I just found another application, which gives a notification when the entered contact number comes online, but I want to know that programmatically so that I can implement that in my application.

Note:- If this kind of application exists, then there must be a solution to my problem.

I found another question on SO but the answer was totally unrelated to what was asked in the question and still, that answer has 4 upvotes and is accepted by OP, I don't know how?

So, Is there any available there? Or any Intent action?

  • This is treacherous territory https://github.com/venomous0x/WhatsAPI Also I'd like to have the app, looks super useful if you have to know when s.o. comes online. – leonardkraemer Dec 12 '18 at 16:35
  • @leonardkraemer, but I don't think that app still exists. –  Dec 12 '18 at 16:36
  • And that repo is also wiped away –  Dec 12 '18 at 16:38
  • 1
    Use shadowsheep's answer. However, for future reference, that repo can still be retrieved by looking at the forks: https://github.com/venomous0x/WhatsAPI/network/members – Jake Lee Dec 12 '18 at 16:43
  • @JakeSteam https://stackoverflow.com/questions/53695481/android-how-to-programmatically-check-if-a-number-is-online-on-whatsapp#comment94347788_53747590 –  Dec 12 '18 at 16:51
  • https://checkwa.online/wp/#search – Smart Manoj Jun 12 '19 at 08:36

1 Answers1

8

Knowing an account online status is still a Private API. So you could not do that in a "legal" way.

But of course WhatsApp and the other Apps you are mentioning at do that. So they know how to do it.

You have to reverse engineered them if you want to know how they do what you are asking for.

What you can do is know if a number is a valid WhatsApp user or not.

According to the documentation, you must have your Facebook WhatsApp Buisiness API:

https://developers.facebook.com/docs/whatsapp/api/reference/

WhatsApp is a fast, secure, and reliable way for businesses to reach their customers all over the world. This guide describes how businesses can use the WhatsApp Business API to interact with their customers.

This version of the WhatsApp Business API uses a REST API Architecture with JSON data formats. The API follows the standard HTTP request-response exchange.

Once you have a valid business account you could then query the Contacts (Contacts) node

Use the contacts node for the following purposes:

To verify that a phone number in your database belongs to a valid WhatsApp account. You must ensure that status is valid before you can message a user. To get the WhatsApp ID for a phone number. WhatsApp IDs are needed to send messages, use notifications, and work with groups.

From doc doing a POST request like that:

POST /v1/contacts

{
   "blocking": "wait",
   "contacts": [
      "16315551003",
      "1-631-555-1002",
      "+54 9 11 5612-1008",
      "+1 (516) 283-7151"
   ] 
}

You can obtain such info:

Response After you send the request to check contacts you will receive a response with the current status of the requested numbers. Contacts that are new will typically have a status of processing as the application asynchronously determines if the numbers belong to a valid WhatsApp account.

If you use the "blocking": "wait" option in the request, the response is now synchronous, so the response is generated only once the status of all of the numbers has been determined. This implies that the request will take a longer time to return if there are new contacts, but you will not see the "processing" value returned. The example code below demonstrates this behavior.

{
   "contacts": [
      {
         "input": "1-631-555-1002",
         "status": "invalid"
      },
      {
         "input": "6315551003",
         "status": "valid"
         "wa_id": "16315551003"
      },
      {
         "input": "+54 9 11 5612-1008",
         "status": "invalid"
      },
      {
         "input": "+1 (516) 283-7151",
         "status": "valid"
         "wa_id": "15162837151"
      }
   ]
}
shadowsheep
  • 14,048
  • 3
  • 67
  • 77
  • 2
    But how can I come to know if any number is online or not? –  Dec 12 '18 at 16:46
  • Can we also get information about the online status of a number that whether any number is online or not? – letsintegreat Dec 12 '18 at 16:59
  • 1
    @Zlytherin you are right, sorry, This is still a non public API. So, I will delete my answer if you like. Anyway, I guess that Apps that do that have reverse engineered official App and looked at how it does it. You could also decompile or MITMed Apps you know that do that in order to see how they are doing it. – shadowsheep Dec 12 '18 at 17:04
  • @Zathura https://stackoverflow.com/questions/53695481/android-how-to-programmatically-check-if-a-number-is-online-on-whatsapp/53747590#53747590 – shadowsheep Dec 12 '18 at 17:09
  • @shadowsheep, can we really decompile any app and can get the source code of it? I didn't know that this is possible, kindly share how can we do so. Now, it is totally up to you if you think that this answer is unrelated to this question, then you should delete this, otherwise who cares? – letsintegreat Dec 12 '18 at 17:09
  • @Zlytherin yes you can. More application are obfuscated and/or use encrypted custom comms less they are easy to be reverse engineered. Start looking at that https://www.evilsocket.net/2017/04/27/Android-Applications-Reversing-101/ and look at tools like Brida or Frida. – shadowsheep Dec 12 '18 at 17:18