Whatsapp web JS - remote authentication node js | Remote auth | mongo DB

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
before we start off I want you to check out my community on NAS dot IO super programmers community so in this community you can get a lot of more support and you can learn a lot of more stuff about what's up web.js and not only that you can get more things like you can learn about different programming languages you can get different webinars I'll be conduct live sessions you can also book a one-on-one session with me so that you can connect on a personal level and just join it's just four dollars per month but you can use the coupon code join now save to just get it for like two dollars per month so if you want to check it out please check it out and do support me and if you need more stuff you can definitely connect with me and ask me about something and yeah and once you join the company it's just free you can get all the content for free and forever so it will look something like this where you as a user you can go over here and look at all of the um you know announcements that I make you know you can see all of the events that are happening over here and you can you can see all of the members you can you can connect with me on a personal level by booking a session on currently based on your yeah and you can see all of the courses that I offer and it's just completely for free so please do check it out I will be providing the link in the description and thank you so much well hello and welcome so I have gotten a lot of requests from people tell me about WhatsApp web.js remote authentication part so I'm gonna show you how we can use mongodb to stir the session of the users on a database and then revive it again so let's go and take the documentation I believe where we have remote auth of course there's not a lot of uh you know information over here but we need to use remote auth and we need to use ww web.js web.js a library that is also written by the same guy who developed this so uh all you have to do is to just do nbmi webmongo web.js slash Mongol so let me do that nbmi okay and remote auth is inside WhatsApp web.js so storing and using it this very very simple all you need to do is just use and my Monger server is running over here I have connected it locally so you can also go ahead and set it up and also I think I also need nvmi mongoose yeah something like this and uh you know we will basically connect okay so we will just copy and paste the same thing so what we'll need is store which we have already imported and we will okay we'll just use this okay we won't do this we'll just you know initialize this store so I ideally when mongodb is connected we will have to you know we'll just initialize the store all right so instead of putting it over here I am gonna you know make the slide copy this remove this and you know store okay so here as soon as the mongodb is connected we will basically store the information so URI so I'm gonna you know write const URI okay so URI will be the UR right that you will see over here so I'm gonna pause the video all right I don't think I I will just change the password okay so I will just you know quickly get the password or URI connection okay so I have it and I will store it over here don't worry I'm Gonna Change the password so you guys cannot use this so all in all you know it just goes into dust you can change it off according to how you need it so uh there are already a lot of stuff I was just testing out some stuff so once it's connected you know it will do the store and let's write you know console.log hello connected mongodb okay so I'm gonna write npm and node index.js remember we will not be using uh yeah there you go so it's connected to mongodb and it did not throw any error that means it did can connect a store connection let's try to write console.log store over here to see what is the uh you know so if you see there are a lot of stuff that's connected over here ideally you know we just it's just uh way of storing there it has the you know this library has like inputs of you know saving where it basically you know Zips the file and stores the file and it extracts and deletes and delete previous all of those things will happen so nonetheless let's move forward so now we have uh you know access to the store now what we will do is that instead of using client instead of using local art we will be using remote auth which will be imported from here from WhatsApp web.js and WhatsApp web.js remote auth will uh you know ask us to uh include the client ID which is all which is which is what it expects and it needs a store and I'll just pass in the store that I have created over here okay once that is done and uh you know you can also write client Dot on remote session save this will tell you that you know the remote session has been saved remote session save it will not return you anything so you can just you know just no no that in a remote session has been saved so you don't have to do a lot of stuff over here so after doing that you know uh you are required to yeah that's it I think if you have already watched the previous video you can store the session and you know if you want to revive the same session again all you have to do is pass the same client ID and it will automatically use your mongodb connection and drive the same old session so for that I will create a new function called get what WhatsApp session where I will do this and I will take an ID and I will basically store copy and paste this yeah and the ID will be coming from here and you know client dot on ready you know yeah and I will write client is ready client is ready and I will just io.mit IO let me just copy and paste the same thing over here okay socket.mit it needs a socket as well again socket automate ready and ID message client is ready or you know if we receive client.r authenticate or not authenticated but you know QR code which tells that the the user has to you know logged out then you know this information will be helpful for us socket.mit and message user got logged out user user God logged out and here is the QR code all right so maybe this will happen and then now we will just basically uh do socket dot on revive session or get session and you know get the ID and just paste this so it will automatically do a lot of stuff for us and uh I think we are pretty much solid all we need to do is just go to app.js or the file that is over here and then we need to have a button which will get old session and yeah so now I need to basically create a new state with old session ID set old session ID you state and we will just basically create a input um something like this if we type of text and it will have on change set on change and there you go all of these things will be sorted so we'll have like on click of get all session and it will just work smoothly okay now here I need to add the socket.mit get session I need to pass in the old session ID which will be received by the backend and we will restructure the ID and we'll pass it over here and then at voila it should automatically work but for now let's go back to this page do not care about old session but let's create a new session let's call this session yeah uh maybe okay before I do that I am also once I get you know report auth connection uh I remember writing somewhere okay I will also you know socket.mit remote session saved yeah there you go so that you know the front-end position and the remote session has been saved so write saf testing or Muhammad on testing that's right create session oops the server is not running I'm really sorry uh I believe it's over here okay node index.js hello mongodb connected but this seems to be some error let's restart and check I think it's connected very cool so now all I need to do is just write create session and uh I think we got a response and oops let's restart the server and check what's wrong okay so so okay there's one more thing that we need to do I totally forgot about it so in remote auth request you go to the documentation we basically are required to pass in more stuff like you know backup sync as well not only that and also the way that I need to implement it is like quite different so let me just go over here or strategy remote auth and I need to pass in the store and backup sync this one so that it will get us all of the stuff that we need okay so now I think we are sorted and now I'm gonna write index.js hopefully this time it will work okay so now let me reload Mohammad Khan testing create session [Music] it automatically opened up your WhatsApp and QR code has been received let me open up my WhatsApp and let me just quickly you know go to link devices scan my WhatsApp okay I've just scanned it now let's see what's happening on the back end on my WhatsApp it's saying it's logging in let's see how the backend response the client is ready and yeah the client is ready so it's saying that it's syncing Keep app open but the client is ready over here and you can see that it has been logged in into my WhatsApp and hopefully if I do get all chats it will get me a lot of stuff which is all of the chats of the user there you go so I I guess we are pretty much sorted about it and yeah so all we need to do is just revive the session again so for that I am gonna stop my server so remember I gave the name as well testing okay so I'm gonna reload the page I'm gonna paste it over here and I am gonna start the server again remember your WhatsApp needs to still be connected you cannot remove the connection if you remove the connection it will not be connected so what we'll do is that we will just basically create get old fashion uh for that I need to start the server okay yeah it needs to get the old session and uh let's see how it spawns let's see if it can actually do what it needs to do but I can see that it did not start the server because I did not write line dot initialize if you forgot line dot initialize it will not initialize and it will not start this uh browser if the browser is not yet started your your whole code will not work so if you see the documentation or maybe you know look at the code of initialize uh in the in this Library you will see that you know they initialize does a lot of stuff including opening up the browser so I wouldn't recommend you can write a weight over here but I don't think it's not it really does not make any difference so I believe I have restarted the server yes indeed and I'm gonna reload and I'm gonna paste it over here and press get old session now is the Moment of Truth where it did not get me the stuff that I needed okay so let me just stop and let's wait for it to say mongodb is connected and actually you know what I forgot to tell you that I have we have to basically make sure that this remote session save was done if this was not done then if you can see over here if you can basically search in the database if you see there is no um the connection that we want to do you see anywhere no right so that means the that was not yet done so for that what we will do is that basically go back to the documentation and uh I mean I we don't have to do anything else over here up like you know we don't have to write any extra code we just we'll just you know start this session again the reason being um we did not wait for the session to uh you know store it in the database so we'll do that now don't worry about it so let me just quickly open up the session again paste it over here create session okay so like you see over here you will see a new QR code let me just sign in okay it is signing in and about it's taking unusual amount of time and uh I think it's saying that it's ready and we need to wait for remote session saved let's wait for that to happen it will throw in a if if that does not happen and you can definitely check this out you can start reloading this and actually you can search for Muhammad Khan and wait until it basically stores the data and let's wait for it so if you see over here we got a response that remote session has been saved and if I reload the database I can see two files which is Chunks and which is the files so this has a tank size basically it it will just convert the data into binary data and store it in different different chunks ideally it's like 23 90 30 or it's just arbitrary value depending upon the data that WhatsApp stores on your account and uh you know this is this is like some information over here ideally behind the scenes the library would basically unzip your file and store it in the database and then let me just stop the server and let's see what's gonna happen if we start the server back again and I'm gonna reload I'm gonna paste over here I'm gonna wait for uh this mongodb to get connected okay I reckon it did now I'm gonna press get old session and now we wait for it to make the magic happen so if you see WhatsApp is loading so what happens behind the scenes is that the library would basically insert the application storage the browser storage insert all of the stuff that is required in the application store in browser storage and then at voila it basically gets everything that you want now if I press get all chats it should basically get me all of the chats I think so I'm not sure yeah but yeah I think getcharge is not defined so that is the reason it's just yeah broke over here but but I think you understand what I mean ideally you can add more functions over here and you can get everything that you want yeah so if you have any doubts please reach out to me and if please consider joining my community on NAS dot IO programmers Community you I have a full fully Flats course on WhatsApp web.js I also teach how to make different boards or everything and a price of just four dollars if you want to Discount just use the save save code discount I'll put it in the description you can check the discount code you can book a session with me you can do whatever you want please consider joining and thank you for watching goodbye and take care
Info
Channel: Mohammed Khan
Views: 8,629
Rating: undefined out of 5
Keywords: whatsapp web js tutorial, whatsapp web js session, whatsapp web js bot, whatsapp-web.js node, remote authentication whatsapp web js, whatsapp web js remote auth, whatsapp web js multi device, whatsapp-web.js deploy, whatsapp-web.is 2022
Id: rCJ82-MJKs8
Channel Id: undefined
Length: 22min 45sec (1365 seconds)
Published: Sun Apr 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.