-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugger.js
More file actions
125 lines (103 loc) · 5.44 KB
/
debugger.js
File metadata and controls
125 lines (103 loc) · 5.44 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const { Client, LocalAuth } = require('whatsapp-web.js');
const qrcode = require('qrcode-terminal');
// Inicializar Cliente
const client = new Client({
authStrategy: new LocalAuth(),
puppeteer: {
headless: true,
args: ['--no-sandbox', '--disable-setuid-sandbox']
}
});
client.on('qr', (qr) => qrcode.generate(qr, { small: true }));
client.on('ready', () => console.log('🔍 Bot de Debugging Listo.'));
client.on('message_create', async (msg) => {
// Evitar bucles infinitos: no responder a nuestros propios reportes de debug
if (msg.body.startsWith('🔍 *REPORTE DE DEBUG*')) return;
console.log("📨 Mensaje recibido. Generando reporte...");
try {
let output = `🔍 *REPORTE DE DEBUG* 🔍\n\n`;
// ---------------------------------------------------------
// 1. INTENTOS DE OBTENER EL NÚMERO (IDENTIFICACIÓN)
// ---------------------------------------------------------
output += `🆔 *IDENTIFICACIÓN DEL REMITENTE*\n`;
// Método A: Propiedades Directas Standard
output += `🔹 msg.from: \`${msg.from}\`\n`;
output += `🔹 msg.author: \`${msg.author || 'undefined'}\`\n`;
// Método B: Propiedad ID anidada
output += `🔹 msg.id.participant: \`${msg.id.participant || 'undefined'}\`\n`;
output += `🔹 msg.id.remote: \`${msg.id.remote}\`\n`;
// Método C: Data Cruda (_data) - A veces tiene datos que la librería no expone
const raw = msg._data || {};
output += `🔹 msg._data.from: \`${raw.from || 'undef'}\`\n`;
output += `🔹 msg._data.author: \`${raw.author || 'undef'}\`\n`;
output += `🔹 msg._data.participant: \`${raw.participant || 'undef'}\`\n`;
if (raw.id) {
output += `🔹 msg._data.id.participant: \`${raw.id.participant || 'undef'}\`\n`;
}
// Método D: Inyección en el Navegador (Lo más avanzado para resolver LIDs)
let navegadorData = "Error";
try {
// Obtenemos el ID que creemos que es el emisor (author si es grupo, from si es privado)
const targetId = msg.author || msg.from;
navegadorData = await client.pupPage.evaluate((targetId) => {
try {
const wid = window.Store.WidFactory.createWid(targetId);
const info = {};
// 1. Intentar resolver LID a Telefono
if (window.Store.LidUtils && window.Store.LidUtils.getPhoneNumber) {
const pn = window.Store.LidUtils.getPhoneNumber(wid);
if (pn) info.mappedPhoneNumber = pn._serialized;
}
// 2. Buscar en el Store de Contactos
const contact = window.Store.Contact.get(wid);
if (contact) {
info.pushname = contact.pushname;
info.isMyContact = contact.isMyContact;
info.isUser = contact.isUser;
info.phoneNumber = contact.phoneNumber; // A veces está aquí
}
return JSON.stringify(info);
} catch(e) { return "Error en browser: " + e.message; }
}, targetId);
} catch (e) { navegadorData = "Fallo Puppeteer: " + e.message; }
output += `🔹 *Browser Store Lookup:* \`\`\`${navegadorData}\`\`\`\n`;
// Método E: Función getContact() (Suele fallar, la probamos igual)
try {
const contact = await msg.getContact();
output += `🔹 msg.getContact(): Nro: \`${contact.number}\` | Name: \`${contact.name}\` | Push: \`${contact.pushname}\`\n`;
} catch (e) {
output += `🔹 msg.getContact(): ❌ FALLÓ (${e.message})\n`;
}
// ---------------------------------------------------------
// 2. CONTEXTO DEL CHAT
// ---------------------------------------------------------
output += `\n🏠 *CONTEXTO DEL CHAT*\n`;
const chat = await msg.getChat();
output += `🔸 Es Grupo: ${chat.isGroup ? 'SÍ' : 'NO'}\n`;
output += `🔸 Nombre Chat: ${chat.name}\n`;
output += `🔸 Chat ID: \`${chat.id._serialized}\`\n`;
if (chat.isGroup) {
// Buscar al emisor en la lista de participantes
const idBusqueda = msg.author || msg.from;
const participante = chat.participants.find(p => p.id._serialized === idBusqueda);
if (participante) {
output += `🔸 Info Participante en Grupo: Admin? ${participante.isAdmin} | SuperAdmin? ${participante.isSuperAdmin}\n`;
} else {
output += `🔸 ⚠️ El emisor NO aparece en la lista de participantes del objeto Chat (¿Bug de LIDs?)\n`;
}
}
// ---------------------------------------------------------
// 3. DATOS DEL CLIENTE (Tú)
// ---------------------------------------------------------
output += `\n🤖 *INFO DEL CLIENTE (BOT)*\n`;
output += `▫️ Mi ID: \`${client.info.wid._serialized}\`\n`;
output += `▫️ Mi Nombre: ${client.info.pushname}\n`;
output += `▫️ Plataforma: ${client.info.platform}\n`;
// Enviar respuesta
await msg.reply(output);
} catch (error) {
console.error("Error fatal en debug:", error);
await msg.reply(`⚠️ Error fatal generando reporte: ${error.message}`);
}
});
client.initialize();