orkestral / venom

Venom is a high-performance system developed with JavaScript to create a bot for WhatsApp, support for creating any interaction, such as customer service, media sending, sentence recognition based on artificial intelligence and all types of design architecture for WhatsApp.
https://orkestral.io
Apache License 2.0
5.9k stars 1.11k forks source link

getGroupMembers is not working #2354

Closed sudeepaviraj closed 1 year ago

sudeepaviraj commented 1 year ago

getGroupMembers is not working

getGroupMembers function is not working when I tried to get group members

Environment

Log Output

node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

Error [TypeError]: window.Store.Cmd.openChatBottom is not a function
    at ExecutionContext._ExecutionContext_evaluate (D:\Programming-Projects\whatsapp-grabber\node_modules\puppeteer-core\lib\cjs\puppeteer\common\ExecutionContext.js:262:51)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ExecutionContext.evaluate (D:\Programming-Projects\whatsapp-grabber\node_modules\puppeteer-core\lib\cjs\puppeteer\common\ExecutionContext.js:145:16)
    at window.WAPI.window.WAPI.getGroupParticipant (D:\Programming-Projects\whatsapp-grabber\node_modules\venom-bot\dist\lib\wapi\wapi.js:0:86341)

Node.js v20.2.0

My Code

client.getGroupMembers(group.id).then(async (number) => {
                        fs.appendFileSync(`output.txt`, `${group.name}\n`)
                        console.log(`\n${number.length - 1} Numbers Found In ${group.name}\n`);
                        let bar1 = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
                        bar1.start(number.length - 1, 0)
                        let numberlist = []
                        number.forEach(async (user, index) => {
                            if (!user.isMe) {
                                fs.appendFileSync(`output.txt`, `${user.id.user}\n`)
                                numberlist = [...numberlist,{id:index,number:user.id.user,user_id:user.id._serialized,group:group.name}]
                                bar1.increment()
                            }
                        });
                        ExportToExcel(numberlist,group_index)
                        bar1.stop()
                        console.log(`\n${group.name} Numbers Saved!\n`);
                    });

Additional context / Screenshot

Hi9ibwB.md.jpg

ghayman commented 1 year ago

+1 - Here's my minimal code example

const venom = require('./dist/index');

venom
  .create({
    session: 'sessionName',
    headless: false,
    devtools: true
  })
  .then((client) => start(client))
  .catch(async (err) => {
    console.log('Startup error: ' + err);
  });
function start(client) {
  client.onAnyMessage((message) => {
    console.log(message);
    if (message['isGroupMsg']) {
      const ids = client
        .getGroupMembers(message['chatId'], 1000)
        .then((ids) => {
          console.log(ids);
        });
    }
  });
}
ghayman commented 1 year ago

@orkestral I know you guys probably hate my hacking but here is a possible solution. I'm not putting it through as a PR (yet) as I don't know the unexpected consequences. I commented out the call to openChatBottom() - I could not seeing it adding any value but I might be wrong. I rebuilt the dist and the getGroupParticipant() returned the participants.

I should add that this is being called during onAnyMessage() so maybe other things are being loaded at the same time outside of this.

Other people - please comment. This may or may not be a solution.

export async function getGroupParticipant(groupId, time = 1000) {
  if (typeof groupId !== 'string') {
    return WAPI.scope(undefined, true, null, 'Use to groupId string');
  }

  const chat = await WAPI.sendExist(groupId);

  if (chat && chat.status != 404 && chat.id) {
    // await window.Store.Cmd.openChatBottom(chat);
    // await sleep(time);
    const moduleGroup = await window.Store.GroupMetadata._models.filter(
      (e) => e.id._serialized === groupId
    );

: 
: 
: 
orkestral commented 1 year ago

Release 5.0.11

SMe12435 commented 8 months ago

@orkestral I know you guys probably hate my hacking but here is a possible solution. I'm not putting it through as a PR (yet) as I don't know the unexpected consequences. I commented out the call to openChatBottom() - I could not seeing it adding any value but I might be wrong. I rebuilt the dist and the getGroupParticipant() returned the participants.

I should add that this is being called during onAnyMessage() so maybe other things are being loaded at the same time outside of this.

Other people - please comment. This may or may not be a solution.

export async function getGroupParticipant(groupId, time = 1000) {
  if (typeof groupId !== 'string') {
    return WAPI.scope(undefined, true, null, 'Use to groupId string');
  }

  const chat = await WAPI.sendExist(groupId);

  if (chat && chat.status != 404 && chat.id) {
    // await window.Store.Cmd.openChatBottom(chat);
    // await sleep(time);
    const moduleGroup = await window.Store.GroupMetadata._models.filter(
      (e) => e.id._serialized === groupId
    );

: 
: 
: 

This worked for me. Thanks <3

pedroota commented 8 months ago

This still an issue for me, I'm facing the same problem here

Error: image

My code: image

ddimoia-wt commented 4 months ago

This still an issue for me, I'm facing the same problem here

Hi have you solved the issue?