If you want with your specifications, if you don't create it, the code will automatically create
CREATE TABLE `auth` (
`session` varchar(50) NOT NULL,
`id` varchar(100) NOT NULL,
`value` json DEFAULT NULL,
UNIQUE KEY `idxunique` (`session`,`id`),
KEY `idxsession` (`session`),
KEY `idxid` (`id`)
) ENGINE=MyISAM
Edge version:
npm i github:bobslavtriev/mysql-baileys
const { useMySQLAuthState } = require('mysql-baileys')
const { state, saveCreds, removeCreds } = await useMySQLAuthState({
session: sessionName, // required
host: 'localhost', // optional
user: 'root', // optional
password: 'Password123#', // required
database: 'baileys' // required
})
const { makeWASocket, makeCacheableSignalKeyStore, fetchLatestBaileysVersion } = require('@whiskeysockets/Baileys')
const { useMySQLAuthState } = require('mysql-baileys')
async function startSock(sessionName){
const { error, version } = await fetchLatestBaileysVersion()
if (error){
console.log(`Session: ${sessionName} | No connection, check your internet.`)
return startSock(sessionName)
}
const { state, saveCreds, removeCreds } = await useMySQLAuthState({
session: sessionName, // required
host: 'localhost', // optional
user: 'root', // optional
password: 'Password123#', // required
database: 'baileys' // required
})
const sock = makeWASocket({
auth: {
creds: state.creds,
keys: makeCacheableSignalKeyStore(state.keys, logger),
},
version: version,
defaultQueryTimeoutMs: undefined
})
sock.ev.on('creds.update', saveCreds)
sock.ev.on('connection.update', async({ connection, lastDisconnect }) => {
// your code here
})
sock.ev.on('messages.upsert', async({ messages, type }) => {
// your code here
})
}
startSock('session1')
startSock('session1')
startSock('session2')
startSock('session3')
startSock('session4')