[repo] desacoplamento e maior coesão
This commit is contained in:
28
src/client/whatsappClient.js
Normal file
28
src/client/whatsappClient.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import pkg from "whatsapp-web.js";
|
||||
import qrcode from "qrcode-terminal";
|
||||
import { exec } from "child_process";
|
||||
import { CLIENT_ID } from "../config.js";
|
||||
|
||||
export const { Client, LocalAuth, MessageMedia } = pkg;
|
||||
|
||||
export const client = new Client({
|
||||
authStrategy: new LocalAuth({ clientId: CLIENT_ID }),
|
||||
puppeteer: { headless: true }
|
||||
});
|
||||
|
||||
client.on("qr", qr => {
|
||||
console.log("[BOT] Escaneie o QR Code");
|
||||
qrcode.generate(qr, { small: true });
|
||||
});
|
||||
|
||||
client.on("ready", () => {
|
||||
exec("clear");
|
||||
console.log("[BOT] WhatsApp conectado.");
|
||||
});
|
||||
|
||||
client.on("disconnected", reason => {
|
||||
console.warn("[BOT] Reconectando:", reason);
|
||||
setTimeout(() => client.initialize(), 5000);
|
||||
});
|
||||
|
||||
export default client;
|
||||
Reference in New Issue
Block a user