pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
15.54k stars 3.7k forks source link

Add LocalAuth support for a temporary file system #1447

Closed ShlomoCode closed 2 years ago

ShlomoCode commented 2 years ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe.

The documentation says: WARNING LocalAuth requires a persistent filesystem to be able to restore sessions. This means that out of the box it is not compatible with hosts that provide ephemeral file systems, such as Heroku.

Describe the solution you'd like.

Add a setting for the sessions to be saved and restored using the mongoDB database. This should be easy to do, using a remote database address, like Mongo db Atlas, or https://www.clever-cloud.com for free.

Describe an alternate solution.

No response

Additional context

No response

miamith commented 2 years ago

Greetings, my question is?

I am looking for someone with this solution, I have the same problem, and I want to keep my session in mongoDB, before with LegacyAuth I had it in mongo.

Share the code please, I need it friend.

sessionData = await cargarSession(); if (sessionData != '') { sessionData = JSON.parse(sessionData); } else { sessionData = ''; }

1397

ShlomoCode commented 2 years ago

@miamith I did not understand your intention... Using the ORM mongoose it should be short and easy. What part are you missing?

I did not understand the code you quoted; It does not demonstrate the use of mongoose/mongodb

miamith commented 2 years ago

@ShlomoCode I am asking if you already have a solution to save the session and restore it in a database, since heroku does not allow it. you have a solution now ? Please I urge you, share

Using LocalAuth creates too many folders on local and it is not supported by heroku.

I am also wondering if this session can be saved to MEGA and retrieved? If you have a solution share. Thanks in advance

ShlomoCode commented 2 years ago

@miamith No, I have not written anything like this - I do not yet actually use this repo. I also do not know enough about the structure of the code, and many creators prefer to fix things themselves, according to different habits, eslinter's, and so on.


How long is the validation of the file system valid? Because you can add the authentication data folder to Git and push it to heroku as part of the code. While this is not a recommended solution at all but should work.

Just note that Herco limits the code to 1 GB...

CHR-onicles commented 2 years ago

How long is the validation of the file system valid? Because you can add the authentication data folder to Git and push it to heroku as part of the code. While this is not a recommended solution at all but should work.

@ShlomoCode I tried that, it doesn't work

ShlomoCode commented 2 years ago

@CHR-onicles What exactly did you try? Did you authenticate on your computer, then add the authentication files added to the git and push the git of heroku?

miamith commented 2 years ago

With what code reloads the session saved locally in the .ww folder so as not to scan again, I want the complete code, please?

I am already fighting with the Twilio team if they can approve me a number to rewrite the code of my chatBot there, our solution is not stable for production.

CHR-onicles commented 2 years ago

@ShlomoCode I pushed the whole .wwebjs_auth folder to git hoping heroku can then use it as Local Auth, but the QR code still appeared to be scanned every time the code is run. It completely ignored the .wwebjs_auth folder.

CHR-onicles commented 2 years ago

With what code reloads the session saved locally in the .ww folder so as not to scan again, I want the complete code, please?

I am already fighting with the Twilio team if they can approve me a number to rewrite the code of my chatBot there, our solution is not stable for production.

const client = new Client({ authStrategy: new LocalAuth() });

This recovers local sessions that are saved in the .wwebjs_auth folder

ShlomoCode commented 2 years ago

@CHR-onicles It just can not be; Everything uploaded as part of the code is saved. Only new files that the app saves are only saved for a limited time, and occasionally reset Look at Haroku documentation ...

CHR-onicles commented 2 years ago

@ShlomoCode I suggest you try it then, because I have (for v1.16.5) and I'm just sharing my experience 👍🏽

miamith commented 2 years ago

Greetings again, @CHR-onicles what you say @ShlomoCode about logging in locally and then uploading everything with the session to heroku works very well, only it is not a recommended technique, last year it worked for me before, but I was not sure that these versions would work more like this. EYE 1: if you log out of your phone, the session folder you uploaded to heroku loses value. EYE 2: Heroku will be restarting if your account is free

miamith commented 2 years ago

image

Here is an observation in heroku when looking at the logs: heroku logs, I see these alerts popping up that I don't know how to resolve, so there are blockages after having an emergency solution. Any solution?

ShlomoCode commented 2 years ago

@miamith I do not think an error in CPU usage is related to this issue... Maybe try to upgrade the dyno? Or maybe buy your own regular server? It seems to me that https://contabo.com is the cheapest. But like I said it is no longer related here.. :)

miamith commented 2 years ago

@ShlomoCode I don't quite understand what you recommend, that I upload my app in contabo?

ShlomoCode commented 2 years ago

@miamith Yes. From what I know they are the cheapest for a reasonable Linux server. (Probably there are better solutions; upgrading the program on heroku should also help - https://www.heroku.com/pricing, my suggestion was based on the fact that anyone who uses free heroku will want as cheap a replacement as possible... hope you know the The basic procedure with a Linux server :))

miamith commented 2 years ago

@ShlomoCode Thanks for the recommendation, I'm just looking for something cheaper.

Do you know if contabo accepts to create files without deleting, it is with the idea of ​​session, heroku its system is ephemeral.

ShlomoCode commented 2 years ago

@miamith Sure, this is a completely standard Linux server, you can save files according to the storage volume you bought.

TemaSM commented 2 years ago

It seems to me that https://contabo.com is the cheapest

Do not recommend contabo VPSs (OpenVZ) and their dedicated servers. Yeah, very cheap, but very very slow CPUs (low frequencies, virtualization overhead), bad IOPS (slow disks, even marked as NVMe) and etc. Don't waste your money and time, as I did in past. Here's that I can recommend (especially for using whatsapp-web.js with multiple Chrome's instances launched, as they are CPU + RAM usage expensive): 1) Aeza - best VPSs I've used. High & performant CPU frequencies (5+ Ghz), stability, helpful support (they can install and configure anything you need on your VPS at no extra charge), optimizations, etc, and they even have a cryptocurrency payment option.

2) Hetzner - cheapest dedicated servers, and awesome "Servers auction" page: https://www.hetzner.com/sb, great Cloud solutions, like VPS and much more

*Not an advert, but simple recommendation. Hope it will help someone ❤️

jtouris commented 2 years ago

Please take a look at https://github.com/pedroslopez/whatsapp-web.js/pull/1450

This Issue will be solved with RemoteAuth. It will allow the use of any cloud server without depending on a persistent file system (including heroku, digitalOcean etc). RemoteAuth is a new Auth Strategy that allows saving the WhatsApp Multi-Device session into a remote database.

miamith commented 2 years ago

Specific temporary message Hide confidential data

Greetings Pedros and other experts, I have a chatBot where I ask the user to enter their PIN code in the chat, I would like that if the message has the PIN code in its body, that it be sent temporarily or automatically deleted in 2 minutes in the chat for the security of the credential data of the user that my chatBot is using, it is a thought in case it is possible for the library to do this taking advantage of the fact that WhatsApp has the option of temporary messages.

What is the possibility to be able to control a type of message that carries a data that we would like to get out of the chat?

_Also, if someone comes up with any other security solution for this PIN data, it is sensitive and confidential data, please, do not hesitate to contact me, I will be very grateful and invite you for a coffee._

1434