| import makeWASocket, { |
| useMultiFileAuthState, |
| DisconnectReason, |
| fetchLatestBaileysVersion, |
| makeCacheableSignalKeyStore |
| } from "@whiskeysockets/baileys"; |
| import pino from "pino"; |
| import fs from "fs"; |
| import readline from "readline"; |
|
|
| const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); |
| const question = (text) => new Promise((resolve) => rl.question(text, resolve)); |
|
|
| async function startAsura() { |
| |
| const { state, saveCreds } = await useMultiFileAuthState('session'); |
| const { version } = await fetchLatestBaileysVersion(); |
|
|
| const sock = makeWASocket({ |
| version, |
| auth: { |
| creds: state.creds, |
| keys: makeCacheableSignalKeyStore(state.keys, pino({ level: "silent" })), |
| }, |
| printQRInTerminal: false, |
| logger: pino({ level: "silent" }), |
| browser: ["Ubuntu", "Chrome", "20.0.04"] |
| }); |
|
|
| |
| if (!sock.authState.creds.registered) { |
| const phoneNumber = await question('\nEnter your Phone Number with Country Code (eg: 91xxxx): '); |
| await delay(3000); |
| const code = await sock.requestPairingCode(phoneNumber.replace(/[^0-9]/g, '')); |
| console.log(`\x1b[32m\nYOUR PAIRING CODE: \x1b[1m${code}\x1b[0m\n`); |
| } |
|
|
| sock.ev.on('creds.update', saveCreds); |
|
|
| sock.ev.on('connection.update', async (update) => { |
| const { connection, lastDisconnect } = update; |
|
|
| if (connection === 'close') { |
| const shouldReconnect = lastDisconnect.error?.output?.statusCode !== DisconnectReason.loggedOut; |
| if (shouldReconnect) startAsura(); |
| } else if (connection === 'open') { |
| console.log('\x1b[36m✅ Asura MD Connected!\x1b[0m'); |
|
|
| |
| console.log('\x1b[33m⚡ waite 5 hours /session folder.\x1b[0m'); |
|
|
| const myNumber = sock.user.id.split(':')[0] + "@s.whatsapp.net"; |
| await sock.sendMessage(myNumber, { text: "Asura MD connected and creds.json created! 👺" }); |
| } |
| }); |
| } |
|
|
| |
| function delay(ms) { |
| return new Promise(resolve => setTimeout(resolve, ms)); |
| } |
|
|
| startAsura(); |