@arcaelas/whatsapp 1.0.21 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +776 -0
- package/DOC.md +532 -0
- package/build/Chat.d.ts +335 -0
- package/build/Chat.js +396 -0
- package/build/Chat.js.map +1 -0
- package/build/Contact.d.ts +828 -0
- package/build/Contact.js +188 -0
- package/build/Contact.js.map +1 -0
- package/build/Message.d.ts +525 -0
- package/build/Message.js +445 -0
- package/build/Message.js.map +1 -0
- package/build/WhatsApp.d.ts +68 -0
- package/build/WhatsApp.js +399 -0
- package/build/WhatsApp.js.map +1 -0
- package/build/index.d.ts +11 -107
- package/build/index.js +1 -1
- package/build/index.js.map +3 -3
- package/build/store/driver/FileEngine.d.ts +23 -0
- package/build/store/driver/FileEngine.js +90 -0
- package/build/store/driver/FileEngine.js.map +1 -0
- package/build/store/driver/RedisEngine.d.ts +38 -0
- package/build/store/driver/RedisEngine.js +69 -0
- package/build/store/driver/RedisEngine.js.map +1 -0
- package/build/store/engine.d.ts +54 -0
- package/build/store/engine.js +7 -0
- package/build/store/engine.js.map +1 -0
- package/build/store/index.d.ts +8 -0
- package/build/store/index.js +12 -0
- package/build/store/index.js.map +1 -0
- package/context7.json +4 -0
- package/package.json +59 -52
- package/tsconfig.json +25 -25
- package/build/model/base.d.ts +0 -28
- package/build/model/base.js +0 -65
- package/build/model/base.js.map +0 -1
- package/build/model/chat.d.ts +0 -112
- package/build/model/chat.js +0 -105
- package/build/model/chat.js.map +0 -1
- package/build/model/contact.d.ts +0 -16
- package/build/model/contact.js +0 -22
- package/build/model/contact.js.map +0 -1
- package/build/model/message.d.ts +0 -159
- package/build/model/message.js +0 -206
- package/build/model/message.js.map +0 -1
- package/build/static/Store.d.ts +0 -137
- package/build/static/Store.js +0 -238
- package/build/static/Store.js.map +0 -1
- package/build/static/useCache.d.ts +0 -12
- package/build/static/useCache.js +0 -43
- package/build/static/useCache.js.map +0 -1
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file WhatsApp.ts
|
|
4
|
+
* @description Clase principal que gestiona la conexión y eventos de WhatsApp
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
40
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
41
|
+
};
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.WhatsApp = void 0;
|
|
44
|
+
const baileys_1 = require("baileys");
|
|
45
|
+
const node_events_1 = require("node:events");
|
|
46
|
+
const pino_1 = __importDefault(require("pino"));
|
|
47
|
+
const QRCode = __importStar(require("qrcode"));
|
|
48
|
+
const Chat_1 = require("./Chat");
|
|
49
|
+
const Contact_1 = require("./Contact");
|
|
50
|
+
const Message_1 = require("./Message");
|
|
51
|
+
const store_1 = require("./store");
|
|
52
|
+
/**
|
|
53
|
+
* @description
|
|
54
|
+
* Clase principal para gestionar la conexión con WhatsApp.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* const { event, pair, Contact, Chat, Message } = new WhatsApp({ phone: '5491112345678' });
|
|
58
|
+
* event.on('open', () => console.log('Conectado'));
|
|
59
|
+
* await pair((code) => console.log('Código:', code));
|
|
60
|
+
*/
|
|
61
|
+
class WhatsApp {
|
|
62
|
+
constructor(options = {}) {
|
|
63
|
+
this._socket = null;
|
|
64
|
+
/**
|
|
65
|
+
* @description Conecta a WhatsApp.
|
|
66
|
+
* - Con phone: callback recibe código de 8 dígitos (una vez)
|
|
67
|
+
* - Sin phone: callback recibe QR como Buffer PNG (periódicamente)
|
|
68
|
+
* @param callback Función que recibe el código o QR.
|
|
69
|
+
*/
|
|
70
|
+
this.pair = async (callback) => {
|
|
71
|
+
const { version } = await (0, baileys_1.fetchLatestBaileysVersion)();
|
|
72
|
+
const stored = await this.engine.get('session/creds');
|
|
73
|
+
const creds = stored ? JSON.parse(stored, baileys_1.BufferJSON.reviver) : (0, baileys_1.initAuthCreds)();
|
|
74
|
+
let code_sent = false;
|
|
75
|
+
const connect = async () => {
|
|
76
|
+
this._socket = (0, baileys_1.makeWASocket)({
|
|
77
|
+
version,
|
|
78
|
+
auth: {
|
|
79
|
+
creds,
|
|
80
|
+
keys: {
|
|
81
|
+
get: async (type, ids) => {
|
|
82
|
+
const data = {};
|
|
83
|
+
for (const id of ids) {
|
|
84
|
+
const stored = await this.engine.get(`session/${type}/${id}`);
|
|
85
|
+
if (stored) {
|
|
86
|
+
let value = JSON.parse(stored, baileys_1.BufferJSON.reviver);
|
|
87
|
+
if (type === 'app-state-sync-key')
|
|
88
|
+
value = baileys_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
89
|
+
data[id] = value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return data;
|
|
93
|
+
},
|
|
94
|
+
set: async (data) => {
|
|
95
|
+
for (const category in data) {
|
|
96
|
+
for (const id in data[category]) {
|
|
97
|
+
const value = data[category][id];
|
|
98
|
+
await this.engine.set(`session/${category}/${id}`, value ? JSON.stringify(value, baileys_1.BufferJSON.replacer) : null);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
browser: baileys_1.Browsers.windows('Chrome'),
|
|
105
|
+
printQRInTerminal: false,
|
|
106
|
+
logger: (0, pino_1.default)({ level: 'silent' }),
|
|
107
|
+
syncFullHistory: false,
|
|
108
|
+
markOnlineOnConnect: false,
|
|
109
|
+
});
|
|
110
|
+
const socket = this._socket;
|
|
111
|
+
socket.ev.on('creds.update', () => this.engine.set('session/creds', JSON.stringify(creds, baileys_1.BufferJSON.replacer)));
|
|
112
|
+
socket.ev.on('connection.update', async (update) => {
|
|
113
|
+
const { connection, lastDisconnect, qr } = update;
|
|
114
|
+
if (qr && !creds.registered) {
|
|
115
|
+
if (this._phone && !code_sent) {
|
|
116
|
+
code_sent = true;
|
|
117
|
+
await callback(await socket.requestPairingCode(this._phone));
|
|
118
|
+
}
|
|
119
|
+
else if (!this._phone) {
|
|
120
|
+
await callback(await QRCode.toBuffer(qr, { type: 'png', margin: 2 }));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (connection === 'open') {
|
|
124
|
+
this.event.emit('open');
|
|
125
|
+
}
|
|
126
|
+
else if (connection === 'close') {
|
|
127
|
+
this._socket = null;
|
|
128
|
+
if (lastDisconnect?.error?.output?.statusCode === baileys_1.DisconnectReason.loggedOut) {
|
|
129
|
+
this.event.emit('error', new Error('Logged out'));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
this.event.emit('close');
|
|
133
|
+
setTimeout(connect, 3000);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
137
|
+
// CONTACTS
|
|
138
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
139
|
+
socket.ev.on('contacts.upsert', async (contacts) => {
|
|
140
|
+
for (const c of contacts) {
|
|
141
|
+
if (!c.id)
|
|
142
|
+
continue;
|
|
143
|
+
const existing = await this.engine.get(`contact/${c.id}/index`);
|
|
144
|
+
const raw = {
|
|
145
|
+
id: c.id,
|
|
146
|
+
lid: c.lid ?? null,
|
|
147
|
+
name: c.name ?? null,
|
|
148
|
+
notify: c.notify ?? null,
|
|
149
|
+
verifiedName: c.verifiedName ?? null,
|
|
150
|
+
imgUrl: c.imgUrl ?? null,
|
|
151
|
+
status: c.status ?? null,
|
|
152
|
+
};
|
|
153
|
+
const data = (0, Contact_1.build_contact)(raw);
|
|
154
|
+
await this.engine.set(`contact/${c.id}/index`, JSON.stringify(data, baileys_1.BufferJSON.replacer));
|
|
155
|
+
this.event.emit(existing ? 'contact:updated' : 'contact:created', new this.Contact(data));
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
socket.ev.on('contacts.update', async (contacts) => {
|
|
159
|
+
for (const c of contacts) {
|
|
160
|
+
if (!c.id)
|
|
161
|
+
continue;
|
|
162
|
+
const stored = await this.engine.get(`contact/${c.id}/index`);
|
|
163
|
+
if (!stored)
|
|
164
|
+
continue;
|
|
165
|
+
const data = JSON.parse(stored, baileys_1.BufferJSON.reviver);
|
|
166
|
+
c.notify && (data.raw.notify = c.notify);
|
|
167
|
+
c.name && (data.raw.name = c.name);
|
|
168
|
+
c.imgUrl && (data.raw.imgUrl = c.imgUrl);
|
|
169
|
+
c.status && (data.raw.status = c.status);
|
|
170
|
+
data.name = data.raw.name ?? data.raw.notify ?? data.raw.id.split('@')[0];
|
|
171
|
+
data.photo = data.raw.imgUrl ?? null;
|
|
172
|
+
data.content = data.raw.status ?? '';
|
|
173
|
+
await this.engine.set(`contact/${c.id}/index`, JSON.stringify(data, baileys_1.BufferJSON.replacer));
|
|
174
|
+
this.event.emit('contact:updated', new this.Contact(data));
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
178
|
+
// CHATS
|
|
179
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
180
|
+
socket.ev.on('chats.upsert', async (chats) => {
|
|
181
|
+
for (const ch of chats) {
|
|
182
|
+
const existing = await this.engine.get(`chat/${ch.id}/index`);
|
|
183
|
+
const raw = existing
|
|
184
|
+
? JSON.parse(existing, baileys_1.BufferJSON.reviver).raw
|
|
185
|
+
: {
|
|
186
|
+
id: ch.id,
|
|
187
|
+
name: ch.name ?? null,
|
|
188
|
+
archived: ch.archived ?? null,
|
|
189
|
+
pinned: ch.pinned ?? null,
|
|
190
|
+
muteEndTime: ch.muteEndTime ?? null,
|
|
191
|
+
unreadCount: ch.unreadCount ?? null,
|
|
192
|
+
readOnly: ch.readOnly ?? null,
|
|
193
|
+
};
|
|
194
|
+
if (ch.name)
|
|
195
|
+
raw.name = ch.name;
|
|
196
|
+
const data = (0, Chat_1.build_chat)(raw);
|
|
197
|
+
await this.engine.set(`chat/${ch.id}/index`, JSON.stringify(data, baileys_1.BufferJSON.replacer));
|
|
198
|
+
this.event.emit(existing ? 'chat:updated' : 'chat:created', new this.Chat(data));
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
socket.ev.on('chats.update', async (chats) => {
|
|
202
|
+
for (const ch of chats) {
|
|
203
|
+
if (!ch.id)
|
|
204
|
+
continue;
|
|
205
|
+
const stored = await this.engine.get(`chat/${ch.id}/index`);
|
|
206
|
+
const data = stored ? JSON.parse(stored, baileys_1.BufferJSON.reviver) : (0, Chat_1.build_chat)({ id: ch.id, name: ch.name ?? null });
|
|
207
|
+
if (ch.name !== undefined) {
|
|
208
|
+
data.raw.name = ch.name ?? data.raw.name;
|
|
209
|
+
data.name = data.raw.name ?? data.raw.displayName ?? ch.id.split('@')[0];
|
|
210
|
+
}
|
|
211
|
+
let has_specific_event = false;
|
|
212
|
+
// Pin
|
|
213
|
+
if ('pinned' in ch) {
|
|
214
|
+
data.raw.pinned = ch.pinned ?? null;
|
|
215
|
+
data.pined = data.raw.pinned !== null;
|
|
216
|
+
this.event.emit('chat:pined', ch.id, data.raw.pinned);
|
|
217
|
+
has_specific_event = true;
|
|
218
|
+
}
|
|
219
|
+
// Archive
|
|
220
|
+
if (ch.archived !== undefined) {
|
|
221
|
+
data.raw.archived = ch.archived ?? false;
|
|
222
|
+
data.archived = data.raw.archived;
|
|
223
|
+
this.event.emit('chat:archived', ch.id, data.archived);
|
|
224
|
+
has_specific_event = true;
|
|
225
|
+
}
|
|
226
|
+
// Mute
|
|
227
|
+
if ('muteEndTime' in ch) {
|
|
228
|
+
data.raw.muteEndTime = ch.muteEndTime ?? null;
|
|
229
|
+
data.muted = data.raw.muteEndTime ?? false;
|
|
230
|
+
this.event.emit('chat:muted', ch.id, data.raw.muteEndTime);
|
|
231
|
+
has_specific_event = true;
|
|
232
|
+
}
|
|
233
|
+
// UnreadCount
|
|
234
|
+
if (ch.unreadCount !== undefined) {
|
|
235
|
+
data.raw.unreadCount = ch.unreadCount;
|
|
236
|
+
data.readed = (data.raw.unreadCount === 0 || data.raw.unreadCount === null) && !data.raw.markedAsUnread;
|
|
237
|
+
}
|
|
238
|
+
await this.engine.set(`chat/${ch.id}/index`, JSON.stringify(data, baileys_1.BufferJSON.replacer));
|
|
239
|
+
if (!has_specific_event) {
|
|
240
|
+
this.event.emit(stored ? 'chat:updated' : 'chat:created', new this.Chat(data));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
socket.ev.on('chats.delete', async (ids) => {
|
|
245
|
+
for (const cid of ids) {
|
|
246
|
+
await this.Chat.cascade_delete(cid);
|
|
247
|
+
this.event.emit('chat:deleted', cid);
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
251
|
+
// MESSAGES
|
|
252
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
253
|
+
socket.ev.on('messages.upsert', async ({ messages }) => {
|
|
254
|
+
for (const msg of messages) {
|
|
255
|
+
if (!msg.key.remoteJid || !msg.key.id)
|
|
256
|
+
continue;
|
|
257
|
+
const cid = msg.key.remoteJid;
|
|
258
|
+
const mid = msg.key.id;
|
|
259
|
+
const content_type = (0, baileys_1.getContentType)(msg.message ?? {});
|
|
260
|
+
// Ignorar reacciones y votos de encuesta (tienen sus propios eventos)
|
|
261
|
+
if (content_type === 'reactionMessage' || content_type === 'pollUpdateMessage')
|
|
262
|
+
continue;
|
|
263
|
+
// ─────────────────────────────────────────────────────────────
|
|
264
|
+
// PROTOCOL MESSAGE (ediciones y eliminaciones)
|
|
265
|
+
// ─────────────────────────────────────────────────────────────
|
|
266
|
+
if (content_type === 'protocolMessage') {
|
|
267
|
+
const protocol = msg.message?.protocolMessage;
|
|
268
|
+
if (!protocol?.key?.id)
|
|
269
|
+
continue;
|
|
270
|
+
const target_mid = protocol.key.id;
|
|
271
|
+
const target_cid = protocol.key.remoteJid ?? cid;
|
|
272
|
+
// MESSAGE_EDIT: Merge selectivo - reemplazar solo message
|
|
273
|
+
if (protocol.type === baileys_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT) {
|
|
274
|
+
const edited_msg = protocol.editedMessage;
|
|
275
|
+
if (!edited_msg)
|
|
276
|
+
continue;
|
|
277
|
+
// Obtener index y raw
|
|
278
|
+
const stored_index = await this.engine.get(`chat/${target_cid}/message/${target_mid}/index`);
|
|
279
|
+
const stored_raw = await this.engine.get(`chat/${target_cid}/message/${target_mid}/raw`);
|
|
280
|
+
if (!stored_index || !stored_raw)
|
|
281
|
+
continue;
|
|
282
|
+
const index = JSON.parse(stored_index, baileys_1.BufferJSON.reviver);
|
|
283
|
+
const raw = JSON.parse(stored_raw, baileys_1.BufferJSON.reviver);
|
|
284
|
+
raw.message = edited_msg;
|
|
285
|
+
index.edited = true;
|
|
286
|
+
index.caption = (0, Message_1.build_message_index)(raw).caption;
|
|
287
|
+
await this.engine.set(`chat/${target_cid}/message/${target_mid}/index`, JSON.stringify(index, baileys_1.BufferJSON.replacer));
|
|
288
|
+
await this.engine.set(`chat/${target_cid}/message/${target_mid}/raw`, JSON.stringify(raw, baileys_1.BufferJSON.replacer));
|
|
289
|
+
const instance = new this.Message({ index, raw });
|
|
290
|
+
this.Message.notify(target_cid, target_mid);
|
|
291
|
+
this.event.emit('message:updated', instance);
|
|
292
|
+
continue;
|
|
293
|
+
}
|
|
294
|
+
// REVOKE: Eliminar del engine
|
|
295
|
+
if (protocol.type === baileys_1.proto.Message.ProtocolMessage.Type.REVOKE) {
|
|
296
|
+
// Eliminar del índice del chat
|
|
297
|
+
await this.Chat.remove_message(target_cid, target_mid);
|
|
298
|
+
// Eliminar archivos
|
|
299
|
+
await this.engine.set(`chat/${target_cid}/message/${target_mid}/index`, null);
|
|
300
|
+
await this.engine.set(`chat/${target_cid}/message/${target_mid}/content`, null);
|
|
301
|
+
await this.engine.set(`chat/${target_cid}/message/${target_mid}/raw`, null);
|
|
302
|
+
this.event.emit('message:deleted', target_cid, target_mid);
|
|
303
|
+
}
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
// ─────────────────────────────────────────────────────────────
|
|
307
|
+
// MENSAJE NUEVO
|
|
308
|
+
// ─────────────────────────────────────────────────────────────
|
|
309
|
+
// Construir index desde raw y guardar
|
|
310
|
+
const index = (0, Message_1.build_message_index)(msg);
|
|
311
|
+
await this.engine.set(`chat/${cid}/message/${mid}/index`, JSON.stringify(index, baileys_1.BufferJSON.replacer));
|
|
312
|
+
await this.engine.set(`chat/${cid}/message/${mid}/raw`, JSON.stringify(msg, baileys_1.BufferJSON.replacer));
|
|
313
|
+
// Extraer content inline según tipo
|
|
314
|
+
let content = Buffer.alloc(0);
|
|
315
|
+
if (index.type === 'text') {
|
|
316
|
+
const raw_content = msg.message?.[content_type];
|
|
317
|
+
content = Buffer.from(typeof raw_content === 'string' ? raw_content : raw_content?.text ?? raw_content?.caption ?? '', 'utf-8');
|
|
318
|
+
}
|
|
319
|
+
else if (index.type === 'location') {
|
|
320
|
+
const loc = msg.message?.locationMessage ?? msg.message?.liveLocationMessage;
|
|
321
|
+
content = Buffer.from(JSON.stringify({ lat: loc?.degreesLatitude, lng: loc?.degreesLongitude }), 'utf-8');
|
|
322
|
+
}
|
|
323
|
+
else if (index.type === 'poll') {
|
|
324
|
+
const poll = msg.message?.pollCreationMessage ?? msg.message?.pollCreationMessageV2 ?? msg.message?.pollCreationMessageV3;
|
|
325
|
+
content = Buffer.from(JSON.stringify({ content: poll?.name ?? '', options: poll?.options?.map((o) => ({ content: o.optionName })) ?? [] }), 'utf-8');
|
|
326
|
+
}
|
|
327
|
+
else if (['image', 'video', 'audio'].includes(index.type) && this._socket) {
|
|
328
|
+
try {
|
|
329
|
+
const buffer = await (0, baileys_1.downloadMediaMessage)(msg, 'buffer', {});
|
|
330
|
+
if (Buffer.isBuffer(buffer))
|
|
331
|
+
content = buffer;
|
|
332
|
+
}
|
|
333
|
+
catch { }
|
|
334
|
+
}
|
|
335
|
+
if (content.length) {
|
|
336
|
+
await this.engine.set(`chat/${cid}/message/${mid}/content`, content.toString('base64'));
|
|
337
|
+
}
|
|
338
|
+
// Agregar al índice del chat y emitir
|
|
339
|
+
await this.Chat.add_message(cid, mid, index.created_at);
|
|
340
|
+
const instance = new this.Message({ index, raw: msg });
|
|
341
|
+
content.length && (instance.content = async () => content);
|
|
342
|
+
this.Message.notify(cid, mid);
|
|
343
|
+
this.event.emit('message:created', instance);
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
socket.ev.on('messages.update', async (updates) => {
|
|
347
|
+
for (const { key, update } of updates) {
|
|
348
|
+
if (!key.remoteJid || !key.id)
|
|
349
|
+
continue;
|
|
350
|
+
const stored_index = await this.engine.get(`chat/${key.remoteJid}/message/${key.id}/index`);
|
|
351
|
+
const stored_raw = await this.engine.get(`chat/${key.remoteJid}/message/${key.id}/raw`);
|
|
352
|
+
if (!stored_index)
|
|
353
|
+
continue;
|
|
354
|
+
const index = JSON.parse(stored_index, baileys_1.BufferJSON.reviver);
|
|
355
|
+
const raw = stored_raw ? JSON.parse(stored_raw, baileys_1.BufferJSON.reviver) : { key };
|
|
356
|
+
// Edición via messages.update
|
|
357
|
+
if (update.message?.editedMessage?.message) {
|
|
358
|
+
raw.message = update.message.editedMessage.message;
|
|
359
|
+
index.edited = true;
|
|
360
|
+
index.caption = (0, Message_1.build_message_index)(raw).caption;
|
|
361
|
+
await this.engine.set(`chat/${key.remoteJid}/message/${key.id}/index`, JSON.stringify(index, baileys_1.BufferJSON.replacer));
|
|
362
|
+
await this.engine.set(`chat/${key.remoteJid}/message/${key.id}/raw`, JSON.stringify(raw, baileys_1.BufferJSON.replacer));
|
|
363
|
+
const instance = new this.Message({ index, raw });
|
|
364
|
+
this.Message.notify(key.remoteJid, key.id);
|
|
365
|
+
this.event.emit('message:updated', instance);
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
// Status update
|
|
369
|
+
if (update.status !== undefined) {
|
|
370
|
+
raw.status = update.status;
|
|
371
|
+
index.status = raw.status;
|
|
372
|
+
await this.engine.set(`chat/${key.remoteJid}/message/${key.id}/index`, JSON.stringify(index, baileys_1.BufferJSON.replacer));
|
|
373
|
+
await this.engine.set(`chat/${key.remoteJid}/message/${key.id}/raw`, JSON.stringify(raw, baileys_1.BufferJSON.replacer));
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
socket.ev.on('messages.reaction', async (reactions) => {
|
|
378
|
+
for (const { key, reaction } of reactions) {
|
|
379
|
+
if (key.remoteJid && key.id)
|
|
380
|
+
this.event.emit('message:reacted', key.remoteJid, key.id, reaction.text ?? '');
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
};
|
|
384
|
+
await connect();
|
|
385
|
+
};
|
|
386
|
+
this._phone = options.phone?.toString();
|
|
387
|
+
this.engine = options.engine ?? new store_1.FileEngine(this._phone ? `.baileys/${this._phone}` : '.baileys/default');
|
|
388
|
+
this.event = new node_events_1.EventEmitter();
|
|
389
|
+
this.Contact = (0, Contact_1.contact)(this);
|
|
390
|
+
this.Chat = (0, Chat_1.chat)(this);
|
|
391
|
+
this.Message = (0, Message_1.message)(this);
|
|
392
|
+
}
|
|
393
|
+
/** @description Retorna el socket de Baileys (null si no está conectado). */
|
|
394
|
+
get socket() {
|
|
395
|
+
return this._socket;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
exports.WhatsApp = WhatsApp;
|
|
399
|
+
//# sourceMappingURL=WhatsApp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WhatsApp.js","sourceRoot":"","sources":["../src/WhatsApp.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGH,qCAciB;AACjB,6CAA2C;AAC3C,gDAAwB;AACxB,+CAAiC;AACjC,iCAAqE;AACrE,uCAAoF;AACpF,uCAA6F;AAC7F,mCAAkD;AAiClD;;;;;;;;GAQG;AACH,MAAa,QAAQ;IAUjB,YAAY,UAAqB,EAAE;QAR3B,YAAO,GAAoB,IAAI,CAAC;QAsBxC;;;;;WAKG;QACH,SAAI,GAAG,KAAK,EAAE,QAAyD,EAAiB,EAAE;YACtF,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,IAAA,mCAAyB,GAAE,CAAC;YACt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,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;CAkWJ;AAxXD,4BAwXC"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,109 +1,13 @@
|
|
|
1
|
-
import { Noop } from '@arcaelas/utils';
|
|
2
|
-
import { Mutex, type MutexInterface } from 'async-mutex';
|
|
3
|
-
import * as Baileys from 'baileys';
|
|
4
|
-
import EventEmitter from 'node:events';
|
|
5
|
-
import Chat from './model/chat';
|
|
6
|
-
import Message from './model/message';
|
|
7
|
-
import Store, { Engine } from './static/Store';
|
|
8
1
|
/**
|
|
9
|
-
* @
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Punto de entrada público de la librería @arcaelas/whatsapp
|
|
10
4
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
*/
|
|
21
|
-
interface EventMap {
|
|
22
|
-
error: [error: Error];
|
|
23
|
-
open: [];
|
|
24
|
-
close: [];
|
|
25
|
-
qr: [qr: string];
|
|
26
|
-
code: [code: string];
|
|
27
|
-
'chat:created': [chat: Chat];
|
|
28
|
-
'chat:updated': [chat: Chat];
|
|
29
|
-
'chat:deleted': [id: string];
|
|
30
|
-
'message:created': [message: Message];
|
|
31
|
-
'message:updated': [message: Message];
|
|
32
|
-
'message:deleted': [id: string];
|
|
33
|
-
process: [event: Partial<Baileys.BaileysEventMap>, socket: Baileys.WASocket, store: Store];
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* @description
|
|
37
|
-
* Client for WhatsApp Web.
|
|
38
|
-
* @example
|
|
39
|
-
* const client = new WhatsApp({
|
|
40
|
-
* phone: '1234567890',
|
|
41
|
-
* loginType: 'qr',
|
|
42
|
-
* qr: (code) => console.log(code),
|
|
43
|
-
* });
|
|
44
|
-
*/
|
|
45
|
-
declare class WhatsApp extends EventEmitter<EventMap> {
|
|
46
|
-
protected readonly options: IWhatsApp;
|
|
47
|
-
/**
|
|
48
|
-
* @description
|
|
49
|
-
* Store for WhatsApp Web.
|
|
50
|
-
*/
|
|
51
|
-
protected store: Store;
|
|
52
|
-
/**
|
|
53
|
-
* @description
|
|
54
|
-
* Socket for WhatsApp Web.
|
|
55
|
-
*/
|
|
56
|
-
protected socket: Baileys.WASocket | null;
|
|
57
|
-
/**
|
|
58
|
-
* @description
|
|
59
|
-
* Mutex, used to prevent concurrent access to the socket.
|
|
60
|
-
*/
|
|
61
|
-
protected readonly mutex: Mutex;
|
|
62
|
-
constructor(options: IWhatsApp);
|
|
63
|
-
/**
|
|
64
|
-
* @description
|
|
65
|
-
* Execute a function with the socket and store, means that the function will be executed only when the socket is ready.
|
|
66
|
-
* @param func Function to execute.
|
|
67
|
-
* @returns Result of the function.
|
|
68
|
-
*/
|
|
69
|
-
tick<T extends Noop<[release: MutexInterface.Releaser, socket: Baileys.WASocket, store: Store], any>>(func: T): Promise<Awaited<ReturnType<T>>>;
|
|
70
|
-
/**
|
|
71
|
-
* @description
|
|
72
|
-
* Process events from the socket.
|
|
73
|
-
* @param func Function to execute.
|
|
74
|
-
* @returns Handler to remove the event listener.
|
|
75
|
-
*/
|
|
76
|
-
process(func: Noop<[event: Partial<Baileys.BaileysEventMap>, socket: Baileys.WASocket, store: Store]>): this;
|
|
77
|
-
/**
|
|
78
|
-
* @description
|
|
79
|
-
* Returns all documents in the store.
|
|
80
|
-
* @returns Promise that resolves to an object containing all documents.
|
|
81
|
-
*/
|
|
82
|
-
documents(): Promise<Record<string, any>>;
|
|
83
|
-
/**
|
|
84
|
-
* @description
|
|
85
|
-
* Returns all chats in the store.
|
|
86
|
-
* @returns Promise that resolves to an array of chats.
|
|
87
|
-
*/
|
|
88
|
-
chats(): Promise<Chat[]>;
|
|
89
|
-
/**
|
|
90
|
-
* @description
|
|
91
|
-
* Returns all messages in the store.
|
|
92
|
-
* @returns Promise that resolves to an array of messages.
|
|
93
|
-
*/
|
|
94
|
-
messages(): Promise<Message[]>;
|
|
95
|
-
/**
|
|
96
|
-
* @description
|
|
97
|
-
* Connect to WhatsApp Web.
|
|
98
|
-
* @returns Promise that resolves to the socket.
|
|
99
|
-
*/
|
|
100
|
-
protected connect(): Promise<any>;
|
|
101
|
-
}
|
|
102
|
-
export default WhatsApp;
|
|
103
|
-
export * from './static/Store';
|
|
104
|
-
export { default as Store } from './static/Store';
|
|
105
|
-
export { default as useCache } from './static/useCache';
|
|
106
|
-
export * from './model/chat';
|
|
107
|
-
export { default as Chat } from './model/chat';
|
|
108
|
-
export * from './model/message';
|
|
109
|
-
export { default as Message } from './model/message';
|
|
5
|
+
export { MESSAGE_STATUS } from './Message';
|
|
6
|
+
export type { LocationOptions, MessageType, PollOptions } from './Message';
|
|
7
|
+
export type { Engine } from './store';
|
|
8
|
+
export type { IChat, IChatRaw, IGroupParticipant } from './Chat';
|
|
9
|
+
export type { IContact, IContactRaw } from './Contact';
|
|
10
|
+
export type { IMessage, IMessageIndex } from './Message';
|
|
11
|
+
export type { IWhatsApp } from './WhatsApp';
|
|
12
|
+
export { FileEngine, RedisEngine } from './store';
|
|
13
|
+
export { WhatsApp } from './WhatsApp';
|
package/build/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var I=(t,e)=>{for(var p in e)a(t,p,{get:e[p],enumerable:!0})},g=(t,e,p,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of f(e))!m.call(t,o)&&o!==p&&a(t,o,{get:()=>e[o],enumerable:!(s=x(e,o))||s.enumerable});return t};var y=t=>g(a({},"__esModule",{value:!0}),t);var h={};I(h,{FileEngine:()=>r.FileEngine,MESSAGE_STATUS:()=>n.MESSAGE_STATUS,RedisEngine:()=>r.RedisEngine,WhatsApp:()=>i.WhatsApp});module.exports=y(h);var n=require("./Message"),r=require("./store"),i=require("./WhatsApp");0&&(module.exports={FileEngine,MESSAGE_STATUS,RedisEngine,WhatsApp});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { merge, Noop, promify, sleep } from '@arcaelas/utils';\nimport { Mutex, type MutexInterface } from 'async-mutex';\nimport * as Baileys from 'baileys';\nimport NodeCache from 'node-cache';\nimport EventEmitter from 'node:events';\nimport P from 'pino';\nimport Chat from './model/chat';\nimport Message from './model/message';\nimport Store, { Engine } from './static/Store';\nimport useCache from './static/useCache';\n\n/**\n * @description Estructura de configuraci\u00F3n para iniciar sesi\u00F3n con WhatsApp.\n */\ninterface IWhatsApp {\n phone: string;\n store: Engine;\n onCode(code: string): void | Promise<void>;\n browser?: Baileys.WABrowserDescription | undefined;\n}\n\n/**\n * @description\n * Event map for WhatsApp.\n */\ninterface EventMap {\n error: [error: Error];\n open: [];\n close: [];\n qr: [qr: string];\n code: [code: string];\n 'chat:created': [chat: Chat];\n 'chat:updated': [chat: Chat];\n 'chat:deleted': [id: string];\n 'message:created': [message: Message];\n 'message:updated': [message: Message];\n 'message:deleted': [id: string];\n process: [event: Partial<Baileys.BaileysEventMap>, socket: Baileys.WASocket, store: Store];\n}\n\n/**\n * @description\n * Client for WhatsApp Web.\n * @example\n * const client = new WhatsApp({\n * phone: '1234567890',\n * loginType: 'qr',\n * qr: (code) => console.log(code),\n * });\n */\nclass WhatsApp extends EventEmitter<EventMap> {\n /**\n * @description\n * Store for WhatsApp Web.\n */\n protected store: Store;\n /**\n * @description\n * Socket for WhatsApp Web.\n */\n protected socket: Baileys.WASocket | null = null;\n /**\n * @description\n * Mutex, used to prevent concurrent access to the socket.\n */\n protected readonly mutex = new Mutex();\n\n constructor(protected readonly options: IWhatsApp) {\n super({ captureRejections: true });\n this.store = new Store(this.options.store);\n this.connect();\n }\n\n /**\n * @description\n * Execute a function with the socket and store, means that the function will be executed only when the socket is ready.\n * @param func Function to execute.\n * @returns Result of the function.\n */\n async tick<T extends Noop<[release: MutexInterface.Releaser, socket: Baileys.WASocket, store: Store], any>>(func: T): Promise<Awaited<ReturnType<T>>> {\n return this.mutex.acquire(5).then((release) => func(release, this.socket!, this.store));\n }\n\n /**\n * @description\n * Process events from the socket.\n * @param func Function to execute.\n * @returns Handler to remove the event listener.\n */\n process(func: Noop<[event: Partial<Baileys.BaileysEventMap>, socket: Baileys.WASocket, store: Store]>) {\n return this.on('process', (event) => {\n func(event, this.socket!, this.store);\n });\n }\n\n /**\n * @description\n * Returns all documents in the store.\n * @returns Promise that resolves to an object containing all documents.\n */\n async documents(): Promise<Record<string, any>> {\n const documents: Record<string, any> = {};\n for await (const document of this.store.document.values()) {\n documents[document.key] = document.value;\n }\n return documents;\n }\n\n /**\n * @description\n * Returns all chats in the store.\n * @returns Promise that resolves to an array of chats.\n */\n async chats(): Promise<Chat[]> {\n const chats: Chat[] = [];\n for await (const chat of this.store.chat.values()) {\n chats.push(new Chat(this, chat));\n }\n return chats;\n }\n\n /**\n * @description\n * Returns all messages in the store.\n * @returns Promise that resolves to an array of messages.\n */\n async messages(): Promise<Message[]> {\n const messages: Message[] = [];\n for await (const message of this.store.message.values()) {\n messages.push(new Message(this, message));\n }\n return messages;\n }\n\n /**\n * @description\n * Connect to WhatsApp Web.\n * @returns Promise that resolves to the socket.\n */\n protected async connect() {\n const promise = promify();\n try {\n const logger = P({ level: 'fatal' });\n const { state, save } = await useCache(this.store);\n const socket = Baileys.makeWASocket({\n logger: logger,\n maxMsgRetryCount: 4,\n syncFullHistory: false,\n printQRInTerminal: false,\n connectTimeoutMs: 20_000,\n retryRequestDelayMs: 350,\n markOnlineOnConnect: false,\n keepAliveIntervalMs: 30_000,\n version: [2, 3000, 1023223821],\n generateHighQualityLinkPreview: true,\n msgRetryCounterCache: new NodeCache(),\n browser: ['Windows', 'Chrome', 'Chrome 114.0.5735.198'],\n auth: {\n creds: state.creds,\n keys: Baileys.makeCacheableSignalKeyStore(state.keys, logger),\n },\n getMessage: async (key) => {\n const message = await this.store.message.get(key.id!);\n return message ? message.message! : undefined;\n },\n });\n socket.ev.process(async (event) => {\n this.emit('process', event, socket, this.store);\n if (event['creds.update']) {\n await save();\n }\n if (event['connection.update']) {\n const { connection, lastDisconnect } = event['connection.update'];\n const statusCode = lastDisconnect?.error?.['output']?.statusCode;\n if (connection === 'open') {\n promise.resolve(socket);\n } else if (connection === 'close') {\n if (statusCode === Baileys.DisconnectReason.loggedOut) {\n promise.resolve(await this.connect());\n } else if (statusCode === Baileys.DisconnectReason.restartRequired) {\n promise.resolve(await this.connect());\n } else {\n promise.reject(lastDisconnect);\n }\n }\n }\n });\n socket.ev.on('messaging-history.set', ({ contacts = [], chats = [], messages = [] }) => {\n // prettier-ignore\n Promise.allSettled(\n contacts.map(async c=>{\n await this.store.contact.set(c);\n })\n );\n // prettier-ignore\n Promise.allSettled(\n chats.map(async c=>{\n await this.store.chat.set(c);\n this.emit('chat:created', new Chat(this, c));\n })\n );\n // prettier-ignore\n Promise.allSettled(\n messages.map(async m=>{\n await this.store.message.set(m);\n const message = new Message(this, m);\n if(['text', 'image', 'audio', 'video', 'location'].includes(message.type)){\n this.emit('message:created', message);\n }\n })\n );\n });\n socket.ev.on('chats.upsert', (chats) => {\n // prettier-ignore\n Promise.allSettled(\n chats.map(async c=>{\n await this.store.chat.set(c);\n this.emit('chat:created', new Chat(this, c));\n })\n )\n });\n socket.ev.on('chats.update', (chats) => {\n // prettier-ignore\n Promise.allSettled(\n chats.map(async c=>{\n const mem = await this.store.chat.get(c.id!)\n const payload = merge({}, mem, c);\n await this.store.chat.set(payload);\n this.emit('chat:updated', new Chat(this, payload));\n })\n )\n });\n socket.ev.on('chats.delete', (ids) => {\n // prettier-ignore\n Promise.allSettled(\n ids.map(async id=>{\n await this.store.chat.unset(id);\n this.emit('chat:deleted', id);\n })\n )\n });\n socket.ev.on('messages.upsert', ({ type, messages }) => {\n if (type === 'notify') {\n // prettier-ignore\n Promise.allSettled(\n messages.map(async m=>{\n await this.store.message.set(m);\n const message = new Message(this, m);\n if(['text', 'image', 'audio', 'video', 'location'].includes(message.type)){\n this.emit('message:created', message);\n }\n })\n )\n }\n });\n socket.ev.on('messages.update', (messages) => {\n // prettier-ignore\n Promise.allSettled(\n messages.map(async m=>{\n const mem = await this.store.message.get(m.key.id!);\n const payload = merge({}, mem, m);\n await this.store.message.set(payload);\n this.emit('message:updated', new Message(this, payload));\n })\n )\n });\n socket.ev.on('messages.delete', (e) => {\n if (e['keys']) {\n // prettier-ignore\n Promise.allSettled(\n e['keys'].map(async k=>{\n await this.store.message.unset(k.id!);\n this.emit('message:deleted', k.id!);\n })\n )\n }\n });\n if (!socket.authState.creds.registered) {\n await sleep(2000);\n await this.store.document.unset('creds.json');\n const code = await socket.requestPairingCode(this.options.phone);\n await this.options.onCode(code);\n }\n } catch (error) {\n promise.reject(error);\n }\n // prettier-ignore\n return promise\n .then((socket) => (this.socket = socket));\n }\n}\n\nexport default WhatsApp;\nexport * from './static/Store';\nexport { default as Store } from './static/Store';\nexport { default as useCache } from './static/useCache';\n\nexport * from './model/chat';\nexport { default as Chat } from './model/chat';\n\nexport * from './model/message';\nexport { default as Message } from './model/message';\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["src_exports", "__export", "
|
|
4
|
+
"sourcesContent": ["/**\n * @file index.ts\n * @description Punto de entrada p\u00FAblico de la librer\u00EDa @arcaelas/whatsapp\n */\n\n// Enums\nexport { MESSAGE_STATUS } from './Message';\n\n// Types\nexport type { LocationOptions, MessageType, PollOptions } from './Message';\nexport type { Engine } from './store';\n\n// Interfaces\nexport type { IChat, IChatRaw, IGroupParticipant } from './Chat';\nexport type { IContact, IContactRaw } from './Contact';\nexport type { IMessage, IMessageIndex } from './Message';\nexport type { IWhatsApp } from './WhatsApp';\n\n// Classes\nexport { FileEngine, RedisEngine } from './store';\nexport { WhatsApp } from './WhatsApp';\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wIAAAE,EAAAF,GAMA,IAAAG,EAA+B,qBAa/BC,EAAwC,mBACxCC,EAAyB",
|
|
6
|
+
"names": ["src_exports", "__export", "__toCommonJS", "import_Message", "import_store", "import_WhatsApp"]
|
|
7
7
|
}
|