@arcaelas/whatsapp 1.2.3 → 2.0.0
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/build/cjs/Chat.d.ts +317 -0
- package/build/cjs/Chat.js +273 -0
- package/build/cjs/Chat.js.map +1 -0
- package/build/{Contact.d.ts → cjs/Contact.d.ts} +317 -304
- package/build/cjs/Contact.js +144 -0
- package/build/cjs/Contact.js.map +1 -0
- package/build/cjs/Message.d.ts +882 -0
- package/build/cjs/Message.js +483 -0
- package/build/cjs/Message.js.map +1 -0
- package/build/{WhatsApp.d.ts → cjs/WhatsApp.d.ts} +16 -4
- package/build/{WhatsApp.js → cjs/WhatsApp.js} +84 -81
- package/build/cjs/WhatsApp.js.map +1 -0
- package/build/{index.d.ts → cjs/index.d.ts} +2 -2
- package/build/cjs/index.js +17 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/package.json +1 -0
- package/build/cjs/store/driver/FileEngine.d.ts +34 -0
- package/build/{store → cjs/store}/driver/FileEngine.js +16 -20
- package/build/cjs/store/driver/FileEngine.js.map +1 -0
- package/build/{store → cjs/store}/driver/RedisEngine.d.ts +14 -5
- package/build/{store → cjs/store}/driver/RedisEngine.js +23 -22
- package/build/cjs/store/driver/RedisEngine.js.map +1 -0
- package/build/{store → cjs/store}/engine.d.ts +9 -10
- package/build/cjs/store/engine.js.map +1 -0
- package/build/cjs/store/index.d.ts +8 -0
- package/build/{store → cjs/store}/index.js +2 -2
- package/build/cjs/store/index.js.map +1 -0
- package/build/esm/Chat.d.ts +317 -0
- package/build/esm/Chat.js +268 -0
- package/build/esm/Chat.js.map +1 -0
- package/build/esm/Contact.d.ts +869 -0
- package/build/esm/Contact.js +139 -0
- package/build/esm/Contact.js.map +1 -0
- package/build/esm/Message.d.ts +882 -0
- package/build/esm/Message.js +478 -0
- package/build/esm/Message.js.map +1 -0
- package/build/esm/WhatsApp.d.ts +80 -0
- package/build/esm/WhatsApp.js +362 -0
- package/build/esm/WhatsApp.js.map +1 -0
- package/build/esm/index.d.ts +13 -0
- package/build/esm/index.js +10 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/package.json +1 -0
- package/build/esm/store/driver/FileEngine.d.ts +34 -0
- package/build/esm/store/driver/FileEngine.js +82 -0
- package/build/esm/store/driver/FileEngine.js.map +1 -0
- package/build/esm/store/driver/RedisEngine.d.ts +47 -0
- package/build/esm/store/driver/RedisEngine.js +66 -0
- package/build/esm/store/driver/RedisEngine.js.map +1 -0
- package/build/esm/store/engine.d.ts +53 -0
- package/build/esm/store/engine.js +6 -0
- package/build/{store → esm/store}/engine.js.map +1 -1
- package/build/esm/store/index.d.ts +8 -0
- package/build/esm/store/index.js +7 -0
- package/build/esm/store/index.js.map +1 -0
- package/package.json +70 -58
- package/API.md +0 -776
- package/CHANGELOG.md +0 -53
- package/DOC.md +0 -532
- package/build/Chat.d.ts +0 -335
- package/build/Chat.js +0 -396
- package/build/Chat.js.map +0 -1
- package/build/Contact.js +0 -188
- package/build/Contact.js.map +0 -1
- package/build/Message.d.ts +0 -580
- package/build/Message.js +0 -463
- package/build/Message.js.map +0 -1
- package/build/WhatsApp.js.map +0 -1
- package/build/index.js +0 -2
- package/build/index.js.map +0 -7
- package/build/store/driver/FileEngine.d.ts +0 -23
- package/build/store/driver/FileEngine.js.map +0 -1
- package/build/store/driver/RedisEngine.js.map +0 -1
- package/build/store/index.d.ts +0 -8
- package/build/store/index.js.map +0 -1
- package/context7.json +0 -4
- package/tsconfig.json +0 -27
- /package/build/{store → cjs/store}/engine.js +0 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Message.ts
|
|
3
|
+
* @description Clase Message para gestión de mensajes de WhatsApp
|
|
4
|
+
*/
|
|
5
|
+
import { BufferJSON, downloadMediaMessage, generateForwardMessageContent, generateWAMessageFromContent, getContentType } from 'baileys';
|
|
6
|
+
import { Readable } from 'node:stream';
|
|
7
|
+
/**
|
|
8
|
+
* @description Estados de un mensaje.
|
|
9
|
+
* Message delivery statuses.
|
|
10
|
+
*/
|
|
11
|
+
export var MESSAGE_STATUS;
|
|
12
|
+
(function (MESSAGE_STATUS) {
|
|
13
|
+
/** Error al enviar / Send error */
|
|
14
|
+
MESSAGE_STATUS[MESSAGE_STATUS["ERROR"] = 0] = "ERROR";
|
|
15
|
+
/** Mensaje pendiente de envío / Pending send */
|
|
16
|
+
MESSAGE_STATUS[MESSAGE_STATUS["PENDING"] = 1] = "PENDING";
|
|
17
|
+
/** Servidor recibió el mensaje / Server acknowledged */
|
|
18
|
+
MESSAGE_STATUS[MESSAGE_STATUS["SERVER_ACK"] = 2] = "SERVER_ACK";
|
|
19
|
+
/** Mensaje entregado al destinatario / Delivered */
|
|
20
|
+
MESSAGE_STATUS[MESSAGE_STATUS["DELIVERED"] = 3] = "DELIVERED";
|
|
21
|
+
/** Mensaje leído por el destinatario / Read */
|
|
22
|
+
MESSAGE_STATUS[MESSAGE_STATUS["READ"] = 4] = "READ";
|
|
23
|
+
/** Mensaje reproducido (audio/video) / Played */
|
|
24
|
+
MESSAGE_STATUS[MESSAGE_STATUS["PLAYED"] = 5] = "PLAYED";
|
|
25
|
+
})(MESSAGE_STATUS || (MESSAGE_STATUS = {}));
|
|
26
|
+
/**
|
|
27
|
+
* @description Mapeo de tipos de contenido de Baileys a MessageType.
|
|
28
|
+
* Baileys content type to MessageType mapping.
|
|
29
|
+
*/
|
|
30
|
+
export const MESSAGE_TYPE_MAP = {
|
|
31
|
+
conversation: 'text',
|
|
32
|
+
extendedTextMessage: 'text',
|
|
33
|
+
imageMessage: 'image',
|
|
34
|
+
videoMessage: 'video',
|
|
35
|
+
audioMessage: 'audio',
|
|
36
|
+
locationMessage: 'location',
|
|
37
|
+
liveLocationMessage: 'location',
|
|
38
|
+
pollCreationMessage: 'poll',
|
|
39
|
+
pollCreationMessageV2: 'poll',
|
|
40
|
+
pollCreationMessageV3: 'poll',
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* @description Construye IMessageIndex desde WAMessage.
|
|
44
|
+
* Builds IMessageIndex from WAMessage.
|
|
45
|
+
*/
|
|
46
|
+
function build_message_index(raw, edited = false) {
|
|
47
|
+
const key = raw.key ?? {};
|
|
48
|
+
const content_type = getContentType(raw.message ?? {});
|
|
49
|
+
const msg_type = MESSAGE_TYPE_MAP[content_type ?? ''] ?? 'text';
|
|
50
|
+
const msg_content = raw.message?.[content_type];
|
|
51
|
+
const context_info = msg_content?.contextInfo;
|
|
52
|
+
const ephemeral_duration = raw.ephemeralDuration ?? context_info?.expiration;
|
|
53
|
+
const deleted_at = raw.ephemeralStartTimestamp && ephemeral_duration ? (Number(raw.ephemeralStartTimestamp) + ephemeral_duration) * 1000 : null;
|
|
54
|
+
let mime = 'text/plain';
|
|
55
|
+
if (msg_type === 'location' || msg_type === 'poll')
|
|
56
|
+
mime = 'application/json';
|
|
57
|
+
else if (msg_type !== 'text' && typeof msg_content === 'object')
|
|
58
|
+
mime = msg_content?.mimetype ?? 'application/octet-stream';
|
|
59
|
+
let caption = '';
|
|
60
|
+
if (typeof msg_content === 'string')
|
|
61
|
+
caption = msg_content;
|
|
62
|
+
else if (msg_content)
|
|
63
|
+
caption = msg_content.caption ?? msg_content.text ?? msg_content.name ?? '';
|
|
64
|
+
return {
|
|
65
|
+
id: key.id ?? '',
|
|
66
|
+
cid: key.remoteJid ?? '',
|
|
67
|
+
mid: context_info?.stanzaId ?? null,
|
|
68
|
+
me: key.fromMe ?? false,
|
|
69
|
+
type: msg_type,
|
|
70
|
+
author: key.participant ?? key.remoteJid ?? '',
|
|
71
|
+
status: raw.status ?? MESSAGE_STATUS.PENDING,
|
|
72
|
+
starred: raw.starred ?? false,
|
|
73
|
+
forwarded: context_info?.isForwarded ?? false,
|
|
74
|
+
created_at: (Number(raw.messageTimestamp) || Math.floor(Date.now() / 1000)) * 1000,
|
|
75
|
+
deleted_at,
|
|
76
|
+
mime,
|
|
77
|
+
caption,
|
|
78
|
+
edited,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @description
|
|
83
|
+
* Clase base para representar un mensaje de WhatsApp.
|
|
84
|
+
* Base class representing a WhatsApp message.
|
|
85
|
+
*/
|
|
86
|
+
export class Message {
|
|
87
|
+
constructor(data) {
|
|
88
|
+
this.index = data.index;
|
|
89
|
+
this.raw = data.raw;
|
|
90
|
+
}
|
|
91
|
+
/** ID único del mensaje / Unique message ID */
|
|
92
|
+
get id() { return this.index.id; }
|
|
93
|
+
/** JID del chat al que pertenece / Chat JID */
|
|
94
|
+
get cid() { return this.index.cid; }
|
|
95
|
+
/** ID del mensaje padre (reply) / Parent message ID (reply) */
|
|
96
|
+
get mid() { return this.index.mid; }
|
|
97
|
+
/** true si el mensaje fue enviado por el usuario autenticado / true if sent by authenticated user */
|
|
98
|
+
get me() { return this.index.me; }
|
|
99
|
+
/** Autor del mensaje / Message author */
|
|
100
|
+
get author() { return this.index.author; }
|
|
101
|
+
/** true si el mensaje fue editado / true if edited */
|
|
102
|
+
get edited() { return this.index.edited; }
|
|
103
|
+
/** Tipo de contenido del mensaje / Message content type */
|
|
104
|
+
get type() { return this.index.type; }
|
|
105
|
+
/** Texto o caption del mensaje / Message text or caption */
|
|
106
|
+
get caption() { return this.index.caption; }
|
|
107
|
+
/** Tipo MIME del contenido / Content MIME type */
|
|
108
|
+
get mime() { return this.index.mime; }
|
|
109
|
+
/** Estado del mensaje / Message status */
|
|
110
|
+
get status() { return this.index.status; }
|
|
111
|
+
/** true si el mensaje está destacado / true if starred */
|
|
112
|
+
get starred() { return this.index.starred; }
|
|
113
|
+
/** true si el mensaje fue reenviado / true if forwarded */
|
|
114
|
+
get forwarded() { return this.index.forwarded; }
|
|
115
|
+
/** Timestamp de creación (ms) / Creation timestamp (ms) */
|
|
116
|
+
get created_at() { return this.index.created_at; }
|
|
117
|
+
/** Timestamp de expiración (ms) o null / Expiration timestamp (ms) or null */
|
|
118
|
+
get deleted_at() { return this.index.deleted_at; }
|
|
119
|
+
/**
|
|
120
|
+
* @description Obtiene el contenido como Readable stream.
|
|
121
|
+
* Gets content as Readable stream.
|
|
122
|
+
*/
|
|
123
|
+
stream() {
|
|
124
|
+
return Promise.resolve(Readable.from(Buffer.alloc(0)));
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* @description Obtiene el contenido del mensaje como Buffer.
|
|
128
|
+
* Gets message content as Buffer.
|
|
129
|
+
*/
|
|
130
|
+
content() {
|
|
131
|
+
return Promise.resolve(Buffer.alloc(0));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* @description Factory que retorna la clase Message enlazada al contexto.
|
|
136
|
+
* Factory that returns the Message class bound to context.
|
|
137
|
+
* @param wa Instancia de WhatsApp.
|
|
138
|
+
*/
|
|
139
|
+
export function message(wa) {
|
|
140
|
+
const _watchers = new Map();
|
|
141
|
+
/**
|
|
142
|
+
* @description Agrega un mensaje al índice del chat (interno).
|
|
143
|
+
* Adds a message to the chat index (internal).
|
|
144
|
+
*/
|
|
145
|
+
async function _add_to_index(cid, mid, timestamp) {
|
|
146
|
+
const key = `chat/${cid}/messages`;
|
|
147
|
+
const line = `${timestamp} ${mid}`;
|
|
148
|
+
const current = await wa.engine.get(key);
|
|
149
|
+
await wa.engine.set(key, current ? `${line}\n${current}` : line);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* @description Elimina un mensaje del índice del chat (interno).
|
|
153
|
+
* Removes a message from the chat index (internal).
|
|
154
|
+
*/
|
|
155
|
+
async function _remove_from_index(cid, mid) {
|
|
156
|
+
const key = `chat/${cid}/messages`;
|
|
157
|
+
const content = await wa.engine.get(key);
|
|
158
|
+
if (!content)
|
|
159
|
+
return;
|
|
160
|
+
const filtered = content.trim().split('\n').filter((line) => !line.endsWith(` ${mid}`)).join('\n');
|
|
161
|
+
await wa.engine.set(key, filtered || null);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* @description Notifica a los watchers de un mensaje (interno).
|
|
165
|
+
* Notifies message watchers (internal).
|
|
166
|
+
*/
|
|
167
|
+
function _notify(cid, mid) {
|
|
168
|
+
const handlers = _watchers.get(`${cid}:${mid}`);
|
|
169
|
+
handlers?.forEach((h) => _Message.get(cid, mid).then((msg) => msg && h(msg)));
|
|
170
|
+
}
|
|
171
|
+
async function _send(cid, content, binary, reply_to) {
|
|
172
|
+
const jid = await wa.resolveJID(cid);
|
|
173
|
+
if (!jid || !wa.socket)
|
|
174
|
+
return null;
|
|
175
|
+
let quoted;
|
|
176
|
+
if (reply_to) {
|
|
177
|
+
const ref = await _Message.get(jid, reply_to);
|
|
178
|
+
if (ref)
|
|
179
|
+
quoted = ref.raw;
|
|
180
|
+
}
|
|
181
|
+
const raw = await wa.socket.sendMessage(jid, { ...content, ...(quoted && { quoted }) });
|
|
182
|
+
const sent_id = raw?.key?.id;
|
|
183
|
+
if (!raw || !sent_id)
|
|
184
|
+
return null;
|
|
185
|
+
const index = build_message_index(raw);
|
|
186
|
+
await wa.engine.set(`chat/${jid}/message/${sent_id}/index`, JSON.stringify(index, BufferJSON.replacer));
|
|
187
|
+
await wa.engine.set(`chat/${jid}/message/${sent_id}/raw`, JSON.stringify(raw, BufferJSON.replacer));
|
|
188
|
+
if (binary)
|
|
189
|
+
await wa.engine.set(`chat/${jid}/message/${sent_id}/content`, binary.toString('base64'));
|
|
190
|
+
await _add_to_index(jid, sent_id, index.created_at);
|
|
191
|
+
return new _Message({ index, raw });
|
|
192
|
+
}
|
|
193
|
+
const _Message = class extends Message {
|
|
194
|
+
/**
|
|
195
|
+
* @description Obtiene un mensaje por CID y MID.
|
|
196
|
+
* Retrieves a message by CID and MID.
|
|
197
|
+
*/
|
|
198
|
+
static async get(cid, mid) {
|
|
199
|
+
const jid = await wa.resolveJID(cid);
|
|
200
|
+
if (!jid)
|
|
201
|
+
return null;
|
|
202
|
+
const stored_index = await wa.engine.get(`chat/${jid}/message/${mid}/index`);
|
|
203
|
+
if (!stored_index)
|
|
204
|
+
return null;
|
|
205
|
+
const index = JSON.parse(stored_index, BufferJSON.reviver);
|
|
206
|
+
const stored_raw = await wa.engine.get(`chat/${jid}/message/${mid}/raw`);
|
|
207
|
+
const raw = stored_raw ? JSON.parse(stored_raw, BufferJSON.reviver) : { key: { remoteJid: jid, id: mid, fromMe: index.me } };
|
|
208
|
+
return new _Message({ index, raw });
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* @description Lista mensajes de un chat (paginado).
|
|
212
|
+
* Lists messages from a chat (paginated).
|
|
213
|
+
*/
|
|
214
|
+
static async list(cid, offset = 0, limit = 50) {
|
|
215
|
+
const jid = await wa.resolveJID(cid);
|
|
216
|
+
if (!jid)
|
|
217
|
+
return [];
|
|
218
|
+
const content = await wa.engine.get(`chat/${jid}/messages`);
|
|
219
|
+
if (!content)
|
|
220
|
+
return [];
|
|
221
|
+
const ids = content.trim().split('\n').slice(offset, offset + limit).map((line) => line.split(' ')[1]).filter(Boolean);
|
|
222
|
+
const messages = [];
|
|
223
|
+
for (const mid of ids) {
|
|
224
|
+
const msg = await _Message.get(jid, mid);
|
|
225
|
+
if (msg)
|
|
226
|
+
messages.push(msg);
|
|
227
|
+
}
|
|
228
|
+
return messages;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* @description Cuenta mensajes de un chat.
|
|
232
|
+
* Counts messages in a chat.
|
|
233
|
+
*/
|
|
234
|
+
static async count(cid) {
|
|
235
|
+
const jid = await wa.resolveJID(cid);
|
|
236
|
+
if (!jid)
|
|
237
|
+
return 0;
|
|
238
|
+
const content = await wa.engine.get(`chat/${jid}/messages`);
|
|
239
|
+
if (!content)
|
|
240
|
+
return 0;
|
|
241
|
+
return content.trim().split('\n').filter(Boolean).length;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* @description Envía un mensaje de texto.
|
|
245
|
+
* Sends a text message.
|
|
246
|
+
*/
|
|
247
|
+
static async text(cid, text, mid) {
|
|
248
|
+
return _send(cid, { text }, undefined, mid);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* @description Envía una imagen.
|
|
252
|
+
* Sends an image.
|
|
253
|
+
*/
|
|
254
|
+
static async image(cid, buffer, caption, mid) {
|
|
255
|
+
return _send(cid, { image: buffer, caption }, buffer, mid);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* @description Envía un video.
|
|
259
|
+
* Sends a video.
|
|
260
|
+
*/
|
|
261
|
+
static async video(cid, buffer, caption, mid) {
|
|
262
|
+
return _send(cid, { video: buffer, caption }, buffer, mid);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* @description Envía un audio.
|
|
266
|
+
* Sends an audio.
|
|
267
|
+
* @param ptt true para nota de voz (default true) / true for voice note (default true).
|
|
268
|
+
*/
|
|
269
|
+
static async audio(cid, buffer, ptt = true, mid) {
|
|
270
|
+
return _send(cid, { audio: buffer, ptt }, buffer, mid);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* @description Envía una ubicación.
|
|
274
|
+
* Sends a location.
|
|
275
|
+
*/
|
|
276
|
+
static async location(cid, opts, mid) {
|
|
277
|
+
return _send(cid, { location: { degreesLatitude: opts.lat, degreesLongitude: opts.lng } }, undefined, mid);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* @description Envía una encuesta.
|
|
281
|
+
* Sends a poll.
|
|
282
|
+
*/
|
|
283
|
+
static async poll(cid, opts, mid) {
|
|
284
|
+
return _send(cid, { poll: { name: opts.content, values: opts.options.map((o) => o.content), selectableCount: 1 } }, undefined, mid);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* @description Observa cambios en un mensaje específico.
|
|
288
|
+
* Watches changes on a specific message.
|
|
289
|
+
* @returns Función para dejar de observar / Unsubscribe function.
|
|
290
|
+
*/
|
|
291
|
+
static watch(cid, mid, handler) {
|
|
292
|
+
const key = `${cid}:${mid}`;
|
|
293
|
+
if (!_watchers.has(key))
|
|
294
|
+
_watchers.set(key, new Set());
|
|
295
|
+
_watchers.get(key)?.add(handler);
|
|
296
|
+
return () => {
|
|
297
|
+
_watchers.get(key)?.delete(handler);
|
|
298
|
+
if (_watchers.get(key)?.size === 0)
|
|
299
|
+
_watchers.delete(key);
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* @description Edita el mensaje (solo texto o caption, solo mensajes propios).
|
|
304
|
+
* Edits the message (text or caption only, own messages only).
|
|
305
|
+
*/
|
|
306
|
+
async edit(text) {
|
|
307
|
+
if (!wa.socket || !this.me)
|
|
308
|
+
return false;
|
|
309
|
+
await wa.socket.sendMessage(this.cid, {
|
|
310
|
+
text,
|
|
311
|
+
edit: { remoteJid: this.cid, id: this.id, fromMe: true },
|
|
312
|
+
});
|
|
313
|
+
const content_type = getContentType(this.raw.message ?? {});
|
|
314
|
+
if (content_type === 'conversation') {
|
|
315
|
+
this.raw.message = { conversation: text };
|
|
316
|
+
}
|
|
317
|
+
else if (content_type === 'extendedTextMessage') {
|
|
318
|
+
this.raw.message = { extendedTextMessage: { text } };
|
|
319
|
+
}
|
|
320
|
+
this.index.caption = text;
|
|
321
|
+
this.index.edited = true;
|
|
322
|
+
await wa.engine.set(`chat/${this.cid}/message/${this.id}/index`, JSON.stringify(this.index, BufferJSON.replacer));
|
|
323
|
+
await wa.engine.set(`chat/${this.cid}/message/${this.id}/raw`, JSON.stringify(this.raw, BufferJSON.replacer));
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* @description Elimina el mensaje para todos.
|
|
328
|
+
* Deletes the message for everyone.
|
|
329
|
+
*/
|
|
330
|
+
async remove() {
|
|
331
|
+
if (!wa.socket)
|
|
332
|
+
return false;
|
|
333
|
+
await wa.socket.sendMessage(this.cid, { delete: { remoteJid: this.cid, id: this.id, fromMe: this.me } });
|
|
334
|
+
await _remove_from_index(this.cid, this.id);
|
|
335
|
+
await wa.engine.set(`chat/${this.cid}/message/${this.id}`, null);
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* @description Reenvía el mensaje a otro chat.
|
|
340
|
+
* Forwards the message to another chat.
|
|
341
|
+
*/
|
|
342
|
+
async forward(to_cid) {
|
|
343
|
+
if (!wa.socket)
|
|
344
|
+
return false;
|
|
345
|
+
if (this.raw.message) {
|
|
346
|
+
try {
|
|
347
|
+
const wa_msg = generateWAMessageFromContent(to_cid, generateForwardMessageContent(this.raw, false), { userJid: wa.socket.user?.id ?? '' });
|
|
348
|
+
if (!wa_msg.message || !wa_msg.key?.id)
|
|
349
|
+
return false;
|
|
350
|
+
await wa.socket.relayMessage(to_cid, wa_msg.message, { messageId: wa_msg.key.id });
|
|
351
|
+
return true;
|
|
352
|
+
}
|
|
353
|
+
catch { /* fallback below */ }
|
|
354
|
+
}
|
|
355
|
+
const buf = await this.content();
|
|
356
|
+
if (!buf.length)
|
|
357
|
+
return false;
|
|
358
|
+
if (this.type === 'text')
|
|
359
|
+
return (await _Message.text(to_cid, buf.toString())) !== null;
|
|
360
|
+
if (this.type === 'image')
|
|
361
|
+
return (await _Message.image(to_cid, buf, this.caption || undefined)) !== null;
|
|
362
|
+
if (this.type === 'video')
|
|
363
|
+
return (await _Message.video(to_cid, buf, this.caption || undefined)) !== null;
|
|
364
|
+
if (this.type === 'audio')
|
|
365
|
+
return (await _Message.audio(to_cid, buf)) !== null;
|
|
366
|
+
if (this.type === 'location') {
|
|
367
|
+
try {
|
|
368
|
+
return (await _Message.location(to_cid, JSON.parse(buf.toString()))) !== null;
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
return false;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* @description Reacciona al mensaje.
|
|
378
|
+
* Reacts to the message.
|
|
379
|
+
* @param emoji Emoji de reacción (vacío para quitar) / Reaction emoji (empty to remove).
|
|
380
|
+
*/
|
|
381
|
+
async react(emoji) {
|
|
382
|
+
if (!wa.socket)
|
|
383
|
+
return false;
|
|
384
|
+
await wa.socket.sendMessage(this.cid, {
|
|
385
|
+
react: { text: emoji, key: { remoteJid: this.cid, id: this.id, fromMe: this.me } },
|
|
386
|
+
});
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* @description Responde con un mensaje de texto.
|
|
391
|
+
* Replies with a text message.
|
|
392
|
+
*/
|
|
393
|
+
async text(content) {
|
|
394
|
+
return _Message.text(this.cid, content, this.id);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* @description Responde con una imagen.
|
|
398
|
+
* Replies with an image.
|
|
399
|
+
*/
|
|
400
|
+
async image(buffer, caption) {
|
|
401
|
+
return _Message.image(this.cid, buffer, caption, this.id);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* @description Responde con un video.
|
|
405
|
+
* Replies with a video.
|
|
406
|
+
*/
|
|
407
|
+
async video(buffer, caption) {
|
|
408
|
+
return _Message.video(this.cid, buffer, caption, this.id);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* @description Responde con un audio.
|
|
412
|
+
* Replies with an audio.
|
|
413
|
+
*/
|
|
414
|
+
async audio(buffer, ptt = true) {
|
|
415
|
+
return _Message.audio(this.cid, buffer, ptt, this.id);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* @description Responde con una ubicacion.
|
|
419
|
+
* Replies with a location.
|
|
420
|
+
*/
|
|
421
|
+
async location(opts) {
|
|
422
|
+
return _Message.location(this.cid, opts, this.id);
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* @description Responde con una encuesta.
|
|
426
|
+
* Replies with a poll.
|
|
427
|
+
*/
|
|
428
|
+
async poll(opts) {
|
|
429
|
+
return _Message.poll(this.cid, opts, this.id);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* @description Obtiene el contenido como Readable stream.
|
|
433
|
+
* Gets content as Readable stream.
|
|
434
|
+
*/
|
|
435
|
+
async stream() {
|
|
436
|
+
if (this.type === 'text') {
|
|
437
|
+
return Readable.from(Buffer.from(this.caption, 'utf-8'));
|
|
438
|
+
}
|
|
439
|
+
if (this.type === 'location') {
|
|
440
|
+
const loc = this.raw.message?.locationMessage ?? this.raw.message?.liveLocationMessage;
|
|
441
|
+
return Readable.from(Buffer.from(JSON.stringify({ lat: loc?.degreesLatitude, lng: loc?.degreesLongitude }), 'utf-8'));
|
|
442
|
+
}
|
|
443
|
+
if (this.type === 'poll') {
|
|
444
|
+
const poll = this.raw.message?.pollCreationMessage ?? this.raw.message?.pollCreationMessageV2 ?? this.raw.message?.pollCreationMessageV3;
|
|
445
|
+
return Readable.from(Buffer.from(JSON.stringify({ content: poll?.name ?? '', options: poll?.options?.map((o) => ({ content: o.optionName })) ?? [] }), 'utf-8'));
|
|
446
|
+
}
|
|
447
|
+
if (wa.socket) {
|
|
448
|
+
try {
|
|
449
|
+
return await downloadMediaMessage(this.raw, 'stream', {});
|
|
450
|
+
}
|
|
451
|
+
catch {
|
|
452
|
+
return Readable.from(Buffer.alloc(0));
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return Readable.from(Buffer.alloc(0));
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* @description Obtiene el contenido del mensaje como Buffer.
|
|
459
|
+
* Gets message content as Buffer.
|
|
460
|
+
*/
|
|
461
|
+
async content() {
|
|
462
|
+
const cached = await wa.engine.get(`chat/${this.cid}/message/${this.id}/content`);
|
|
463
|
+
if (cached)
|
|
464
|
+
return Buffer.from(cached, 'base64');
|
|
465
|
+
const readable = await this.stream();
|
|
466
|
+
const chunks = [];
|
|
467
|
+
for await (const chunk of readable) {
|
|
468
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
469
|
+
}
|
|
470
|
+
const buffer = Buffer.concat(chunks);
|
|
471
|
+
if (buffer.length)
|
|
472
|
+
await wa.engine.set(`chat/${this.cid}/message/${this.id}/content`, buffer.toString('base64'));
|
|
473
|
+
return buffer;
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
return Object.assign(_Message, { _add_to_index, _remove_from_index, _notify, _build_index: build_message_index });
|
|
477
|
+
}
|
|
478
|
+
//# sourceMappingURL=Message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Message.js","sourceRoot":"","sources":["../../src/Message.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,6BAA6B,EAAE,4BAA4B,EAAE,cAAc,EAAS,MAAM,SAAS,CAAC;AAC/I,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AASvC;;;GAGG;AACH,MAAM,CAAN,IAAY,cAaX;AAbD,WAAY,cAAc;IACtB,mCAAmC;IACnC,qDAAS,CAAA;IACT,gDAAgD;IAChD,yDAAW,CAAA;IACX,wDAAwD;IACxD,+DAAc,CAAA;IACd,oDAAoD;IACpD,6DAAa,CAAA;IACb,+CAA+C;IAC/C,mDAAQ,CAAA;IACR,iDAAiD;IACjD,uDAAU,CAAA;AACd,CAAC,EAbW,cAAc,KAAd,cAAc,QAazB;AAwED;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAgC;IACzD,YAAY,EAAE,MAAM;IACpB,mBAAmB,EAAE,MAAM;IAC3B,YAAY,EAAE,OAAO;IACrB,YAAY,EAAE,OAAO;IACrB,YAAY,EAAE,OAAO;IACrB,eAAe,EAAE,UAAU;IAC3B,mBAAmB,EAAE,UAAU;IAC/B,mBAAmB,EAAE,MAAM;IAC3B,qBAAqB,EAAE,MAAM;IAC7B,qBAAqB,EAAE,MAAM;CAChC,CAAC;AAEF;;;GAGG;AACH,SAAS,mBAAmB,CAAC,GAAc,EAAE,MAAM,GAAG,KAAK;IACvD,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC;IAC1B,MAA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,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,aAAa,EAAE,kBAAkB,EAAE,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,CAAC,CAAC;AACtH,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file WhatsApp.ts
|
|
3
|
+
* @description Clase principal que gestiona la conexión y eventos de WhatsApp
|
|
4
|
+
*/
|
|
5
|
+
import { type WASocket } from 'baileys';
|
|
6
|
+
import { EventEmitter } from 'node:events';
|
|
7
|
+
import { chat } from './Chat';
|
|
8
|
+
import { contact } from './Contact';
|
|
9
|
+
import { message } from './Message';
|
|
10
|
+
import { type Engine } from './store';
|
|
11
|
+
/**
|
|
12
|
+
* @description Opciones de configuración de WhatsApp.
|
|
13
|
+
* WhatsApp configuration options.
|
|
14
|
+
*/
|
|
15
|
+
export interface IWhatsApp {
|
|
16
|
+
/** Motor de almacenamiento personalizado / Custom storage engine */
|
|
17
|
+
engine?: Engine;
|
|
18
|
+
/** Número de teléfono para emparejamiento con código / Phone number for code pairing */
|
|
19
|
+
phone?: string | number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @description Mapa de eventos emitidos por WhatsApp.
|
|
23
|
+
* Map of events emitted by WhatsApp.
|
|
24
|
+
*/
|
|
25
|
+
interface WhatsAppEventMap {
|
|
26
|
+
open: [];
|
|
27
|
+
close: [];
|
|
28
|
+
error: [Error];
|
|
29
|
+
'message:created': [InstanceType<ReturnType<typeof message>>];
|
|
30
|
+
'message:updated': [InstanceType<ReturnType<typeof message>>];
|
|
31
|
+
'message:reacted': [cid: string, mid: string, emoji: string];
|
|
32
|
+
'message:deleted': [cid: string, mid: string];
|
|
33
|
+
'chat:created': [InstanceType<ReturnType<typeof chat>>];
|
|
34
|
+
'chat:updated': [InstanceType<ReturnType<typeof chat>>];
|
|
35
|
+
'chat:pined': [cid: string, pined: number | null];
|
|
36
|
+
'chat:archived': [cid: string, archived: boolean];
|
|
37
|
+
'chat:muted': [cid: string, muted: number | null];
|
|
38
|
+
'chat:deleted': [cid: string];
|
|
39
|
+
'contact:created': [InstanceType<ReturnType<typeof contact>>];
|
|
40
|
+
'contact:updated': [InstanceType<ReturnType<typeof contact>>];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @description
|
|
44
|
+
* Clase principal para gestionar la conexión con WhatsApp.
|
|
45
|
+
* Main class for managing the WhatsApp connection.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const { event, pair, Contact, Chat, Message } = new WhatsApp({ phone: '5491112345678' });
|
|
49
|
+
* event.on('open', () => console.log('Conectado'));
|
|
50
|
+
* await pair((code) => console.log('Código:', code));
|
|
51
|
+
*/
|
|
52
|
+
export declare class WhatsApp {
|
|
53
|
+
private readonly _phone?;
|
|
54
|
+
private _socket;
|
|
55
|
+
readonly engine: Engine;
|
|
56
|
+
readonly event: EventEmitter<WhatsAppEventMap>;
|
|
57
|
+
readonly Contact: ReturnType<typeof contact>;
|
|
58
|
+
readonly Chat: ReturnType<typeof chat>;
|
|
59
|
+
readonly Message: ReturnType<typeof message>;
|
|
60
|
+
constructor(options?: IWhatsApp);
|
|
61
|
+
/**
|
|
62
|
+
* @description Retorna el socket de Baileys (null si no está conectado).
|
|
63
|
+
* Returns the Baileys socket (null if disconnected).
|
|
64
|
+
*/
|
|
65
|
+
get socket(): WASocket | null;
|
|
66
|
+
/**
|
|
67
|
+
* @description Normaliza cualquier identificador (JID, LID, phone) a JID.
|
|
68
|
+
* Normalizes any identifier (JID, LID, phone) to JID format.
|
|
69
|
+
* @param uid Identificador: JID, LID (@lid), o numero de telefono.
|
|
70
|
+
*/
|
|
71
|
+
resolveJID(uid: string): Promise<string | null>;
|
|
72
|
+
/**
|
|
73
|
+
* @description Conecta a WhatsApp.
|
|
74
|
+
* Connects to WhatsApp.
|
|
75
|
+
* - Con phone: callback recibe código de 8 dígitos (una vez)
|
|
76
|
+
* - Sin phone: callback recibe QR como Buffer PNG (periódicamente)
|
|
77
|
+
*/
|
|
78
|
+
pair: (callback: (code: string | Buffer) => void | Promise<void>) => Promise<void>;
|
|
79
|
+
}
|
|
80
|
+
export {};
|