How to properly check for WhatsApp on a number#
November 12, 2024
When working with WhatsApp API, it is sometimes necessary to check whether the user has an active WhatsApp account on the number. This can be useful to prevent messages from being sent to inactive numbers, when updating the database, etc.
How can you correctly check for WhatsApp on a number? There are two methods to do this.
Method 1: CheckWhatsapp Method#
The easiest and fastest way is to use the checkWhatsApp method. The method checks for a WhatsApp account on a phone number.
This is an easy-to-use and fast method, but it does not always work correctly and returns incorrect values. There is also a risk of blocking the account if you use the method too often and do not write to the number.
Method 2: Sending a message and getting the status#
This method is more reliable, as it allows you to get the exact status of sending a message, and therefore - confirmation of the existence of a WhatsApp account. In addition, there is no risk of blocking the account.
The verification process looks like this:
- Send a test message to the number of interest.
- Get the status of sending a message.
- Find out the status - if sending is successful, then the WhatsApp account exists.
Options for getting the status of a sent message:
- Use the GetMessage method, which returns a chat message. The response contains the
statusMessage
field. - Use the lastIncomingMessages method, which returns the last incoming messages of the instance. By default, the last messages for 24 hours are returned.
- Receiving notifications via HTTP API using Receive / Delete.
- Receiving notifications via Webhook Endpoint.
We recommend the option with Webhook setup to receive notifications about the message sending status. This option is more difficult to implement, but has a number of advantages. For example, Webhook technology allows you to receive a real-time notification about the message sending status. This is the most effective way to monitor the sending status and get accurate information about the presence of a WhatsApp account.
To receive incoming notifications using Webhook Endpoint technology, you will need to:
- Publish the IP address on the Internet.
- Implement the logic for processing incoming notifications to the specified IP address.
- If required for the server, install the Webhook URL Token.
You can read more about setting up webhooks in our documentation.
Conclusion#
In this article, we looked at ways to check if a number has WhatsApp. We recommend the method of sending a message and receiving the status, as it will not block the account. Do not forget about the rules for reducing the risk of blocking and use webhooks to get up-to-date data.