Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Client.acceptInvite #2642

Open
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

alechkos
Copy link
Collaborator

@alechkos alechkos commented Nov 21, 2023

Important

breaking change Fix or feature that would cause existing functionality to change

Table of Contents

- Description

- Related Issue

- Usage Example

- I Want to Test this PR

- I Got an Error While Testing This PR ❌

- How Has the PR Been Tested (latest test on 01.12.2023)

- Types of Changes


Description

The Client.acceptInvite method previously encountered an error when attempting to accept an invitation link for a group with Membership Approval Mode turned on.

The PR fixes that issue, and also improves user convenience by merging Client.acceptGroupV4Invite into Client.acceptInvite, now you can achieve the same result using a single method.

Furthermore, the Client.acceptInvite method's return value now provides additional information, including error codes and their explanations, to help better understand any issues that may occur during the method's execution.
For not to break a lot the Client.acceptGroupV4Invite method hasn't been removed, all the underlying logic has been migrated to the Client.acceptInvite.

❗ Breaking Change:

The Client.acceptInvite, Client.acceptGroupV4Invite and Message.acceptGroupV4Invite methods now return an object with the following structure:

{
  gid: {
    server: 'g.us',
    user: '26422642XX',
    _serialized: '26422642XX@g.us'
  },
  status: 200,
  message: 'You joined the group/community successfully'
}

Related Issue

The PR closes #2570, closes #2256


Usage Example

client.on('message', async (msg) => {
    if (msg.body.startsWith('!join ')) {
        const inviteCode = msg.body.split(' ')[1];
        const result = await client.acceptInvite(inviteCode);
        /**
         * Example of the {@link result} object:
         * 
         * {
         *   gid: {
         *     server: 'g.us',
         *     user: '26422642XX',
         *     _serialized: '26422642XX@g.us'
         *   },
         *   statusCode: 200,
         *   message: 'You joined the group/community successfully'
         * }
         */
        console.log(result);
    } else if (msg.body === '!joinViaInviteV4' && msg.hasQuotedMsg) {
        const quotedMsg = await msg.getQuotedMessage();
        if (quotedMsg.inviteV4) {
            await client.acceptInvite(quotedMsg.inviteV4);
        }
    }
});

To test this PR by yourself you can run one of the following commands:

  • NPM
npm install github:alechkos/whatsapp-web.js#fix-accept-invite
  • YARN
yarn add github:alechkos/whatsapp-web.js#fix-accept-invite

If you encounter any errors while testing this PR, please provide in a comment:

  1. The code you've used without any sensitive information (use syntax highlighting for more readability)
  2. The error you got
  3. The library version
  4. The WWeb version: console.log(await client.getWWebVersion());
  5. The browser (Chrome/Chromium)

Important

You have to reapply the PR each time it is changed (new commits were pushed since your last application)


How Has The PR Been Tested (latest test on 01.12.2023)

Tested with a code provided in usage exmaple on groups that have the membership approval mode turned on and off.

Tested On:

Types of accounts:

  • Personal
  • Buisness

Environment:

  • Android 10:
    • WhatsApp: latest
    • WA Business: latest
  • Windows 10:
    • WWebJS: 1.23.1-alpha.0
    • WWeb: v2.2353.0
    • Puppeteer: v18.2.1
    • Node: v18.17.1
    • Chrome: latest

Types of Changes

  • Dependency change
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • I have updated the usage example accordingly (example.js)
  • I have updated the documentation accordingly (index.d.ts)

@alechkos alechkos added the breaking change Fix or feature that would cause existing functionality to change label Dec 1, 2023
@shirser121
Copy link
Collaborator

If the result object used to return {status: number} we should keep the status property, maybe instead of the code property

@alechkos
Copy link
Collaborator Author

@shirser121

If the result object used to return {status: number} we should keep the status property, maybe instead of the code property

I changed to statusCode to be more conventional, since the createGroup method of a Client class also returns statusCode in it

@alechkos alechkos added the waiting for testers Waiting for other people test this PR in other envs label Jan 14, 2024
@shirser121
Copy link
Collaborator

@shirser121

If the result object used to return {status: number} we should keep the status property, maybe instead of the code property

I changed to statusCode to be more conventional, since the createGroup method of a Client class also returns statusCode in it

It's still will break the current behavior

@alechkos
Copy link
Collaborator Author

@shirser121

It's still will break the current behavior

Yes, the pr has break changes

@shirser121
Copy link
Collaborator

So let keep it less breaking...
If you can keep the property, we should.
Add all the other properties, but keep to old one.
This is my opinion anyway

@alechkos
Copy link
Collaborator Author

@shirser121

So let keep it less breaking... If you can keep the property, we should. Add all the other properties, but keep to old one. This is my opinion anyway

No problem, renamed

@alechkos alechkos marked this pull request as draft April 16, 2024 02:53
Repository owner locked and limited conversation to collaborators Apr 16, 2024
Repository owner unlocked this conversation Apr 19, 2024
@alechkos alechkos marked this pull request as ready for review April 27, 2024 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Fix or feature that would cause existing functionality to change waiting for testers Waiting for other people test this PR in other envs
Projects
None yet
2 participants