-
Notifications
You must be signed in to change notification settings - Fork 0
/
botWhatsApp.js
91 lines (84 loc) · 3.18 KB
/
botWhatsApp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const {
default: makeWASocket,
DisconnectReason,
useMultiFileAuthState
} = require('@adiwajshing/baileys');
const P = require('pino');
async function run() {
console.log('starting')
const { state, saveCreds } = await useMultiFileAuthState("baileys_auth_info");
const sock = await makeWASocket({
printQRInTerminal: true,
logger: P({level: 'silent'}),
auth: state
});
sock.ev.on('connection.update', update => {
const { connection, lastDisconnect} = update;
if(connection === 'close') {
if(lastDisconnect.error.hasOwnProperty('output') ? lastDisconnect.error.output.statusCode !== DisconnectReason.loggedOut : true) {
console.log("Connection error, reconnecting...");
run();
} else if(lastDisconnect.error.output.statusCode === DisconnectReason.loggedOut) {
console.log("Desconnected, reconnecting tryed...");
run();
};
} else if(connection === 'open') {
console.log("Connected succesfully to WhatsApp.");
};
});
sock.ev.on('creds.update', saveCreds);
const chatIds = [
];
setInterval(async () => {
// Creamos un bucle para enviar mensajes a cada grupo en el intervalo de 1 minuto
for (const chatId of chatIds) {
const message = { text: '🇺🇸🇨🇺 OFERTA DE REMESAS Y COMBOS DE COMIDAS 🇺🇸🇨🇺\n\n➡️ 100 USD 🇺🇲 - 14 500 CUP 🇨🇺\n➡️ 112 USD 🇺🇸 - 100 USD/MLC 🇨🇺\n\n‼️ PARA SABER LAS OFERTAS DE LOS COMBOS DE COMIDA PASE AL PV ‼️\n\nCOMPRO DIVISAS\nMLC A 150\nUSD A 150\nEUROS A 155\n\nLink de grupo de WhatsApp: https://chat.whatsapp.com/L1frnLZTSykG2JTqZnnVk9\n\nTRATO PRECENCIAL en toda la Isla de la juventud' };
const options = {};
await sock.sendMessage(chatId, message, options);
console.log(`Mensaje enviado a ${chatId}`);
// Esperamos 1 minuto antes de enviar el siguiente mensaje
await new Promise(resolve => setTimeout(resolve, 60000));
}
}, 480000);
}
run();