You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const{
makeWASocket,
makeCacheableSignalKeyStore,
isJidBroadcast,
fetchLatestBaileysVersion,
DisconnectReason
}=require('@whiskeysockets/Baileys')const{ useMySQLAuthState }=require('auth-mysql')constpino=require('pino')constlogger=pino({level: 40})asyncfunctionstartSock(sessionName){const{ version, error, isLatest }=awaitfetchLatestBaileysVersion()//This is important, so as not to try to create a MySQL connection with unstable internet or without internet, otherwise it gives the error: "Many connections"if(error||!isLatest){connectToWhatsApp(sessionName)return}const{ state, saveCreds, removeCreds }=awaituseMySQLAuthState({session: sessionName||'1',host: 'localhost',user: 'root',password: 'Password123#',database: 'auth'})constsock=makeWASocket({auth: {creds: state.creds,keys: makeCacheableSignalKeyStore(state.keys,logger),},browser: ['Windows','DESKTOP','2.2344.5.0'],version: version,qrTimeout: 45_000,defaultQueryTimeoutMs: undefined,// importantmarkOnlineOnConnect: true,logger: logger,shouldIgnoreJid: (jid)=>{return!jid||isJidBroadcast(jid)}})sock.ev.on('creds.update',saveCreds)sock.ev.on('connection.update',async({ connection, lastDisconnect })=>{conststatus=lastDisconnect?.error?.output?.statusCodeif(connection==='close'){constreason=Object.entries(DisconnectReason).find(i=>i[1]===status)?.[0]||'unknown'console.log(`Closed connection, status: ${reason} (${status})`)if(status===403||status===401){sock=nullremoveCreds()}else{startSock(session)}}elseif(connection==='open'){console.log(`WhatsApp on-line!`)}})sock.ev.on('messages.upsert',async({ messages, type })=>{// your code here})}startSock('session1')
If you want to start other sessions in the same code, use this: