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
14.62k stars 3.48k forks source link

I get "Evaluation failed: Error: wid error: invalid wid" even if wid is valid. #2790

Closed OpperDev closed 4 months ago

OpperDev commented 4 months ago

Is there an existing issue for this?

Describe the bug

Im using whatsapp-web.js to make a bot who create groups automatically. before creating the group, I use isRegisteredUser and then createGroup

The problem is : each time I use a theeses both functions, even if the wid is correct (cause the group is created, and the invitation is sent, means that isRegisteredUser function return true) I get this error : Error: Evaluation failed: Error: wid error: invalid wid And I dont understand why it send me this error cause the wid is valid, the group is successfully created and isRegisteredUser function return true, its very annoying cause it crash my code each time I call one of theeses 2 function.

Expected behavior

I wanted to create an URL who create a whatsapp group automatically with the number sent in the parameters of the URL

Steps to Reproduce the Bug or Issue

  1. Use isRegisteredUser function (with or without "@c.us" added to the number)
  2. Use createGroup function (with valid contacts)

Relevant Code

Here is my function to create groups

const createWhatsappGroup = async function(groupName, contacts) {
        contacts = contacts.map(contact => `${contact}@c.us`);
        return await client.createGroup(groupName, contacts, {
            comment: 'TEST COMMENT',
            autoSendInviteV4: true
        });
    }

Here is where I use it and where I call isRegisteredUser (I dont add "@c.us" when I call isRegisteredUser cause I've seen that in the code its automatically added)

app.get('/:phone', async (req, res) => {
        const phone = req.params.phone;
        if (!phone) return res.end('invalid phone number');
        if (!authenticated) return res.end('internal error\nplease contact website\'s administrator');
        if (!await client.isRegisteredUser(phone)) return res.end('user is not whatsapp user');
        const result = await createWhatsappGroup(
            "GROUP NAME",
            [...JSON.parse(process.env.ADMINS), phone]
        );
        console.log(result);
        return res.send('ok group created');
    });

Browser Type

Chromium

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

OS : Windows 11 Phone OS : Iphone 11 IOS 16.6.1 Whatsapp-Web version : 1.23.0 NodeJS version : 20.10.0

Additional context

(Sorry for my bad english)

alechkos commented 4 months ago

https://github.com/pedroslopez/whatsapp-web.js/issues/1441#issuecomment-1178965390

https://github.com/pedroslopez/whatsapp-web.js/issues/2765#issuecomment-1932729073