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.53k stars 3.7k forks source link

`getInviteCode` method is not working on 2.3000.xx #3007

Closed khsoh closed 6 months ago

khsoh commented 6 months ago

Is there an existing issue for this?

Describe the bug

My code has been working for a long time and then stopped working about 1 day ago. I found that the getInviteCode() method for GroupChat is not working - even though the bot is an admin of the chat group (I know that this method should only be called if the bot is part of the chat group)``

Expected behavior

I expected the invite code to be returned when this method is called.

Steps to Reproduce the Bug or Issue

  1. Get group chats that this bot belongs to
  2. call getInviteCode of chats where bot is admin of group

Relevant Code

let chats = await client.getChats();
chats = chats.filter(c => c.isGroup && !c.groupMetadata.isParentGroup && !c.groupMetadata.announce);
for (const chat of chats) {
  // get participant info of this bot for this chat
  let pid = chat.participants.find(p => p.id._serialized == client.info.wid._serialized);
  if (pid.isAdmin) {
    // Only print invite code if bot is admin of this group
    let inviteCode = await chat.getInviteCode();
    console.log(`Invite code: ${inviteCode}`);
  }
}

Browser Type

Chromium

WhatsApp Account Type

Standard

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

Linux, Ubuntu 22.04.4 LTS Node 20.11.1 WhatsApp Web version 2.3000.1013269842

Additional context

No response

MaitoV commented 6 months ago

I'm experiencing the same issue with version 2.3000.xx and webpack-exodus.

smsoousa commented 6 months ago

Was the WWJ project abandoned? In the last update last year, we have many instance disconnection errors, even with the corrections proposed by the collaborators.

5|1006-104 | at emitErrorNT (node:internal/streams/destroy:151:8) 5|1006-104 | at emitErrorCloseNT (node:internal/streams/destroy:116:3) 5|1006-104 | at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { 5|1006-104 | type: 'system', 5|1006-104 | errno: 'ENOTFOUND', 5|1006-104 | code: 'ENOTFOUND' 5|1006-104 | } 5|1006-104 | Error: Evaluation failed: TypeError: Cannot read properties of undefined (reading 'push') 5|1006-104 | at fillModuleArray (eval at <anonymous> (:2:5), <anonymous>:6:74) 5|1006-104 | at moduleRaid (eval at <anonymous> (:2:5), <anonymous>:15:3) 5|1006-104 | at __puppeteer_evaluation_script__:4:17 5|1006-104 | at ExecutionContext._evaluateInternal (/opt/1006-104.237.2.168-Bravos/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221:19) 5|1006-104 | at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 5|1006-104 | at async ExecutionContext.evaluate (/opt/1006-104.237.2.168-Bravos/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:110:16) 5|1006-104 | at async Client.initialize (/opt/1006-104.237.2.168-Bravos/node_modules/whatsapp-web.js/src/Client.js:323:9)

6|1007-104 | at __puppeteer_evaluation_script__:5:95 6|1007-104 | at ExecutionContext._evaluateInternal (/opt/1007-104.237.9.136-Today/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221:19) 6|1007-104 | at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 6|1007-104 | at async ExecutionContext.evaluate (/opt/1007-104.237.9.136-Today/node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:110:16) 6|1007-104 | at async Client.initialize (/opt/1007-104.237.9.136-Today/node_modules/whatsapp-web.js/src/Client.js:323:9) 6|1007-104 | ProtocolError: Protocol error (Network.getResponseBody): Target closed. 6|1007-104 | at /opt/1007-104.237.9.136-Today/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:329:24 6|1007-104 | at new Promise (<anonymous>) 6|1007-104 | at CDPSessionImpl.send (/opt/1007-104.237.9.136-Today/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:325:16) 6|1007-104 | at /opt/1007-104.237.9.136-Today/node_modules/puppeteer-core/lib/cjs/puppeteer/common/HTTPResponse.js:140:100 6|1007-104 | at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 6|1007-104 | at async HTTPResponse.text (/opt/1007-104.237.9.136-Today/node_modules/puppeteer-core/lib/cjs/puppeteer/common/HTTPResponse.js:160:25) 6|1007-104 | at async /opt/1007-104.237.9.136-Today/node_modules/whatsapp-web.js/src/Client.js:778:39 { 6|1007-104 | originalMessage: '' 6|1007-104 | }

I've already used npm install github:

pedroslopez/whatsapp-web.js#webpack-exodus

but it didn't work for me, the client connects to the instance and is then disconnected! What worked at first was:

webVersionCache: { type: 'remote', remotePath: 'https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2409.0.html', }

but it works for a few days and then I get the error stated above, so I need to clear wwebjs_auth and read the qrcode again. Can anyone help me with a way to fix this? May it be an efficient solution if possible? Thanks

"whatsapp-web.js": "^1.23.0"

themazim commented 6 months ago

Feel free to test and review this fix: https://github.com/themazim/whatsapp-web.js/commit/5e94f2993e2dd081a94d204c1937347b76c96151

PR: https://github.com/pedroslopez/whatsapp-web.js/pull/3029

smsoousa commented 6 months ago

I'm sorry, I think I posted my error in the wrong place, could you redirect me?