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

feat: add new link with phone option #2363

Closed
wants to merge 19 commits into from

Conversation

fm1randa
Copy link
Contributor

@fm1randa fm1randa commented Jul 27, 2023

Implement the new Whatsapp Web feature to link with phone number

Description

  • Added LinkingMethod.js - A class that will model the configuration object to choose to link with a QR code or phone number.

index.js

  • Added LinkingMethod.

index.d.ts

  • Deprecated qrMaxRetries.
  • Updated JSDoc for qr event.
  • Added JSDoc for the new code event and the new linkingMethod property.
  • Added LinkingMethod class

src/Client.js

  • Added logic to handle linkingMethod

src/util/Constants.js

  • Added CODE_RECEIVED event.

tests/client.js

  • Added 2 new test cases to cover linkingMethod paths.

Motivation and Context

Implement the new feature to link with phone number.

How Has This Been Tested

Tested running npm run shell and npm test. Some tests are failing, but I've confirmed that they're failing on the main branch too.

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).

@fm1randa fm1randa force-pushed the link-with-phone-number branch 2 times, most recently from c504d6f to b8f1488 Compare July 27, 2023 04:40
@fm1randa fm1randa marked this pull request as ready for review July 27, 2023 06:57
@tofers
Copy link
Contributor

tofers commented Jul 27, 2023

The things that matter to me are.

  1. Switching between the two in a running Puppeteer (without restarting the client) by number and back again
  2. Entering a phone number after starting the client.
  3. Changing the phone number (in case of its erroneous entry ).
  4. Whether an error is handled after the codes waiting time expires

@shirser121
Copy link
Collaborator

Thanks you !
If there is anything i can help, please write it down

@fm1randa
Copy link
Contributor Author

The things that matter to me are.

  1. Switching between the two in a running Puppeteer (without restarting the client) by number and back again
  2. Entering a phone number after starting the client.
  3. Changing the phone number (in case of its erroneous entry ).
  4. Whether an error is handled after the codes waiting time expires
  1. My approach differs from what you expect. It's not possible to switch between the two. Also, I think it wouldn't be a thing that most users will use. IMO, you usually want to avoid playing around authentication part while automating a Whatsapp session. You want to authenticate and make your automation online as soon as possible.
  2. This library doesn't support user inputs after starting the client.
  3. Same answer as the above subject. You can achieve a flexible way to change the phone number (I mean, without changing the source code) by using an environment variable for it.
  4. I didn't reproduce this scenario locally. The expiration time is probably too big.

cc @tofers

@tofers
Copy link
Contributor

tofers commented Aug 1, 2023

Required to be reproduced as in the original WA.

  1. QR
  2. Transition to the phone
  3. Switch to QR

These are the basic actions in the original Whatsapp.

Restarting the puppeteer to switch methods is not the best way.

@fm1randa
Copy link
Contributor Author

fm1randa commented Aug 1, 2023

Required to be reproduced as in the original WA.

  1. QR
  2. Transition to the phone
  3. Switch to QR

These are the basic actions in the original Whatsapp.

Restarting the puppeteer to switch methods is not the best way.

@tofers Why would you like to switch methods in runtime? Just choose QR or Code, and then it will proceed with the selected mode.

@jgarciach
Copy link

just tested the phone code linking method and works great

lgtm

@tuyuribr
Copy link
Collaborator

tuyuribr commented Aug 4, 2023

Good work!

@tuyuribr tuyuribr added waiting for testers Waiting for other people test this PR in other envs good pr labels Aug 4, 2023
@renzhxr
Copy link

renzhxr commented Aug 5, 2023

haven't been able to get the login code after being linked?

@fm1randa
Copy link
Contributor Author

fm1randa commented Aug 5, 2023

haven't been able to get the login code after being linked?

@renzhxr I'm not sure if I got your issue. Could you describe it better?

If I got your question correctly, the answer is: you won't get any code after linking.

Copy link

@andresayac andresayac left a comment

Choose a reason for hiding this comment

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

Tested good job

@amiruldev20
Copy link

then how to do client.logout from this method?

@pfnh26
Copy link

pfnh26 commented Jan 25, 2024

a funcionalidade é incrível, estou projetando um chatbot, mas sou muito novo em código e a biblioteca está me ajudando muito, recentemente criei minha lógica para essa funcionalidade mas acredito que houve alguma mudança no WhatsApp web e na funcionalidade parou, certo? Vou imprimir o erro: Error: No node found for selector: div[role="button"] > div > div at assert (C:\Users\Phelipe\Desktop\Sistema-whatsapp-web2\node_modules\whatsapp-web. js\node_modules\puppeteer\lib\cjs\puppeteer\common\assert.js:26:15) em DOMWorld.click (C:\Users\Phelipe\Desktop\Sistema-whatsapp-web2\node_modules\whatsapp-web.js\ node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:287:32) em process.processTicksAndRejections (node:internal/process/task_queues:95:5) em assíncrono handleLinkWithPhoneNumber (C:\Users\Phelipe\Desktop\ Sistema-whatsapp-web2\node_modules\whatsapp-web.js\src\Client.js:321:17) em async Client.initialize (C:\Users\Phelipe\Desktop\Sistema-whatsapp-web2\node_modules\whatsapp-web .js\src\Client.js:403:17) em startWhatsAppSession assíncrono (C:\Users\Phelipe\Desktop\Sistema-whatsapp-web2\server.js:1363:13) em assíncrono C:\Users\Phelipe\Desktop \Sistema-whatsapp-web2\server.js:935:7

If anyone can solve it, I would be very grateful

Até onde eu sei, não haverá mais suporte para esse recurso porque ele depende da tag HTML e está sujeito a erros como o que você está enfrentando neste exemplo.

I thought it was because of this: npm i https://github.com/pedroslopez/whatsapp-web.js#main
not working here, by the way there is a command that updates the entire library on your PC, because: npm install whatsapp-web.js It's not working here either

@MobCode100
Copy link

Anyone can try it with npm install https://github.com/MobCode100/whatsapp-web.js.git and the below sample code:

const { Client, LinkingMethod, LocalAuth} = require('whatsapp-web.js');
const client = new Client(
    {
        linkingMethod:  new LinkingMethod({
            phone: {
                number: "+<COUNTRY CODE><PHONE NUMBER>"
            }
        }),
        puppeteer: {
            args: ['--no-sandbox'],
        },
    }
);
client.on('code', (code) => {
    console.log('CODE RECEIVED', code);
});
client.on('ready', () => {
    console.log('Client is ready!');
});
client.initialize();

@pfnh26 I've made a temporary modifications in my fork, that fixes the selector for me while waiting for this feature to be completed by this repository. Can I ask you to try and see if it works for you?

@pfnh26
Copy link

pfnh26 commented Jan 26, 2024

Qualquer um pode experimentá-lo com npm install https://github.com/MobCode100/whatsapp-web.js.gito código de exemplo abaixo:

const { Client, LinkingMethod, LocalAuth} = require('whatsapp-web.js');
const client = new Client(
    {
        linkingMethod:  new LinkingMethod({
            phone: {
                number: "+<COUNTRY CODE><PHONE NUMBER>"
            }
        }),
        puppeteer: {
            args: ['--no-sandbox'],
        },
    }
);
client.on('code', (code) => {
    console.log('CODE RECEIVED', code);
});
client.on('ready', () => {
    console.log('Client is ready!');
});
client.initialize();

@pfnh26Fiz modificações temporárias em meu fork, que corrigem o seletor para mim enquanto aguardo que esse recurso seja concluído por este repositório. Posso pedir que você experimente e veja se funciona para você?

This change worked, but is it temporary?

Thank you very much, my project really appreciates it

@MobCode100
Copy link

MobCode100 commented Jan 26, 2024

This change worked, but is it temporary?

Thank you very much, my project really appreciates it

Happy to have it working for you! It is temporary because WhatsApp Web can make changes on the UI, thus we'll have to update the code again. I'll keep maintaining my fork tho, cause one of my project is using it until whatsapp-web.js have the feature to link by phone.

@pfnh26
Copy link

pfnh26 commented Jan 26, 2024

This change worked, but is it temporary?
Thank you very much, my project really appreciates it

Happy to have it working for you! It is temporary because WhatsApp Web can make changes on the UI thus, we'll have to update the code again. I'll keep maintaining my fork tho, cause one of my project is using it until whatsapp-web.js have the feature to link by phone.

Thanks again, but I'm hoping that whatsapp-web.js has this feature natively, we agree that QRcode authentication is very outdated

@aidar87
Copy link

aidar87 commented Jan 31, 2024

Any updates? will this pull request merged?

@pfnh26
Copy link

pfnh26 commented Apr 2, 2024

Essa mudança funcionou, mas é temporária?
Muito obrigado, meu projeto realmente agradece

Fico feliz em tê-lo funcionando para você! É temporário porque o WhatsApp Web pode fazer alterações na UI, portanto teremos que atualizar o código novamente. Vou continuar mantendo meu fork, porque um dos meus projetos está usando-o até que o whatsapp-web.js tenha o recurso de link por telefone.

good afternoon my friend, how are you?
Again we are having the same problem when authenticating using a WhatsApp number, I believe that today WhatsApp made some changes as it also fell due to webVersionCache, but in the end, I would like to know if somehow I can learn to manipulate the code like you do so I can help you update this authentication method, if it's something manual, you can give me the tutorial and I'll make the updates, or if you can do it.
Thank you very much in advance

@MobCode100
Copy link

Essa mudança funcionou, mas é temporária?
Muito obrigado, meu projeto realmente agradece

Fico feliz em tê-lo funcionando para você! É temporário porque o WhatsApp Web pode fazer alterações na UI, portanto teremos que atualizar o código novamente. Vou continuar mantendo meu fork, porque um dos meus projetos está usando-o até que o whatsapp-web.js tenha o recurso de link por telefone.

good afternoon my friend, how are you?
Again we are having the same problem when authenticating using a WhatsApp number, I believe that today WhatsApp made some changes as it also fell due to webVersionCache, but in the end, I would like to know if somehow I can learn to manipulate the code like you do so I can help you update this authentication method, if it's something manual, you can give me the tutorial and I'll make the updates, or if you can do it.
Thank you very much in advance

Thanks for the notice, I'll check the problem and try to fix it later this day. You can modify if you have some knowledge on JavaScript, there a lots of tutorial in the internet. The file to be modified is the LinkingMethod.js. Fork my git repo. Make your changes, and then install using the command above but be sure to replace the url to your forked git repo. Make sure to change the client headless config to false for testing changes. You can also modify the code directly inside node_modules folder for testing. Goodluck.

@pfnh26
Copy link

pfnh26 commented Apr 2, 2024

Essa mudança funcionou, mas é temporária?
Muito obrigado, meu projeto realmente agradece

Fico feliz em tê-lo funcionando para você! É temporário porque o WhatsApp Web pode fazer alterações na UI, portanto teremos que atualizar o código novamente. Vou continuar mantendo meu fork, porque um dos meus projetos está usando-o até que o whatsapp-web.js tenha o recurso de link por telefone.

good afternoon my friend, how are you?
Again we are having the same problem when authenticating using a WhatsApp number, I believe that today WhatsApp made some changes as it also fell due to webVersionCache, but in the end, I would like to know if somehow I can learn to manipulate the code like you do so I can help you update this authentication method, if it's something manual, you can give me the tutorial and I'll make the updates, or if you can do it.
Thank you very much in advance

Thanks for the notice, I'll check the problem and try to fix it later this day. You can modify if you have some knowledge on JavaScript, there a lots of tutorial in the internet. The file to be modified is the LinkingMethod.js. Fork my git repo. Make your changes, and then install using the command above but be sure to replace the url to your forked git repo. Make sure to change the client headless config to false for testing changes. You can also modify the code directly inside node_modules folder for testing. Goodluck.

OK, I'll study this, I believe I can help you next time.
I'm looking for an investor so that I can launch this project, in addition to whatsapp-web.js I'm also using other libraries and Python to incorporate an AI model, soon I'll be able to hire people to help with this project, and these errors will no longer be problems ^^

@MobCode100
Copy link

MobCode100 commented Apr 3, 2024

webVersionCache

I believe that today WhatsApp made some changes as it also fell due to webVersionCache,

Okay, so I've looked into it. It's an ongoing problem with WhatsApp Web version 2.3XXX. The workaround is to add the webVersionCache config as below:

const wwebVersion = '2.2412.54';
const client = new Client(
    {
        linkingMethod:  new LinkingMethod({
            phone: {
                number: "+<COUNTRY CODE><PHONE NUMBER>"
            }
        }),
        puppeteer: {
            args: ['--no-sandbox'],
        },
        webVersionCache: {
            type: 'remote',
            remotePath: `https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/${wwebVersion}.html`,
        },
    }
);

Be sure to update your whatsapp-web.js package with npm update.
See https://github.com/wppconnect-team/wa-version/tree/main/html for versions.

@pfnh26
Copy link

pfnh26 commented Apr 3, 2024

webVersionCache

I believe that today WhatsApp made some changes as it also fell due to webVersionCache,

Okay, so I've looked into it. It's an ongoing problem with WhatsApp Web version 2.3XXX. The workaround is to add the webVersionCache config as below:

const wwebVersion = '2.2412.54';
const client = new Client(
    {
        linkingMethod:  new LinkingMethod({
            phone: {
                number: "+<COUNTRY CODE><PHONE NUMBER>"
            }
        }),
        puppeteer: {
            args: ['--no-sandbox'],
        },
        webVersionCache: {
            type: 'remote',
            remotePath: `https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/${wwebVersion}.html`,
        },
    }
);

Be sure to update your whatsapp-web.js package with npm update. See https://github.com/wppconnect-team/wa-version/tree/main/html for versions.

Sorry for not telling you how to resolve the webVersionCache error, below is the solution:
• In src/util/constants.js to replace:
webVersionCache: {
type: 'remote',
remotePath: 'https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2410.1.html',
}

It's the same thing you did, but including it this way you don't need to write it inside the client code.

@MobCode100
Copy link

It's the same thing you did, but including it this way you don't need to write it inside the client code.

Thank you for this, I'll make this change soon!

@pfnh26
Copy link

pfnh26 commented Apr 3, 2024

const wwebVersion = '2.2412.54';
const client = new Client(
    {
        linkingMethod:  new LinkingMethod({
            phone: {
                number: "+<COUNTRY CODE><PHONE NUMBER>"
            }
        }),
        puppeteer: {
            args: ['--no-sandbox'],
        },
        webVersionCache: {
            type: 'remote',
            remotePath: `https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/${wwebVersion}.html`,
        },
    }
);

Did you manage to resolve the "LinkingMethod" error?
Is it already operational?
I'm using it this way:
const { Client, LinkingMethod, LocalAuth} = require('whatsapp-web.js');
const client = new Client(
{
linkingMethod: new LinkingMethod({
phone: {
number: "+000000000"
}
}),
puppeteer: {
args: ['--no-sandbox'],
},
}
);
client.on('code', (code) => {
console.log('CODE RECEIVED', code);
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.initialize();

@MobCode100
Copy link

Is it already operational?

Yes, you can use it normally now. Just run npm update.

@pfnh26
Copy link

pfnh26 commented Apr 3, 2024

Is it already operational?

Yes, you can use it normally now. Just run npm update.

The code is not being generated, could I be doing something wrong?

@MobCode100
Copy link

The code is not being generated, could I be doing something wrong?

Try to delete your session folder, or maybe reinstall my repo:

npm uninstall whatsapp-web.js
npm install https://github.com/MobCode100/whatsapp-web.js.git

@pfnh26
Copy link

pfnh26 commented Apr 3, 2024

The code is not being generated, could I be doing something wrong?

Try to delete your session folder, or maybe reinstall my repo:

npm uninstall whatsapp-web.js
npm install https://github.com/MobCode100/whatsapp-web.js.git

I did this, but the code is not generated, it does not give an error, but it also does not generate the code.
Is it the format of the WhatsApp number?

const { Client, LinkingMethod, LocalAuth} = require('whatsapp-web.js');
const client = new Client(
{
linkingMethod: new LinkingMethod({
phone: {
number: "+000000000000"
}
}),
puppeteer: {
args: ['--no-sandbox'],
},
}
);
client.on('code', (code) => {
console.log('CODE RECEIVED', code);
});
client.on('ready', () => {
console.log('Client is ready!');
});
client.initialize();

@MobCode100
Copy link

Is it the format of the WhatsApp number?

I don't think so, I've tried exactly your code and I'm able to receive the code from WhatsApp. Maybe try new number? Just in case, I've changed the WhatsApp version in my repo. You can try to reinstall again.

@pfnh26
Copy link

pfnh26 commented Apr 6, 2024

Is it the format of the WhatsApp number?

I don't think so, I've tried exactly your code and I'm able to receive the code from WhatsApp. Maybe try new number? Just in case, I've changed the WhatsApp version in my repo. You can try to reinstall again.

Sorry for the delay in testing, but it still doesn't work for me, the format I used before was like this <+556292286543>
my country changed the number by adding the number 9 after 62, like this
<+5562992286543> but this change was not necessary the first time the code worked, please if you can check why it is not working, when I request the code event it simply does not happen, nor does it give an error in my code

@MobCode100
Copy link

<+5562992286543> but this change was not necessary the first time the code worked, please if you can check why it is not working,

I've tried that number, I still can get the code... very strange. Let's not spam our conversations here, create an issue here.

@pfnh26
Copy link

pfnh26 commented Apr 8, 2024

<+5562992286543> but this change was not necessary the first time the code worked, please if you can check why it is not working,

I've tried that number, I still can get the code... very strange. Let's not spam our conversations here, create an issue here.

here it is :
MobCode100#1

@PurpShell PurpShell closed this Apr 14, 2024
@PurpShell
Copy link
Sponsor Collaborator

#2816

@pfnh26
Copy link

pfnh26 commented May 17, 2024

@MobCode100 all good?
Today the error was reported:
throw new Error('Evaluation failed: ' + (0, util_js_1.getExceptionMessage)(exceptionDetails));
^

Error: Evaluation failed: TypeError: Unable to read properties from undefined (reading 'push')
in fillModuleArray (evaluation in (:2:5), :6:74)

Updating this way I managed to solve:
npm install github:pedroslopez/whatsapp-web.js#webpack-exodus

You can update yours because of LinkingMethod:
npm install https://github.com/MobCode100/whatsapp-web.js.git

please?

@MobCode100
Copy link

Does webpack exodus supports phone linking method?

@pfnh26
Copy link

pfnh26 commented May 17, 2024

Does webpack exodus supports phone linking method?

unfortunately not

@pfnh26
Copy link

pfnh26 commented May 18, 2024

@MobCode100
I made a small modification to the client instantiation by adding:
webVersionCache: {
type: "remote",
remotePath: "https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2412.54.html"
}

the only problem is that apparently the webcache has a bug regarding sending MP4
using webpack-exodus and MP4 in this format works:
format = mp4
video Codec= libx264
video Bitrate = 500k'
audio bitrate = 128k

however with webpack-exodus the application may have a bug in other parts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet