3

I know it's possible to create a button to start a conversation for a number.

But is it possible to check first if this number has whatsapp?

I need a grid with multiple numbers, and show the option to start conversation only for numbers that have whatsapp.

Note: I want to make this process logged in to whatsapp web.

JPSM
  • 41
  • 1
  • 5

3 Answers3

1

It is a bit old question, but i get this question when i search for the same thing. After some reads, this is what i get. Hope it could help someone that search the same thing.

You could use the Client.getNumberId() function to check if the mobile phone number is registered on WhatsApp or not, check out the documentation on https://docs.wwebjs.dev/Client.html.

Note: you might need to sanitized the phone number first to ensure it is in the right format, which is , etc 618123456789. 61 is the country code, and the 08123456789 is the usual mobile number (remove the first zero on it).

var client = whatsAppWebClient.client;
var mobile_no = '+628123456789';
var sanitized_number = mobile_no.replace(/[^\d]/g, ''); // remove except number

// Get the registered WhatsApp ID for a number
var number_details = await client.getNumberId(sanitized_number);

if(number_details) {
  console.log("Sending message to ", number_details);
  /* send message */
} else {
  console.log(sanitized_number, "Mobile no is not registered on Whatsapp")
}
  
David
  • 522
  • 3
  • 7
0
import {Client} from 'whatsapp-web.js';
const client = new Client({
    // client configuration if any
})
// other blocks of code goes here

//function for checking if number is registered on whatsapp
const isNumberOnWhatsapp = async (number) => {
  return await client.isRegisteredUser(number)
}
client.initialize()
R A Omeiza
  • 11
  • 4
0

You can use WhatsAppWeb JS Library or 3rd party. But most times you just quickly need an already stable and setup service you can use that is one time. Try https://watverifyapi.live it works