open-wa / wa-automate-nodejs

💬 🤖 The most reliable tool for chatbots with advanced features. Be sure to 🌟 this repository for updates!
https://docs.openwa.dev/
Other
3.14k stars 600 forks source link

error when call method addParticipant #847

Closed luanmnz closed 4 years ago

luanmnz commented 4 years ago

When i call the method addParticipant, i have the above error in puppeteer:

Evaluation failed: TypeError: Cannot read property 'id' of undefined\n at https://web.whatsapp.com/lazy_loaded_high_priority_components~lazy_loaded_low_priority_components.b1c2491b1125907ddb05.js:2:48250\n at Array.some (<anonymous>)\n at e (https://web.whatsapp.com/lazy_loaded_high_priority_components~lazy_loaded_low_priority_components.b1c2491b1125907ddb05.js:2:48217)\n at Object.t.addParticipants (https://web.whatsapp.com/lazy_loaded_high_priority_components~lazy_loaded_low_priority_components.b1c2491b1125907ddb05.js:2:49026)\n at Object.window.WAPI.addParticipant (/Users/luanmenezes/Projetos/api-whatsapp/node_modules/@open-wa/wa-automate/dist/lib/wapi.js:1964:37)\n at __puppeteer_evaluation_script__:3:41

my code:

app.post("/addParticipant", async (req, res) => {
  try {
           const res = await globalClient.addParticipant('xxxxx-xxxx@g.us', 'xxxxx-xxxx@c.us');

        return res.json({msg:'ok'});
  } catch (err) {
    return res.status(500).send({ error: err.message });
  }
});

create code:

wa.create({
  sessionId: "session-teste",
  //executablePath: '/usr/bin/google-chrome',
  autoRefresh: true,
  qrRefreshS: 60,
  headless: true,
  throwErrorOnTosBlock: true,
  cacheEnabled: false,
}).then((client: Client) => start(client));
Debug Info {
  WA_VERSION: '2.2037.6',
  PAGE_UA:  'WhatsApp/2.2037.6 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
  WA_AUTOMATE_VERSION: '2.0.24 UPDATE AVAILABLE: 2.0.24',
  BROWSER_VERSION: 'HeadlessChrome/86.0.4240.0'  
}
smashah commented 4 years ago

@luanmnz

           const res = await globalClient.addParticipant('xxxxx-xxxx@g.us', 'xxxxx-xxxx@c.us');

Why is there a - in the second parameter? - is only used in a group id. It looks like you are removing a group from a group.

smashah commented 4 years ago

@luanmnz is the account you're trying to remove a contact?

luanmnz commented 4 years ago

@luanmnz

           const res = await globalClient.addParticipant('xxxxx-xxxx@g.us', 'xxxxx-xxxx@c.us');

Why is there a - in the second parameter? - is only used in a group id. It looks like you are removing a group from a group.

It's only an example. I'm trying to add an participant to a group. I'm giving the group id in the first param, and the contact id in the second param. Ignore the - in the second param

smashah commented 4 years ago

@luanmnz is the participant you're trying to add a contact or some random number?

luanmnz commented 4 years ago

@luanmnz is the participant you're trying to add a contact or some random number?

is a number that has whatsapp, but is not in my contacts

smashah commented 4 years ago

@luanmnz you can't add random people to groups. They have to be in your contacts

Try to send them an invite link instead

luanmnz commented 4 years ago

@luanmnz you can't add random people to groups. They have to be in your contacts

Try to send them an invite link instead

I tried to add this number to my contacts, it appeared on the whatsapp list, but still it was not possible to add it to the group

smashah commented 4 years ago

@luanmnz try this:

  1. Add the number as a contact on your phone
  2. Manually start a chat with them on the phone
  3. Wait a few minutes.
  4. Add them to the group using the code.

If that works then the issue is because the person you're trying to add is not a contact.

You can force the session to sync contacts (after you do it from the phone) using: https://open-wa.github.io/wa-automate-nodejs/classes/client.html#synccontacts

Again, the best thing to do is to add them after they have started a chat with you or generate the invite link and send it to them.