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: Contact #2325

Merged
merged 12 commits into from
Jul 31, 2023
Merged

fix: Contact #2325

merged 12 commits into from
Jul 31, 2023

Conversation

alechkos
Copy link
Collaborator

@alechkos alechkos commented Jul 2, 2023

PR Details

- Description

- Motivation and Context

- Related Issues

- How Has the PR Been Tested

- Types of Changes


Description

  1. Fixes for Contact class:
  • Client.getContactById() method now retreives the valid contact info
  • Contact.block() method fixed to block a contact
  • The value of Contact.isBlocked property changes after the block() or unblock() methods are called
  1. Added inner function to compare between two WWeb versions.
    Its purpose is to provide a compatibility between old code implementations and a new updates made for the library to be synced with the newer WWeb versions. The thing will ensure the stable work for WWebJS no matter what version of WWeb is used.

Motivation and Context

After the WWeb v2.2327.4 the contact data structure has been modified causing some of the Contact class field values to be undefined, so it would be nice to fix an issue and keep this lib up-to-date with the latest WWeb version.

Related Issues

PR fixes #2299 fixes #2312

How Has This Been Tested

The code used in tests:

client.on('message', async (message) => {
    if (message.body === '!test') {
        const contact = await client.getContactById(message.author ?? message.from);
        console.log(contact);
        console.log('TRYING TO BLOCK...');
        await contact.block();
        console.log(`CHECKING IF BLOCKED...\n${contact.isBlocked}`);
        console.log('TRYING TO UNBLOCK...');
        await contact.unblock();
        console.log(`CHECKING IF UNBLOCKED...\n${contact.isBlocked}`);
    }
});

Tested On

Types of accounts:

  • Personal
  • Buisness

Environment:

  • Android 10
  • Windows 10:
    • WWebJS v1.21.0
    • WWeb v2.2327.4
    • Node v16.17.1
    • Chrome 114.0.5735.199

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

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

If you encounter any issues 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 library version
  3. The WWeb version: console.log(await client.getWwebVersion());
  4. The browser (Chrome/Chromium)
  5. The error you got

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 or feature that would cause existing functionality to change)

Checklist

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

ALΞX added 4 commits July 2, 2023 17:38
The function compares the currently used WWeb version with the version that requires the code changes. Its purpose is to ensure the stable operation of the library across different WWeb versions.
@T3uZ
Copy link

T3uZ commented Jul 2, 2023

Boa noite, funcionou perfeitamente aqui, obrigado.

@ivanzigoni
Copy link

ivanzigoni commented Jul 3, 2023

hi.
just tested the pr and it seems to be working fine, although some contact's fields (labels, sectionHeader, statusMute, verifiedLevel and verifiedName) are still undefined but since i don't know exactly what they refer to, i guess that's just how it is?

edit: it also fixes the client.getContacts() and probably any other calls that returns Contact or Contact[].

@alechkos
Copy link
Collaborator Author

alechkos commented Jul 3, 2023

@ivanzigoni

although some contact's fields (labels, sectionHeader, statusMute, verifiedLevel and verifiedName) are still undefined

Thank you for your test,
labels, sectionHeader, statusMute, verifiedLevel and verifiedName are expected to be undefined if they do not have a value in your contact object.

@PedroLGaldino
Copy link

It still returns the contact as undefined, when sending the contact to another contact and saving it in the mysql database, it worked perfectly before.

@alechkos
Copy link
Collaborator Author

alechkos commented Jul 3, 2023

@PedroLGaldino

It still returns the contact as undefined, when sending the contact to another contact and saving it in the mysql database, it worked perfectly before.

Provide the code you used

@PedroLGaldino
Copy link

PedroLGaldino commented Jul 3, 2023

ok

@alechkos
Copy link
Collaborator Author

alechkos commented Jul 3, 2023

@PedroLGaldino
what wweb version do you use?

console.log(await client.getWWebVersion());

did you run npm install github:alechkos/whatsapp-web.js#fix-contact?

@PedroLGaldino
Copy link

@PedroLGaldino qual versão do wweb vc usa?

console.log(await client.getWWebVersion());

você correu npm install github:alechkos/whatsapp-web.js#fix-contact?

Yes:

{
"dependencies": {
"mysql2": "^3.4.3",
"qrcode-terminal": "^0.12.0",
"whatsapp-web.js": "github:alechkos/whatsapp-web.js"
}
}

@alechkos
Copy link
Collaborator Author

alechkos commented Jul 3, 2023

@PedroLGaldino
Can you run

console.log(await client.getWWebVersion());
console.log(await client.getContactById(/** number@c.us */);

and send the output without sensitive information?

@PedroLGaldino
Copy link

PedroLGaldino commented Jul 3, 2023

console.log(await client.getWWebVersion());
console.log(await client.getContactById(/** number@c.us */);

PrivateContact {
id: {
server: 'c.us',
user: 'x',xxxxxxxxxxxxx
_serialized: xxxxxxxxxxx@c.us'
},
number: undefined,
isBusiness: undefined,
isEnterprise: undefined,
labels: undefined,
name: undefined,
pushname: 'Client',
sectionHeader: undefined,
shortName: undefined,
statusMute: undefined,
type: 'in',
verifiedLevel: undefined,
verifiedName: undefined,
isMe: undefined,
isUser: undefined,
isGroup: undefined,
isWAContact: undefined,
isMyContact: undefined,
isBlocked: false
}

The contact appears in the log. So I'm getting it wrong in my code

@alechkos
Copy link
Collaborator Author

alechkos commented Jul 3, 2023

@PedroLGaldino what about this?

console.log(await client.getWWebVersion());

@PedroLGaldino
Copy link

@PedroLGaldinoe quanto a isso?

console.log(await client.getWWebVersion());

Sorry 2.2327.4

@alechkos
Copy link
Collaborator Author

alechkos commented Jul 3, 2023

@PedroLGaldino

2.2327.4

Is it a buisiness contact? Because i havent checked the fix on buisiness contacts yet

@PedroLGaldino
Copy link

@PedroLGaldino

2.2327.4

Is it a buisiness contact? Because i havent checked the fix on buisiness contacts yet

Yes its a bussines acount and bussines contact. So I'll wait for the solution, if you need help I'm available

@alechkos
Copy link
Collaborator Author

alechkos commented Jul 3, 2023

@PedroLGaldino

Yes its a bussines acount and bussines contact. So I'll wait for the solution, if you need help I'm available

Thank you for your tests, ill check later and make required changes

@alechkos
Copy link
Collaborator Author

alechkos commented Jul 4, 2023

@PedroLGaldino i made some changes so you can test it, please let me know if you have issues

Copy link

@Matheus-Lima-Moreira Matheus-Lima-Moreira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just worked fine for me, i had some issues recently with wwebjs that multiplied some groups generating a new group with a new id, this group was recognized as a contact and received the new messages, while the old one only sent, after this patch the problem is fixed.
wwebjs version test was 1.21 and 1.95

@dottovip
Copy link

dottovip commented Jul 5, 2023

It works for me. Thanks

@diegofemello
Copy link

worked for me, thanks

@hldpzz
Copy link

hldpzz commented Jul 7, 2023

Worked here, thank you very much!

@fenchai23
Copy link

bro where is the merge🤨

@T3uZ
Copy link

T3uZ commented Jul 10, 2023

Mais alguem com problemas para baixar no ??
npm install github:alechkos/whatsapp-web.js#fix-contact

@Mr-Nobody1
Copy link

works fine on my machine but when I try to do it on VM it shows me this
image

@alechkos
Copy link
Collaborator Author

alechkos commented Jul 28, 2023

@Mr-Nobody1

when I try to do it on VM it shows me this

The error you got is unrelated to this PR, check your git/npm settings on the VM

@Mr-Nobody1
Copy link

@Mr-Nobody1

when I try to do it on VM it shows me this

The error you got is unrelated to this PR, check your git/npm settings on the VM

Ok I was able to install it and it works fine. Thanks

@shirser121
Copy link
Collaborator

@pedroslopez @PurpShell

Copy link
Collaborator

@shirser121 shirser121 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@shirser121 shirser121 merged commit c8c2f09 into pedroslopez:main Jul 31, 2023
1 check passed
fm1randa added a commit to fm1randa/whatsapp-web.js that referenced this pull request Aug 1, 2023
* fix: Contact (pedroslopez#2325)

* fixed: contact info retrieving

* fixed: block method

* fixed: isBlocked property is now changeble

* added inner function to compare between WWeb versions

The function compares the currently used WWeb version with the version that requires the code changes. Its purpose is to ensure the stable operation of the library across different WWeb versions.

* added: todo remove useOldImplementation

* improved inner function to compare WWeb versions

* inner function: added support for beta versions

* added support for business accounts

* module queries changed to strings

* fixed check for wweb beta versions

* updated to throw a custom error message

* minor changes in inner function

* feat: send photo/video as a view once message (pedroslopez#2317)

* added isViewOnce property

* docs updated

* added usage example

* fix: ESLint

* feat: add new link with phone option
without regen observer

* feat: implement code regeneration observer

* chore: revert .gitignore change

* chore: .gitignore EOF

* refactor: replace wrong `LinkingOption` param type with `object`

* refactor: make qr handler use the new `linkingMethod.qr.maxRetries`

* test: add new test cases for linking method

* refactor: improve new code checking

* test: replace number with a number provided in the `.env`

* refactor: improve constructor typing

* refactor: make never properties optional

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
@shirser121 shirser121 mentioned this pull request Aug 3, 2023
1 task
matiascamiletti pushed a commit to Tots-Agency/whatsapp-web.js that referenced this pull request Aug 10, 2023
* fixed: contact info retrieving

* fixed: block method

* fixed: isBlocked property is now changeble

* added inner function to compare between WWeb versions

The function compares the currently used WWeb version with the version that requires the code changes. Its purpose is to ensure the stable operation of the library across different WWeb versions.

* added: todo remove useOldImplementation

* improved inner function to compare WWeb versions

* inner function: added support for beta versions

* added support for business accounts

* module queries changed to strings

* fixed check for wweb beta versions

* updated to throw a custom error message

* minor changes in inner function
fm1randa added a commit to fm1randa/whatsapp-web.js that referenced this pull request Aug 13, 2023
* fix: Contact (pedroslopez#2325)

* fixed: contact info retrieving

* fixed: block method

* fixed: isBlocked property is now changeble

* added inner function to compare between WWeb versions

The function compares the currently used WWeb version with the version that requires the code changes. Its purpose is to ensure the stable operation of the library across different WWeb versions.

* added: todo remove useOldImplementation

* improved inner function to compare WWeb versions

* inner function: added support for beta versions

* added support for business accounts

* module queries changed to strings

* fixed check for wweb beta versions

* updated to throw a custom error message

* minor changes in inner function

* feat: send photo/video as a view once message (pedroslopez#2317)

* added isViewOnce property

* docs updated

* added usage example

* fix: ESLint

* feat: add new link with phone option
without regen observer

* feat: implement code regeneration observer

* chore: revert .gitignore change

* chore: .gitignore EOF

* refactor: replace wrong `LinkingOption` param type with `object`

* refactor: make qr handler use the new `linkingMethod.qr.maxRetries`

* test: add new test cases for linking method

* refactor: improve new code checking

* test: replace number with a number provided in the `.env`

* refactor: improve constructor typing

* refactor: make never properties optional

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
dlimars pushed a commit to somosversotech/whatsapp-web.js that referenced this pull request Nov 7, 2023
* fixed: contact info retrieving

* fixed: block method

* fixed: isBlocked property is now changeble

* added inner function to compare between WWeb versions

The function compares the currently used WWeb version with the version that requires the code changes. Its purpose is to ensure the stable operation of the library across different WWeb versions.

* added: todo remove useOldImplementation

* improved inner function to compare WWeb versions

* inner function: added support for beta versions

* added support for business accounts

* module queries changed to strings

* fixed check for wweb beta versions

* updated to throw a custom error message

* minor changes in inner function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet