pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.05k stars 3.58k forks source link

getNumberId #2765

Closed EDSL1312 closed 7 months ago

EDSL1312 commented 7 months ago

Is there an existing issue for this?

Describe the bug

getNumberId sometimes work and sometime not working.

getNumberId takes a very long time to finish its execution

I have researched info by this fail and i not found nothing

Expected behavior

I have this error in last version API 1.23.0

Steps to Reproduce the Bug or Issue

console.log("getNumberId"); const number_details = await client.getNumberId(finalNumber);

Relevant Code

export var getNumberId = async (finalNumber: any) => { return await new Promise(async (resolve, reject) => { // Create a stream to which the upload will be written. console.log("getNumberId"); const number_details = await client.getNumberId(finalNumber); console.log("getNumberId==>finalNumber._serialized: ", finalNumber._serialized); resolve(number_details); }); };

Browser Type

Google Chrome

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

Linux and Windows

Additional context

NA

alechkos commented 7 months ago

Client.getNumberId method gets a string in a format: XXXXXXXXX or XXXXXXXXX@c.us, where the XXXXXXXXX part is a user's phone number without + at the beginning. If the user with a provided phone number is registered on WhatsApp, the method returns an object:

{
  server: 'c.us',
  user: 'XXXXXXXXX',
  _serialized: 'XXXXXXXXX@c.us'
}

Otherwise you will get null.

I just checked the method on the latest WWeb v2.2405.52 and it works like a charm. The bug is in your code, check it.