@arcaelas/whatsapp 1.4.0 → 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.
Files changed (41) hide show
  1. package/build/cjs/Chat.d.ts +187 -205
  2. package/build/cjs/Chat.js +151 -274
  3. package/build/cjs/Chat.js.map +1 -1
  4. package/build/cjs/Contact.d.ts +317 -304
  5. package/build/cjs/Contact.js +58 -103
  6. package/build/cjs/Contact.js.map +1 -1
  7. package/build/cjs/Message.d.ts +567 -265
  8. package/build/cjs/Message.js +274 -256
  9. package/build/cjs/Message.js.map +1 -1
  10. package/build/cjs/WhatsApp.d.ts +16 -4
  11. package/build/cjs/WhatsApp.js +77 -79
  12. package/build/cjs/WhatsApp.js.map +1 -1
  13. package/build/cjs/index.d.ts +2 -2
  14. package/build/cjs/store/driver/FileEngine.d.ts +13 -2
  15. package/build/cjs/store/driver/FileEngine.js +15 -19
  16. package/build/cjs/store/driver/FileEngine.js.map +1 -1
  17. package/build/cjs/store/driver/RedisEngine.d.ts +13 -4
  18. package/build/cjs/store/driver/RedisEngine.js +23 -22
  19. package/build/cjs/store/driver/RedisEngine.js.map +1 -1
  20. package/build/cjs/store/engine.d.ts +9 -10
  21. package/build/esm/Chat.d.ts +187 -205
  22. package/build/esm/Chat.js +151 -273
  23. package/build/esm/Chat.js.map +1 -1
  24. package/build/esm/Contact.d.ts +317 -304
  25. package/build/esm/Contact.js +58 -102
  26. package/build/esm/Contact.js.map +1 -1
  27. package/build/esm/Message.d.ts +567 -265
  28. package/build/esm/Message.js +275 -256
  29. package/build/esm/Message.js.map +1 -1
  30. package/build/esm/WhatsApp.d.ts +16 -4
  31. package/build/esm/WhatsApp.js +80 -82
  32. package/build/esm/WhatsApp.js.map +1 -1
  33. package/build/esm/index.d.ts +2 -2
  34. package/build/esm/store/driver/FileEngine.d.ts +13 -2
  35. package/build/esm/store/driver/FileEngine.js +15 -19
  36. package/build/esm/store/driver/FileEngine.js.map +1 -1
  37. package/build/esm/store/driver/RedisEngine.d.ts +13 -4
  38. package/build/esm/store/driver/RedisEngine.js +23 -22
  39. package/build/esm/store/driver/RedisEngine.js.map +1 -1
  40. package/build/esm/store/engine.d.ts +9 -10
  41. package/package.json +2 -2
@@ -5,30 +5,31 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.Message = exports.MESSAGE_TYPE_MAP = exports.MESSAGE_STATUS = void 0;
8
- exports.build_message_index = build_message_index;
9
8
  exports.message = message;
10
9
  const baileys_1 = require("baileys");
11
10
  const node_stream_1 = require("node:stream");
12
11
  /**
13
12
  * @description Estados de un mensaje.
13
+ * Message delivery statuses.
14
14
  */
15
15
  var MESSAGE_STATUS;
16
16
  (function (MESSAGE_STATUS) {
17
- /** Error al enviar */
17
+ /** Error al enviar / Send error */
18
18
  MESSAGE_STATUS[MESSAGE_STATUS["ERROR"] = 0] = "ERROR";
19
- /** Mensaje pendiente de envío */
19
+ /** Mensaje pendiente de envío / Pending send */
20
20
  MESSAGE_STATUS[MESSAGE_STATUS["PENDING"] = 1] = "PENDING";
21
- /** Servidor recibió el mensaje */
21
+ /** Servidor recibió el mensaje / Server acknowledged */
22
22
  MESSAGE_STATUS[MESSAGE_STATUS["SERVER_ACK"] = 2] = "SERVER_ACK";
23
- /** Mensaje entregado al destinatario */
23
+ /** Mensaje entregado al destinatario / Delivered */
24
24
  MESSAGE_STATUS[MESSAGE_STATUS["DELIVERED"] = 3] = "DELIVERED";
25
- /** Mensaje leído por el destinatario */
25
+ /** Mensaje leído por el destinatario / Read */
26
26
  MESSAGE_STATUS[MESSAGE_STATUS["READ"] = 4] = "READ";
27
- /** Mensaje reproducido (audio/video) */
27
+ /** Mensaje reproducido (audio/video) / Played */
28
28
  MESSAGE_STATUS[MESSAGE_STATUS["PLAYED"] = 5] = "PLAYED";
29
29
  })(MESSAGE_STATUS || (exports.MESSAGE_STATUS = MESSAGE_STATUS = {}));
30
30
  /**
31
31
  * @description Mapeo de tipos de contenido de Baileys a MessageType.
32
+ * Baileys content type to MessageType mapping.
32
33
  */
33
34
  exports.MESSAGE_TYPE_MAP = {
34
35
  conversation: 'text',
@@ -44,41 +45,33 @@ exports.MESSAGE_TYPE_MAP = {
44
45
  };
45
46
  /**
46
47
  * @description Construye IMessageIndex desde WAMessage.
47
- * @param raw WAMessage del protocolo.
48
- * @param edited Si el mensaje fue editado.
49
- * @returns IMessageIndex normalizado.
48
+ * Builds IMessageIndex from WAMessage.
50
49
  */
51
50
  function build_message_index(raw, edited = false) {
51
+ const key = raw.key ?? {};
52
52
  const content_type = (0, baileys_1.getContentType)(raw.message ?? {});
53
53
  const msg_type = exports.MESSAGE_TYPE_MAP[content_type ?? ''] ?? 'text';
54
54
  const msg_content = raw.message?.[content_type];
55
55
  const context_info = msg_content?.contextInfo;
56
- // Calcular MIME
56
+ const ephemeral_duration = raw.ephemeralDuration ?? context_info?.expiration;
57
+ const deleted_at = raw.ephemeralStartTimestamp && ephemeral_duration ? (Number(raw.ephemeralStartTimestamp) + ephemeral_duration) * 1000 : null;
57
58
  let mime = 'text/plain';
58
- if (msg_type === 'location' || msg_type === 'poll') {
59
+ if (msg_type === 'location' || msg_type === 'poll')
59
60
  mime = 'application/json';
60
- }
61
- else if (msg_type !== 'text' && typeof msg_content === 'object') {
61
+ else if (msg_type !== 'text' && typeof msg_content === 'object')
62
62
  mime = msg_content?.mimetype ?? 'application/octet-stream';
63
- }
64
- // Calcular caption
65
63
  let caption = '';
66
- if (typeof msg_content === 'string') {
64
+ if (typeof msg_content === 'string')
67
65
  caption = msg_content;
68
- }
69
- else if (msg_content) {
66
+ else if (msg_content)
70
67
  caption = msg_content.caption ?? msg_content.text ?? msg_content.name ?? '';
71
- }
72
- // Calcular deleted_at
73
- const ephemeral_duration = raw.ephemeralDuration ?? context_info?.expiration;
74
- const deleted_at = raw.ephemeralStartTimestamp && ephemeral_duration ? (Number(raw.ephemeralStartTimestamp) + ephemeral_duration) * 1000 : null;
75
68
  return {
76
- id: raw.key.id,
77
- cid: raw.key.remoteJid,
69
+ id: key.id ?? '',
70
+ cid: key.remoteJid ?? '',
78
71
  mid: context_info?.stanzaId ?? null,
79
- me: raw.key.fromMe ?? false,
72
+ me: key.fromMe ?? false,
80
73
  type: msg_type,
81
- author: raw.key.participant ?? raw.key.remoteJid,
74
+ author: key.participant ?? key.remoteJid ?? '',
82
75
  status: raw.status ?? MESSAGE_STATUS.PENDING,
83
76
  starred: raw.starred ?? false,
84
77
  forwarded: context_info?.isForwarded ?? false,
@@ -92,79 +85,51 @@ function build_message_index(raw, edited = false) {
92
85
  /**
93
86
  * @description
94
87
  * Clase base para representar un mensaje de WhatsApp.
95
- * Expone getters sobre el índice, raw accesible para operaciones avanzadas.
88
+ * Base class representing a WhatsApp message.
96
89
  */
97
90
  class Message {
98
91
  constructor(data) {
99
92
  this.index = data.index;
100
93
  this.raw = data.raw;
101
94
  }
102
- /** ID único del mensaje */
103
- get id() {
104
- return this.index.id;
105
- }
106
- /** JID del chat al que pertenece */
107
- get cid() {
108
- return this.index.cid;
109
- }
110
- /** ID del mensaje padre (reply) */
111
- get mid() {
112
- return this.index.mid;
113
- }
114
- /** true si el mensaje fue enviado por el usuario autenticado */
115
- get me() {
116
- return this.index.me;
117
- }
118
- /** Autor del mensaje */
119
- get author() {
120
- return this.index.author;
121
- }
122
- /** true si el mensaje fue editado */
123
- get edited() {
124
- return this.index.edited;
125
- }
126
- /** Tipo de contenido del mensaje */
127
- get type() {
128
- return this.index.type;
129
- }
130
- /** Texto o caption del mensaje */
131
- get caption() {
132
- return this.index.caption;
133
- }
134
- /** Tipo MIME del contenido */
135
- get mime() {
136
- return this.index.mime;
137
- }
138
- /** Estado del mensaje */
139
- get status() {
140
- return this.index.status;
141
- }
142
- /** true si el mensaje está destacado */
143
- get starred() {
144
- return this.index.starred;
145
- }
146
- /** true si el mensaje fue reenviado */
147
- get forwarded() {
148
- return this.index.forwarded;
149
- }
150
- /** Timestamp de creación (ms) */
151
- get created_at() {
152
- return this.index.created_at;
153
- }
154
- /** Timestamp de expiración (ms) o null */
155
- get deleted_at() {
156
- return this.index.deleted_at;
157
- }
95
+ /** ID único del mensaje / Unique message ID */
96
+ get id() { return this.index.id; }
97
+ /** JID del chat al que pertenece / Chat JID */
98
+ get cid() { return this.index.cid; }
99
+ /** ID del mensaje padre (reply) / Parent message ID (reply) */
100
+ get mid() { return this.index.mid; }
101
+ /** true si el mensaje fue enviado por el usuario autenticado / true if sent by authenticated user */
102
+ get me() { return this.index.me; }
103
+ /** Autor del mensaje / Message author */
104
+ get author() { return this.index.author; }
105
+ /** true si el mensaje fue editado / true if edited */
106
+ get edited() { return this.index.edited; }
107
+ /** Tipo de contenido del mensaje / Message content type */
108
+ get type() { return this.index.type; }
109
+ /** Texto o caption del mensaje / Message text or caption */
110
+ get caption() { return this.index.caption; }
111
+ /** Tipo MIME del contenido / Content MIME type */
112
+ get mime() { return this.index.mime; }
113
+ /** Estado del mensaje / Message status */
114
+ get status() { return this.index.status; }
115
+ /** true si el mensaje está destacado / true if starred */
116
+ get starred() { return this.index.starred; }
117
+ /** true si el mensaje fue reenviado / true if forwarded */
118
+ get forwarded() { return this.index.forwarded; }
119
+ /** Timestamp de creación (ms) / Creation timestamp (ms) */
120
+ get created_at() { return this.index.created_at; }
121
+ /** Timestamp de expiración (ms) o null / Expiration timestamp (ms) or null */
122
+ get deleted_at() { return this.index.deleted_at; }
158
123
  /**
159
124
  * @description Obtiene el contenido como Readable stream.
160
- * @returns Readable stream (vacío en clase base).
125
+ * Gets content as Readable stream.
161
126
  */
162
127
  stream() {
163
128
  return Promise.resolve(node_stream_1.Readable.from(Buffer.alloc(0)));
164
129
  }
165
130
  /**
166
131
  * @description Obtiene el contenido del mensaje como Buffer.
167
- * @returns Buffer con el contenido (vacío en clase base).
132
+ * Gets message content as Buffer.
168
133
  */
169
134
  content() {
170
135
  return Promise.resolve(Buffer.alloc(0));
@@ -173,122 +138,239 @@ class Message {
173
138
  exports.Message = Message;
174
139
  /**
175
140
  * @description Factory que retorna la clase Message enlazada al contexto.
141
+ * Factory that returns the Message class bound to context.
176
142
  * @param wa Instancia de WhatsApp.
177
- * @returns Clase _Message que extiende Message.
178
143
  */
179
144
  function message(wa) {
180
- /** Subscribers para watch() */
181
145
  const _watchers = new Map();
182
- /** Función interna para envío de mensajes */
183
- async function _send(cid, content, binary) {
184
- if (!wa.socket)
146
+ /**
147
+ * @description Agrega un mensaje al índice del chat (interno).
148
+ * Adds a message to the chat index (internal).
149
+ */
150
+ async function _add_to_index(cid, mid, timestamp) {
151
+ const key = `chat/${cid}/messages`;
152
+ const line = `${timestamp} ${mid}`;
153
+ const current = await wa.engine.get(key);
154
+ await wa.engine.set(key, current ? `${line}\n${current}` : line);
155
+ }
156
+ /**
157
+ * @description Elimina un mensaje del índice del chat (interno).
158
+ * Removes a message from the chat index (internal).
159
+ */
160
+ async function _remove_from_index(cid, mid) {
161
+ const key = `chat/${cid}/messages`;
162
+ const content = await wa.engine.get(key);
163
+ if (!content)
164
+ return;
165
+ const filtered = content.trim().split('\n').filter((line) => !line.endsWith(` ${mid}`)).join('\n');
166
+ await wa.engine.set(key, filtered || null);
167
+ }
168
+ /**
169
+ * @description Notifica a los watchers de un mensaje (interno).
170
+ * Notifies message watchers (internal).
171
+ */
172
+ function _notify(cid, mid) {
173
+ const handlers = _watchers.get(`${cid}:${mid}`);
174
+ handlers?.forEach((h) => _Message.get(cid, mid).then((msg) => msg && h(msg)));
175
+ }
176
+ async function _send(cid, content, binary, reply_to) {
177
+ const jid = await wa.resolveJID(cid);
178
+ if (!jid || !wa.socket)
185
179
  return null;
186
- const raw = await wa.socket.sendMessage(cid, content);
187
- if (!raw?.key?.id)
180
+ let quoted;
181
+ if (reply_to) {
182
+ const ref = await _Message.get(jid, reply_to);
183
+ if (ref)
184
+ quoted = ref.raw;
185
+ }
186
+ const raw = await wa.socket.sendMessage(jid, { ...content, ...(quoted && { quoted }) });
187
+ const sent_id = raw?.key?.id;
188
+ if (!raw || !sent_id)
188
189
  return null;
189
190
  const index = build_message_index(raw);
190
- await wa.engine.set(`chat/${cid}/message/${raw.key.id}/index`, JSON.stringify(index, baileys_1.BufferJSON.replacer));
191
- await wa.engine.set(`chat/${cid}/message/${raw.key.id}/raw`, JSON.stringify(raw, baileys_1.BufferJSON.replacer));
191
+ await wa.engine.set(`chat/${jid}/message/${sent_id}/index`, JSON.stringify(index, baileys_1.BufferJSON.replacer));
192
+ await wa.engine.set(`chat/${jid}/message/${sent_id}/raw`, JSON.stringify(raw, baileys_1.BufferJSON.replacer));
192
193
  if (binary)
193
- await wa.engine.set(`chat/${cid}/message/${raw.key.id}/content`, binary.toString('base64'));
194
- await wa.Chat.add_message(cid, raw.key.id, index.created_at);
194
+ await wa.engine.set(`chat/${jid}/message/${sent_id}/content`, binary.toString('base64'));
195
+ await _add_to_index(jid, sent_id, index.created_at);
195
196
  return new _Message({ index, raw });
196
197
  }
197
198
  const _Message = class extends Message {
198
199
  /**
199
200
  * @description Obtiene un mensaje por CID y MID.
200
- * @param cid ID del chat.
201
- * @param mid ID del mensaje.
202
- * @returns Mensaje o null si no existe.
201
+ * Retrieves a message by CID and MID.
203
202
  */
204
203
  static async get(cid, mid) {
205
- const stored_index = await wa.engine.get(`chat/${cid}/message/${mid}/index`);
204
+ const jid = await wa.resolveJID(cid);
205
+ if (!jid)
206
+ return null;
207
+ const stored_index = await wa.engine.get(`chat/${jid}/message/${mid}/index`);
206
208
  if (!stored_index)
207
209
  return null;
208
210
  const index = JSON.parse(stored_index, baileys_1.BufferJSON.reviver);
209
- // Obtener raw si existe
210
- const stored_raw = await wa.engine.get(`chat/${cid}/message/${mid}/raw`);
211
- const raw = stored_raw ? JSON.parse(stored_raw, baileys_1.BufferJSON.reviver) : { key: { remoteJid: cid, id: mid, fromMe: index.me } };
211
+ const stored_raw = await wa.engine.get(`chat/${jid}/message/${mid}/raw`);
212
+ const raw = stored_raw ? JSON.parse(stored_raw, baileys_1.BufferJSON.reviver) : { key: { remoteJid: jid, id: mid, fromMe: index.me } };
212
213
  return new _Message({ index, raw });
213
214
  }
214
215
  /**
215
- * @description Reacciona a un mensaje.
216
- * @param cid ID del chat.
217
- * @param mid ID del mensaje.
218
- * @param emoji Emoji de reacción (vacío para quitar).
219
- * @returns true si se envió correctamente.
216
+ * @description Lista mensajes de un chat (paginado).
217
+ * Lists messages from a chat (paginated).
220
218
  */
221
- static async react(cid, mid, emoji) {
222
- if (!wa.socket)
223
- return false;
224
- const msg = await _Message.get(cid, mid);
225
- if (!msg)
219
+ static async list(cid, offset = 0, limit = 50) {
220
+ const jid = await wa.resolveJID(cid);
221
+ if (!jid)
222
+ return [];
223
+ const content = await wa.engine.get(`chat/${jid}/messages`);
224
+ if (!content)
225
+ return [];
226
+ const ids = content.trim().split('\n').slice(offset, offset + limit).map((line) => line.split(' ')[1]).filter(Boolean);
227
+ const messages = [];
228
+ for (const mid of ids) {
229
+ const msg = await _Message.get(jid, mid);
230
+ if (msg)
231
+ messages.push(msg);
232
+ }
233
+ return messages;
234
+ }
235
+ /**
236
+ * @description Cuenta mensajes de un chat.
237
+ * Counts messages in a chat.
238
+ */
239
+ static async count(cid) {
240
+ const jid = await wa.resolveJID(cid);
241
+ if (!jid)
242
+ return 0;
243
+ const content = await wa.engine.get(`chat/${jid}/messages`);
244
+ if (!content)
245
+ return 0;
246
+ return content.trim().split('\n').filter(Boolean).length;
247
+ }
248
+ /**
249
+ * @description Envía un mensaje de texto.
250
+ * Sends a text message.
251
+ */
252
+ static async text(cid, text, mid) {
253
+ return _send(cid, { text }, undefined, mid);
254
+ }
255
+ /**
256
+ * @description Envía una imagen.
257
+ * Sends an image.
258
+ */
259
+ static async image(cid, buffer, caption, mid) {
260
+ return _send(cid, { image: buffer, caption }, buffer, mid);
261
+ }
262
+ /**
263
+ * @description Envía un video.
264
+ * Sends a video.
265
+ */
266
+ static async video(cid, buffer, caption, mid) {
267
+ return _send(cid, { video: buffer, caption }, buffer, mid);
268
+ }
269
+ /**
270
+ * @description Envía un audio.
271
+ * Sends an audio.
272
+ * @param ptt true para nota de voz (default true) / true for voice note (default true).
273
+ */
274
+ static async audio(cid, buffer, ptt = true, mid) {
275
+ return _send(cid, { audio: buffer, ptt }, buffer, mid);
276
+ }
277
+ /**
278
+ * @description Envía una ubicación.
279
+ * Sends a location.
280
+ */
281
+ static async location(cid, opts, mid) {
282
+ return _send(cid, { location: { degreesLatitude: opts.lat, degreesLongitude: opts.lng } }, undefined, mid);
283
+ }
284
+ /**
285
+ * @description Envía una encuesta.
286
+ * Sends a poll.
287
+ */
288
+ static async poll(cid, opts, mid) {
289
+ return _send(cid, { poll: { name: opts.content, values: opts.options.map((o) => o.content), selectableCount: 1 } }, undefined, mid);
290
+ }
291
+ /**
292
+ * @description Observa cambios en un mensaje específico.
293
+ * Watches changes on a specific message.
294
+ * @returns Función para dejar de observar / Unsubscribe function.
295
+ */
296
+ static watch(cid, mid, handler) {
297
+ const key = `${cid}:${mid}`;
298
+ if (!_watchers.has(key))
299
+ _watchers.set(key, new Set());
300
+ _watchers.get(key)?.add(handler);
301
+ return () => {
302
+ _watchers.get(key)?.delete(handler);
303
+ if (_watchers.get(key)?.size === 0)
304
+ _watchers.delete(key);
305
+ };
306
+ }
307
+ /**
308
+ * @description Edita el mensaje (solo texto o caption, solo mensajes propios).
309
+ * Edits the message (text or caption only, own messages only).
310
+ */
311
+ async edit(text) {
312
+ if (!wa.socket || !this.me)
226
313
  return false;
227
- await wa.socket.sendMessage(cid, {
228
- react: { text: emoji, key: { remoteJid: cid, id: mid, fromMe: msg.me } },
314
+ await wa.socket.sendMessage(this.cid, {
315
+ text,
316
+ edit: { remoteJid: this.cid, id: this.id, fromMe: true },
229
317
  });
318
+ const content_type = (0, baileys_1.getContentType)(this.raw.message ?? {});
319
+ if (content_type === 'conversation') {
320
+ this.raw.message = { conversation: text };
321
+ }
322
+ else if (content_type === 'extendedTextMessage') {
323
+ this.raw.message = { extendedTextMessage: { text } };
324
+ }
325
+ this.index.caption = text;
326
+ this.index.edited = true;
327
+ await wa.engine.set(`chat/${this.cid}/message/${this.id}/index`, JSON.stringify(this.index, baileys_1.BufferJSON.replacer));
328
+ await wa.engine.set(`chat/${this.cid}/message/${this.id}/raw`, JSON.stringify(this.raw, baileys_1.BufferJSON.replacer));
230
329
  return true;
231
330
  }
232
331
  /**
233
- * @description Elimina un mensaje para todos.
234
- * @param cid ID del chat.
235
- * @param mid ID del mensaje.
236
- * @returns true si se eliminó correctamente.
332
+ * @description Elimina el mensaje para todos.
333
+ * Deletes the message for everyone.
237
334
  */
238
- static async remove(cid, mid) {
335
+ async remove() {
239
336
  if (!wa.socket)
240
337
  return false;
241
- const msg = await _Message.get(cid, mid);
242
- if (!msg)
243
- return false;
244
- await wa.socket.sendMessage(cid, { delete: { remoteJid: cid, id: mid, fromMe: msg.me } });
245
- // Eliminar del índice del chat
246
- await wa.Chat.remove_message(cid, mid);
247
- // Eliminar archivos
248
- await wa.engine.set(`chat/${cid}/message/${mid}/index`, null);
249
- await wa.engine.set(`chat/${cid}/message/${mid}/content`, null);
250
- await wa.engine.set(`chat/${cid}/message/${mid}/raw`, null);
338
+ await wa.socket.sendMessage(this.cid, { delete: { remoteJid: this.cid, id: this.id, fromMe: this.me } });
339
+ await _remove_from_index(this.cid, this.id);
340
+ await wa.engine.set(`chat/${this.cid}/message/${this.id}`, null);
251
341
  return true;
252
342
  }
253
343
  /**
254
- * @description Reenvía un mensaje a otro chat.
255
- * @param cid ID del chat origen.
256
- * @param mid ID del mensaje.
257
- * @param to_cid ID del chat destino.
258
- * @returns true si se reenvió correctamente.
344
+ * @description Reenvía el mensaje a otro chat.
345
+ * Forwards the message to another chat.
259
346
  */
260
- static async forward(cid, mid, to_cid) {
347
+ async forward(to_cid) {
261
348
  if (!wa.socket)
262
349
  return false;
263
- const msg = await _Message.get(cid, mid);
264
- if (!msg)
265
- return false;
266
- // Forward nativo con raw
267
- if (msg.raw.message) {
350
+ if (this.raw.message) {
268
351
  try {
269
- const wa_msg = (0, baileys_1.generateWAMessageFromContent)(to_cid, (0, baileys_1.generateForwardMessageContent)(msg.raw, false), { userJid: wa.socket.user?.id ?? '' });
352
+ const wa_msg = (0, baileys_1.generateWAMessageFromContent)(to_cid, (0, baileys_1.generateForwardMessageContent)(this.raw, false), { userJid: wa.socket.user?.id ?? '' });
353
+ if (!wa_msg.message || !wa_msg.key?.id)
354
+ return false;
270
355
  await wa.socket.relayMessage(to_cid, wa_msg.message, { messageId: wa_msg.key.id });
271
356
  return true;
272
357
  }
273
- catch {
274
- // Fallback si falla el forward nativo
275
- }
358
+ catch { /* fallback below */ }
276
359
  }
277
- // Fallback: obtener contenido y reenviar
278
- const content = await msg.content();
279
- if (!content.length)
360
+ const buf = await this.content();
361
+ if (!buf.length)
280
362
  return false;
281
- if (msg.type === 'text')
282
- return (await _Message.text(to_cid, content.toString())) !== null;
283
- if (msg.type === 'image')
284
- return (await _Message.image(to_cid, content, msg.caption || undefined)) !== null;
285
- if (msg.type === 'video')
286
- return (await _Message.video(to_cid, content, msg.caption || undefined)) !== null;
287
- if (msg.type === 'audio')
288
- return (await _Message.audio(to_cid, content)) !== null;
289
- if (msg.type === 'location') {
363
+ if (this.type === 'text')
364
+ return (await _Message.text(to_cid, buf.toString())) !== null;
365
+ if (this.type === 'image')
366
+ return (await _Message.image(to_cid, buf, this.caption || undefined)) !== null;
367
+ if (this.type === 'video')
368
+ return (await _Message.video(to_cid, buf, this.caption || undefined)) !== null;
369
+ if (this.type === 'audio')
370
+ return (await _Message.audio(to_cid, buf)) !== null;
371
+ if (this.type === 'location') {
290
372
  try {
291
- return (await _Message.location(to_cid, JSON.parse(content.toString()))) !== null;
373
+ return (await _Message.location(to_cid, JSON.parse(buf.toString()))) !== null;
292
374
  }
293
375
  catch {
294
376
  return false;
@@ -297,126 +379,63 @@ function message(wa) {
297
379
  return false;
298
380
  }
299
381
  /**
300
- * @description Edita un mensaje (solo texto o caption).
301
- * @param cid ID del chat.
302
- * @param mid ID del mensaje.
303
- * @param text Nuevo contenido.
304
- * @returns true si se editó correctamente.
382
+ * @description Reacciona al mensaje.
383
+ * Reacts to the message.
384
+ * @param emoji Emoji de reacción (vacío para quitar) / Reaction emoji (empty to remove).
305
385
  */
306
- static async edit(cid, mid, text) {
386
+ async react(emoji) {
307
387
  if (!wa.socket)
308
388
  return false;
309
- const msg = await _Message.get(cid, mid);
310
- if (!msg?.me)
311
- return false;
312
- await wa.socket.sendMessage(cid, {
313
- text,
314
- edit: { remoteJid: cid, id: mid, fromMe: true },
389
+ await wa.socket.sendMessage(this.cid, {
390
+ react: { text: emoji, key: { remoteJid: this.cid, id: this.id, fromMe: this.me } },
315
391
  });
316
- // Actualizar el mensaje almacenado con el nuevo contenido
317
- const content_type = (0, baileys_1.getContentType)(msg.raw.message ?? {});
318
- if (content_type === 'conversation') {
319
- msg.raw.message = { conversation: text };
320
- }
321
- else if (content_type === 'extendedTextMessage') {
322
- msg.raw.message = { extendedTextMessage: { text } };
323
- }
324
- // Actualizar índice
325
- msg.index.caption = text;
326
- msg.index.edited = true;
327
- await wa.engine.set(`chat/${cid}/message/${mid}/index`, JSON.stringify(msg.index, baileys_1.BufferJSON.replacer));
328
- await wa.engine.set(`chat/${cid}/message/${mid}/raw`, JSON.stringify(msg.raw, baileys_1.BufferJSON.replacer));
329
392
  return true;
330
393
  }
331
394
  /**
332
- * @description Envía un mensaje de texto.
333
- * @param cid ID del chat destino.
334
- * @param text Contenido del mensaje.
335
- * @returns Mensaje enviado o null.
395
+ * @description Responde con un mensaje de texto.
396
+ * Replies with a text message.
336
397
  */
337
- static async text(cid, text) {
338
- return _send(cid, { text });
398
+ async text(content) {
399
+ return _Message.text(this.cid, content, this.id);
339
400
  }
340
401
  /**
341
- * @description Envía una imagen.
342
- * @param cid ID del chat destino.
343
- * @param buffer Buffer de la imagen.
344
- * @param caption Caption opcional.
345
- * @returns Mensaje enviado o null.
402
+ * @description Responde con una imagen.
403
+ * Replies with an image.
346
404
  */
347
- static async image(cid, buffer, caption) {
348
- return _send(cid, { image: buffer, caption }, buffer);
405
+ async image(buffer, caption) {
406
+ return _Message.image(this.cid, buffer, caption, this.id);
349
407
  }
350
408
  /**
351
- * @description Envía un video.
352
- * @param cid ID del chat destino.
353
- * @param buffer Buffer del video.
354
- * @param caption Caption opcional.
355
- * @returns Mensaje enviado o null.
409
+ * @description Responde con un video.
410
+ * Replies with a video.
356
411
  */
357
- static async video(cid, buffer, caption) {
358
- return _send(cid, { video: buffer, caption }, buffer);
412
+ async video(buffer, caption) {
413
+ return _Message.video(this.cid, buffer, caption, this.id);
359
414
  }
360
415
  /**
361
- * @description Envía un audio.
362
- * @param cid ID del chat destino.
363
- * @param buffer Buffer del audio.
364
- * @param ptt true para nota de voz (default true).
365
- * @returns Mensaje enviado o null.
416
+ * @description Responde con un audio.
417
+ * Replies with an audio.
366
418
  */
367
- static async audio(cid, buffer, ptt = true) {
368
- return _send(cid, { audio: buffer, ptt }, buffer);
419
+ async audio(buffer, ptt = true) {
420
+ return _Message.audio(this.cid, buffer, ptt, this.id);
369
421
  }
370
422
  /**
371
- * @description Envía una ubicación.
372
- * @param cid ID del chat destino.
373
- * @param opts Opciones de ubicación (lat, lng, live).
374
- * @returns Mensaje enviado o null.
423
+ * @description Responde con una ubicacion.
424
+ * Replies with a location.
375
425
  */
376
- static async location(cid, opts) {
377
- return _send(cid, { location: { degreesLatitude: opts.lat, degreesLongitude: opts.lng } });
378
- }
379
- /**
380
- * @description Envía una encuesta.
381
- * @param cid ID del chat destino.
382
- * @param opts Opciones de encuesta (content, options).
383
- * @returns Mensaje enviado o null.
384
- */
385
- static async poll(cid, opts) {
386
- return _send(cid, { poll: { name: opts.content, values: opts.options.map((o) => o.content), selectableCount: 1 } });
387
- }
388
- /**
389
- * @description Observa cambios en un mensaje específico.
390
- * @param cid ID del chat.
391
- * @param mid ID del mensaje.
392
- * @param handler Callback con el mensaje actualizado.
393
- * @returns Función para dejar de observar.
394
- */
395
- static watch(cid, mid, handler) {
396
- const key = `${cid}:${mid}`;
397
- if (!_watchers.has(key))
398
- _watchers.set(key, new Set());
399
- _watchers.get(key).add(handler);
400
- return () => {
401
- _watchers.get(key)?.delete(handler);
402
- if (_watchers.get(key)?.size === 0)
403
- _watchers.delete(key);
404
- };
426
+ async location(opts) {
427
+ return _Message.location(this.cid, opts, this.id);
405
428
  }
406
429
  /**
407
- * @description Notifica a los watchers de un mensaje.
408
- * @param cid ID del chat.
409
- * @param mid ID del mensaje.
430
+ * @description Responde con una encuesta.
431
+ * Replies with a poll.
410
432
  */
411
- static notify(cid, mid) {
412
- const handlers = _watchers.get(`${cid}:${mid}`);
413
- handlers?.forEach((h) => _Message.get(cid, mid).then((msg) => msg && h(msg)));
433
+ async poll(opts) {
434
+ return _Message.poll(this.cid, opts, this.id);
414
435
  }
415
436
  /**
416
437
  * @description Obtiene el contenido como Readable stream.
417
- * Para media (image/video/audio) retorna stream directo de Baileys sin cargar en memoria.
418
- * Para text/location/poll retorna stream desde buffer pequeño.
419
- * @returns Readable stream con el contenido.
438
+ * Gets content as Readable stream.
420
439
  */
421
440
  async stream() {
422
441
  if (this.type === 'text') {
@@ -442,8 +461,7 @@ function message(wa) {
442
461
  }
443
462
  /**
444
463
  * @description Obtiene el contenido del mensaje como Buffer.
445
- * Usa stream() internamente y cachea el resultado en el engine.
446
- * @returns Buffer con el contenido.
464
+ * Gets message content as Buffer.
447
465
  */
448
466
  async content() {
449
467
  const cached = await wa.engine.get(`chat/${this.cid}/message/${this.id}/content`);
@@ -460,6 +478,6 @@ function message(wa) {
460
478
  return buffer;
461
479
  }
462
480
  };
463
- return _Message;
481
+ return Object.assign(_Message, { _add_to_index, _remove_from_index, _notify, _build_index: build_message_index });
464
482
  }
465
483
  //# sourceMappingURL=Message.js.map