@arcaelas/whatsapp 6.2.0 → 7.0.1

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 (42) hide show
  1. package/README.md +19 -15
  2. package/build/cjs/index.d.ts +9 -5
  3. package/build/cjs/index.js +8 -7
  4. package/build/cjs/lib/bot/decorator.d.ts +2 -9
  5. package/build/cjs/lib/bot/decorator.js +0 -1
  6. package/build/cjs/lib/bot/decorators.d.ts +48 -4
  7. package/build/cjs/lib/bot/decorators.js +2 -2
  8. package/build/cjs/lib/chat/index.d.ts +132 -152
  9. package/build/cjs/lib/chat/index.js +138 -219
  10. package/build/cjs/lib/contact/index.d.ts +114 -80
  11. package/build/cjs/lib/contact/index.js +187 -94
  12. package/build/cjs/lib/message/index.d.ts +400 -321
  13. package/build/cjs/lib/message/index.js +425 -913
  14. package/build/cjs/lib/status/index.d.ts +22 -33
  15. package/build/cjs/lib/status/index.js +52 -93
  16. package/build/cjs/lib/store/index.d.ts +16 -0
  17. package/build/cjs/lib/store/index.js +29 -3
  18. package/build/cjs/lib/whatsapp/index.d.ts +44 -212
  19. package/build/cjs/lib/whatsapp/index.js +483 -1099
  20. package/build/esm/index.d.ts +9 -5
  21. package/build/esm/index.js +6 -4
  22. package/build/esm/lib/bot/decorator.d.ts +2 -9
  23. package/build/esm/lib/bot/decorator.js +1 -1
  24. package/build/esm/lib/bot/decorators.d.ts +48 -4
  25. package/build/esm/lib/bot/decorators.js +2 -2
  26. package/build/esm/lib/chat/index.d.ts +132 -152
  27. package/build/esm/lib/chat/index.js +139 -219
  28. package/build/esm/lib/contact/index.d.ts +114 -80
  29. package/build/esm/lib/contact/index.js +186 -94
  30. package/build/esm/lib/message/index.d.ts +400 -321
  31. package/build/esm/lib/message/index.js +422 -913
  32. package/build/esm/lib/status/index.d.ts +22 -33
  33. package/build/esm/lib/status/index.js +49 -93
  34. package/build/esm/lib/store/index.d.ts +16 -0
  35. package/build/esm/lib/store/index.js +25 -0
  36. package/build/esm/lib/whatsapp/index.d.ts +44 -212
  37. package/build/esm/lib/whatsapp/index.js +486 -1101
  38. package/package.json +1 -1
  39. package/build/cjs/lib/internal.d.ts +0 -40
  40. package/build/cjs/lib/internal.js +0 -38
  41. package/build/esm/lib/internal.d.ts +0 -40
  42. package/build/esm/lib/internal.js +0 -34
@@ -1,32 +1,44 @@
1
1
  /**
2
2
  * @file message/index.ts
3
- * @description Entidad Message — clase base con getters puros y subclases por tipo
4
- * (Text, Image, Video, Audio, Sticker, Document, Location, Poll, VCard, Event);
5
- * `message(wa, raw)` evalúa el tipo y retorna la instancia correcta.
6
- * Message entity — pure-getter base class with per-type subclasses;
7
- * `message(wa, raw)` evaluates the type and returns the right instance.
3
+ * @description Entidad Message — clase base con getters puros y subclases por tipo;
4
+ * `message(init)` devuelve la clase ligada a la sesión con los envíos y lecturas.
5
+ * Message entity pure-getter base class with per-type subclasses; `message(init)`
6
+ * returns the session-bound class with sends and reads.
8
7
  */
9
- import { type WAMessage } from 'baileys';
8
+ import { proto, type WAMessage, type WASocket } from 'baileys';
10
9
  import { Readable } from 'node:stream';
11
- import { Chat } from '../../lib/chat/index.js';
12
- import { Contact } from '../../lib/contact/index.js';
13
- import type { WhatsApp } from '../../lib/whatsapp/index.js';
10
+ import Chat from '../../lib/chat/index.js';
11
+ import type Contact from '../../lib/contact/index.js';
12
+ import { type Engine } from '../../lib/store/index.js';
13
+ import type WhatsApp from '../../lib/whatsapp/index.js';
14
14
  /** Estados legibles indexados por el status numérico de baileys. / Readable states indexed by the baileys numeric status. */
15
15
  declare const STATUS: readonly ["error", "pending", "sent", "delivered", "read", "played"];
16
- type SendExtra = {
16
+ /** Sesión activa que liga la entidad. / Active session binding the entity. */
17
+ type Init = {
18
+ wa: WhatsApp;
19
+ engine: Engine;
20
+ socket: WASocket;
21
+ };
22
+ /** Opciones comunes de envío. / Common send options. */
23
+ type Extra = {
17
24
  mid?: string;
18
25
  once?: boolean;
19
26
  };
20
27
  /**
21
- * Clase base del mensaje: recibe el cliente y el raw, deriva el estado con getters y
22
- * opera contra WhatsApp con sus métodos. Los estáticos reciben el cliente como primer
23
- * argumento (`Message.text(wa, cid, …)`).
24
- * Base message class: receives the client and the raw, derives state via getters and
25
- * operates against WhatsApp with its methods. Statics take the client as their first
26
- * argument (`Message.text(wa, cid, …)`).
28
+ * Mensaje: recibe la sesión y el documento, deriva el estado con getters y opera contra
29
+ * WhatsApp con sus métodos. Los de respuesta citan automáticamente este mensaje.
30
+ * Message: receives the session and the document, derives state via getters and operates
31
+ * against WhatsApp with its methods. Reply methods quote this message automatically.
27
32
  */
28
- export declare class Message {
29
- readonly _wa: WhatsApp;
33
+ export default class Message {
34
+ /** @internal Sesión dueña de la instancia. / Session owning the instance. */
35
+ readonly _init: Init;
36
+ /**
37
+ * @internal Documento persistido. `status`, `created_at` y `deleted_at` guardan los
38
+ * números del protocolo; los getters los presentan legibles.
39
+ * Persisted document. `status`, `created_at` and `deleted_at` keep the protocol numbers;
40
+ * getters expose them readable.
41
+ */
30
42
  readonly _raw: {
31
43
  id: string;
32
44
  cid: string;
@@ -52,149 +64,87 @@ export declare class Message {
52
64
  raw: WAMessage;
53
65
  };
54
66
  /**
55
- * @internal Cliente dueño y documento persistido. `status`, `created_at` y
56
- * `deleted_at` guardan los valores numéricos del protocolo; los getters los
57
- * presentan legibles. `viewed` existe únicamente en los status broadcast (Feed).
58
- * Owner client and persisted document. `status`, `created_at` and `deleted_at`
59
- * keep the protocol numeric values; getters expose them readable. `viewed` only
60
- * exists on status broadcasts (Feed).
67
+ * Recibe la sesión y el documento persistido, o el crudo de baileys: en ese caso el
68
+ * documento se deriva aquí y se despacha la subclase del tipo `new Message(init, raw)`
69
+ * de una encuesta devuelve un `Poll`.
70
+ * Receives the session and the persisted document, or the baileys raw: in that case the
71
+ * document is derived here and the per-type subclass is dispatched — `new Message(init,
72
+ * raw)` of a poll returns a `Poll`.
61
73
  */
62
- constructor(_wa: WhatsApp, _raw: {
63
- id: string;
64
- cid: string;
65
- mid: string | null;
66
- me: boolean;
67
- type: 'text' | 'image' | 'video' | 'audio' | 'sticker' | 'document' | 'location' | 'poll' | 'vcard' | 'event';
68
- author: string;
69
- status: number;
70
- starred: boolean;
71
- forwarded: boolean;
72
- created_at: number;
73
- deleted_at: number | null;
74
- mime: string;
75
- caption: string;
76
- edited: boolean;
77
- multiple?: boolean;
78
- reactions?: {
79
- author: string;
80
- emoji: string;
81
- at: number;
82
- }[];
83
- viewed?: boolean | null;
84
- raw: WAMessage;
85
- });
74
+ constructor(init: Init, raw: Message['_raw'] | WAMessage);
86
75
  /** Identificador del mensaje. / Message identifier. */
87
76
  get id(): string;
88
- /** Identificador del chat del mensaje. / Message chat identifier. */
77
+ /** Identificador del chat. / Chat identifier. */
89
78
  get cid(): string;
90
79
  /** Identificador del mensaje citado, o null. / Quoted message identifier, or null. */
91
80
  get mid(): string | null;
92
- /** JID del autor, para acceso síncrono. / Author JID, for sync access. */
81
+ /** JID del autor. / Author JID. */
93
82
  get from(): string;
94
83
  /** true si soy el autor. / true when I am the author. */
95
84
  get me(): boolean;
96
85
  /** Tipo del mensaje. / Message type. */
97
86
  get type(): Message['_raw']['type'];
98
- /** MIME: text/plain en texto, text/json en poll/location/vcard/event, real en media. / MIME: text/plain for text, text/json for poll/location/vcard/event, actual for media. */
99
- get mime(): string;
100
87
  /** Texto del mensaje o caption del media. / Message text or media caption. */
101
88
  get caption(): string;
102
89
  /** Estado legible del mensaje. / Readable message state. */
103
90
  get status(): (typeof STATUS)[number];
104
91
  /** true si el mensaje fue visto. / true when the message was seen. */
105
92
  get read(): boolean;
106
- /** Motivo del rechazo cuando `status` es `error` (`restricted`, `invalid-session`, o el código crudo); null en cualquier otro caso. / Rejection reason when `status` is `error` (`restricted`, `invalid-session`, or the raw code); null otherwise. */
107
- get reason(): string | null;
108
- /** Nombre del negocio verificado que firma el mensaje, o null. / Verified business name signing the message, or null. */
109
- get business(): string | null;
110
93
  /** true si está destacado. / true when starred. */
111
94
  get starred(): boolean;
112
95
  /** true si fue reenviado. / true when forwarded. */
113
96
  get forwarded(): boolean;
114
97
  /** true si fue editado. / true when edited. */
115
98
  get edited(): boolean;
116
- /** true si es de una sola lectura (view-once). / true when view-once. */
117
- get once(): boolean;
118
99
  /** Fecha de creación en ISO UTC. / Creation date as ISO UTC. */
119
100
  get created_at(): string;
120
101
  /** Vencimiento del mensaje temporal en ISO UTC, o null. / Ephemeral expiration as ISO UTC, or null. */
121
102
  get expires_at(): string | null;
122
- /**
123
- * Contacto autor del mensaje, desde el engine (ficha mínima si no está persistido).
124
- * Message author contact, from the engine (minimal card when not persisted).
125
- *
126
- * @returns Contacto / Contact
127
- */
103
+ /** MIME: text/plain en texto, text/json en poll/location/vcard/event, real en media. / MIME: text/plain for text, text/json for poll/location/vcard/event, actual for media. */
104
+ get mime(): string;
105
+ /** Motivo del rechazo cuando `status` es `error` (`restricted`, `invalid-session`, o el código crudo); null si no. / Rejection reason when `status` is `error` (`restricted`, `invalid-session`, or the raw code); null otherwise. */
106
+ get reason(): string | null;
107
+ /** Nombre del negocio verificado que firma el mensaje, o null. / Verified business name signing the message, or null. */
108
+ get business(): string | null;
109
+ /** true si es de una sola lectura (view-once). / true when view-once. */
110
+ get once(): boolean;
111
+ /** Contacto autor, desde el engine (ficha mínima si no está persistido). / Author contact, from the engine (minimal card when not persisted). */
128
112
  author(): Promise<InstanceType<WhatsApp['Contact']>>;
129
- /**
130
- * Chat al que pertenece el mensaje.
131
- * Chat the message belongs to.
132
- *
133
- * @returns Chat / Chat
134
- */
113
+ /** Chat al que pertenece el mensaje. / Chat the message belongs to. */
135
114
  chat(): Promise<InstanceType<WhatsApp['Chat']>>;
136
- /**
137
- * Mensaje citado cuando hay `mid`, o null.
138
- * Quoted message when `mid` exists, or null.
139
- *
140
- * @returns Mensaje citado o null / Quoted message or null
141
- */
115
+ /** Mensaje citado cuando hay `mid`, o null. / Quoted message when `mid` exists, or null. */
142
116
  message(): Promise<Message | null>;
143
- /**
144
- * Contenido del mensaje: texto como su caption, media como binario, y
145
- * poll/location/vcard/event como JSON.
146
- * Message content: text as its caption, media as binary, and
147
- * poll/location/vcard/event as JSON.
148
- *
149
- * @returns Buffer del contenido / Content buffer
150
- */
117
+ /** Contenido persistido: texto, JSON del tipo, o binario del media. / Persisted content: text, per-type JSON, or media binary. */
151
118
  content(): Promise<Buffer>;
152
- /**
153
- * Stream del contenido; para media descarga de baileys si el cache falta.
154
- * Content stream; media falls back to a baileys download when the cache is missing.
155
- *
156
- * @returns Readable del contenido / Content readable
157
- */
119
+ /** Stream del contenido. / Content stream. */
158
120
  stream(): Promise<Readable>;
159
- /**
160
- * Reacciones del mensaje agrupadas por emoji con su conteo.
161
- * Message reactions grouped by emoji with their count.
162
- *
163
- * @returns Conteo por emoji / Per-emoji count
164
- */
121
+ /** Reacciones agrupadas por emoji con su conteo. / Reactions grouped by emoji with their count. */
165
122
  reactions(): Promise<{
166
123
  emoji: string;
167
124
  count: number;
168
125
  }[]>;
169
126
  /**
170
127
  * Reacciona al mensaje; el emoji vacío retira la reacción.
171
- * Reacts to the message; an empty emoji removes the reaction.
128
+ * Reacts to the message; an empty emoji removes it.
172
129
  *
173
130
  * @param emoji - Emoji o '' / Emoji or ''
174
- * @returns true si se envió / true when sent
175
131
  */
176
132
  react(emoji: string): Promise<boolean>;
177
133
  /**
178
- * Destaca o quita el destacado del mensaje.
134
+ * Destaca o quita el destacado.
179
135
  * Stars or unstars the message.
180
136
  *
181
137
  * @param value - true destaca / true stars
182
- * @returns true si se envió / true when sent
183
138
  */
184
139
  star(value: boolean): Promise<boolean>;
185
- /**
186
- * Marca el mensaje como leído.
187
- * Marks the message as read.
188
- *
189
- * @returns true si se envió / true when sent
190
- */
140
+ /** Marca el mensaje como leído. / Marks the message as read. */
191
141
  seen(): Promise<boolean>;
192
142
  /**
193
143
  * Edita el caption del mensaje propio (texto, imagen o video).
194
144
  * Edits the own message caption (text, image or video).
195
145
  *
196
146
  * @param caption - Texto nuevo / New text
197
- * @returns true si se editó / true when edited
147
+ * @returns false si el mensaje no es propio o su tipo no se puede editar / false when not own or its type cannot be edited
198
148
  */
199
149
  edit(caption: string): Promise<boolean>;
200
150
  /**
@@ -202,7 +152,7 @@ export declare class Message {
202
152
  * Forwards the message to another chat.
203
153
  *
204
154
  * @param target - CID, Chat o Contact destino / Target CID, Chat or Contact
205
- * @returns true si se reenvió / true when forwarded
155
+ * @returns false si el destino es irresoluble o el contenido no admite reenvío / false when the target cannot be resolved or the content cannot be forwarded
206
156
  */
207
157
  forward(target: string | Chat | Contact): Promise<boolean>;
208
158
  /**
@@ -210,39 +160,38 @@ export declare class Message {
210
160
  * Deletes the message: this device only by default, for everyone with `true`.
211
161
  *
212
162
  * @param all - true elimina para todos / true deletes for everyone
213
- * @returns true si se eliminó / true when deleted
214
163
  */
215
164
  delete(all?: boolean): Promise<boolean>;
216
165
  /** Responde con texto. / Replies with text. */
217
- text(caption: string, extra?: Omit<SendExtra, 'mid'>): Promise<Message | null>;
166
+ text(caption: string, extra?: Omit<Extra, 'mid'>): Promise<Message | null>;
218
167
  /** Responde con imagen. / Replies with an image. */
219
- image(buf: Buffer, extra?: Omit<SendExtra, 'mid'> & {
168
+ image(buf: Buffer, extra?: Omit<Extra, 'mid'> & {
220
169
  caption?: string;
221
170
  }): Promise<Message | null>;
222
171
  /** Responde con video. / Replies with a video. */
223
- video(buf: Buffer, extra?: Omit<SendExtra, 'mid'> & {
172
+ video(buf: Buffer, extra?: Omit<Extra, 'mid'> & {
224
173
  caption?: string;
225
174
  }): Promise<Message | null>;
226
175
  /** Responde con audio. / Replies with audio. */
227
- audio(buf: Buffer, extra?: Omit<SendExtra, 'mid'> & {
176
+ audio(buf: Buffer, extra?: Omit<Extra, 'mid'> & {
228
177
  ptt?: boolean;
229
178
  }): Promise<Message | null>;
230
179
  /** Responde con ubicación. / Replies with a location. */
231
180
  location(loc: {
232
181
  lat: number;
233
182
  lng: number;
234
- }, extra?: Omit<SendExtra, 'mid'>): Promise<Message | null>;
183
+ }, extra?: Omit<Extra, 'mid'>): Promise<Message | null>;
235
184
  /** Responde con encuesta. / Replies with a poll. */
236
185
  poll(input: {
237
186
  content: string;
238
187
  options: {
239
188
  content: string;
240
189
  }[];
241
- }, extra?: Omit<SendExtra, 'mid'> & {
190
+ }, extra?: Omit<Extra, 'mid'> & {
242
191
  multiple?: boolean;
243
192
  }): Promise<Message | null>;
244
193
  /** Responde con documento. / Replies with a document. */
245
- document(buf: Buffer, extra: Omit<SendExtra, 'mid'> & {
194
+ document(buf: Buffer, extra: Omit<Extra, 'mid'> & {
246
195
  file_name: string;
247
196
  mimetype?: string;
248
197
  caption?: string;
@@ -251,7 +200,7 @@ export declare class Message {
251
200
  vcard(contacts: {
252
201
  name: string;
253
202
  phone: string;
254
- }[], extra?: Omit<SendExtra, 'mid'>): Promise<Message | null>;
203
+ }[], extra?: Omit<Extra, 'mid'>): Promise<Message | null>;
255
204
  /** Responde con evento. / Replies with an event. */
256
205
  event(data: {
257
206
  name: string;
@@ -262,107 +211,14 @@ export declare class Message {
262
211
  lat: number;
263
212
  lng: number;
264
213
  };
265
- }, extra?: Omit<SendExtra, 'mid'>): Promise<Message | null>;
266
- /**
267
- * Obtiene un mensaje por chat y id.
268
- * Retrieves a message by chat and id.
269
- *
270
- * @param wa - Cliente dueño / Owner client
271
- * @param cid - Identificador del chat / Chat identifier
272
- * @param mid - Identificador del mensaje / Message identifier
273
- * @returns Mensaje o null / Message or null
274
- */
275
- static get(wa: WhatsApp, cid: string, mid: string): Promise<Message | null>;
276
- /**
277
- * Pagina los mensajes de un chat desde el más reciente.
278
- * Paginates chat messages from the most recent one.
279
- *
280
- * @param wa - Cliente dueño / Owner client
281
- * @param cid - Identificador del chat / Chat identifier
282
- * @param offset - Desplazamiento / Offset
283
- * @param limit - Tamaño de página / Page size
284
- * @returns Página de mensajes / Message page
285
- */
286
- static list(wa: WhatsApp, cid: string, offset?: number, limit?: number): Promise<Message[]>;
287
- /** Envía texto. / Sends text. */
288
- static text(wa: WhatsApp, cid: string, caption: string, extra?: SendExtra): Promise<Message | null>;
289
- /** Envía imagen. / Sends an image. */
290
- static image(wa: WhatsApp, cid: string, buf: Buffer, extra?: SendExtra & {
291
- caption?: string;
292
- }): Promise<Message | null>;
293
- /** Envía video. / Sends a video. */
294
- static video(wa: WhatsApp, cid: string, buf: Buffer, extra?: SendExtra & {
295
- caption?: string;
296
- }): Promise<Message | null>;
297
- /** Envía audio. / Sends audio. */
298
- static audio(wa: WhatsApp, cid: string, buf: Buffer, extra?: SendExtra & {
299
- ptt?: boolean;
300
- }): Promise<Message | null>;
301
- /** Envía ubicación. / Sends a location. */
302
- static location(wa: WhatsApp, cid: string, loc: {
303
- lat: number;
304
- lng: number;
305
- }, extra?: SendExtra): Promise<Message | null>;
306
- /** Envía encuesta. / Sends a poll. */
307
- static poll(wa: WhatsApp, cid: string, input: {
308
- content: string;
309
- options: {
310
- content: string;
311
- }[];
312
- }, extra?: SendExtra & {
313
- multiple?: boolean;
314
- }): Promise<Message | null>;
315
- /** Envía documento. / Sends a document. */
316
- static document(wa: WhatsApp, cid: string, buf: Buffer, extra: SendExtra & {
317
- file_name: string;
318
- mimetype?: string;
319
- caption?: string;
320
- }): Promise<Message | null>;
321
- /** Envía tarjeta(s) de contacto. / Sends contact card(s). */
322
- static vcard(wa: WhatsApp, cid: string, contacts: {
323
- name: string;
324
- phone: string;
325
- }[], extra?: SendExtra): Promise<Message | null>;
326
- /** Envía evento. / Sends an event. */
327
- static event(wa: WhatsApp, cid: string, data: {
328
- name: string;
329
- caption?: string;
330
- start: Date;
331
- end?: Date;
332
- place?: {
333
- lat: number;
334
- lng: number;
335
- };
336
- }, extra?: SendExtra): Promise<Message | null>;
337
- /** Reacciona a un mensaje por id. / Reacts to a message by id. */
338
- static react(wa: WhatsApp, cid: string, mid: string, emoji: string): Promise<boolean>;
339
- /** Destaca un mensaje por id. / Stars a message by id. */
340
- static star(wa: WhatsApp, cid: string, mid: string, value: boolean): Promise<boolean>;
341
- /** Marca un mensaje como leído por id. / Marks a message as read by id. */
342
- static seen(wa: WhatsApp, cid: string, mid: string): Promise<boolean>;
343
- /** Edita un mensaje por id. / Edits a message by id. */
344
- static edit(wa: WhatsApp, cid: string, mid: string, caption: string): Promise<boolean>;
345
- /** Reenvía un mensaje por id. / Forwards a message by id. */
346
- static forward(wa: WhatsApp, cid: string, mid: string, target: string | Chat | Contact): Promise<boolean>;
347
- /** Elimina un mensaje por id. / Deletes a message by id. */
348
- static delete(wa: WhatsApp, cid: string, mid: string, all?: boolean): Promise<boolean>;
349
- /** Reacciones de un mensaje por id. / Reactions of a message by id. */
350
- static reactions(wa: WhatsApp, cid: string, mid: string): Promise<{
351
- emoji: string;
352
- count: number;
353
- }[]>;
214
+ }, extra?: Omit<Extra, 'mid'>): Promise<Message | null>;
354
215
  }
355
216
  /**
356
217
  * Mensaje de texto; `preview()` expone la tarjeta del enlace embebido.
357
218
  * Text message; `preview()` exposes the embedded link card.
358
219
  */
359
220
  export declare class Text extends Message {
360
- /**
361
- * Preview del enlace del texto, o null cuando no trae metadata.
362
- * Text link preview, or null when it carries no metadata.
363
- *
364
- * @returns { link, name, content, thumb } o null / { link, name, content, thumb } or null
365
- */
221
+ /** Preview del enlace, o null cuando el texto no trae metadata. / Link preview, or null when the text carries no metadata. */
366
222
  preview(): Promise<{
367
223
  link: string;
368
224
  name: string | null;
@@ -371,107 +227,69 @@ export declare class Text extends Message {
371
227
  } | null>;
372
228
  }
373
229
  /**
374
- * Mensaje de imagen: dimensiones, peso y miniatura.
375
- * Image message: dimensions, size and thumbnail.
230
+ * Base de los mensajes con binario: dimensiones, peso, miniatura y descarga.
231
+ * Base for binary messages: dimensions, size, thumbnail and download.
376
232
  */
377
- export declare class Image extends Message {
378
- /** @internal */
379
- private get _media();
233
+ declare class Media extends Message {
234
+ /** @internal Bloque de media del raw, común a los cinco tipos. / Raw media block, shared by the five types. */
235
+ get _media(): {
236
+ width?: number | null;
237
+ height?: number | null;
238
+ seconds?: number | null;
239
+ ptt?: boolean | null;
240
+ isAnimated?: boolean | null;
241
+ fileName?: string | null;
242
+ pageCount?: number | null;
243
+ fileLength?: number | {
244
+ toString(): string;
245
+ } | null;
246
+ waveform?: Uint8Array | string | null;
247
+ jpegThumbnail?: Uint8Array | string | null;
248
+ } | null;
380
249
  /** Ancho en píxeles. / Width in pixels. */
381
250
  get width(): number;
382
251
  /** Alto en píxeles. / Height in pixels. */
383
252
  get height(): number;
384
253
  /** Peso en bytes. / Size in bytes. */
385
254
  get size(): number;
386
- /**
387
- * Miniatura JPEG embebida, o null.
388
- * Embedded JPEG thumbnail, or null.
389
- *
390
- * @returns Buffer de la miniatura o null / Thumbnail buffer or null
391
- */
255
+ /** Miniatura JPEG embebida, o null. / Embedded JPEG thumbnail, or null. */
392
256
  thumb(): Promise<Buffer | null>;
257
+ /** Binario del media: el persistido, o la descarga de baileys. / Media binary: the persisted one, or the baileys download. */
393
258
  content(): Promise<Buffer>;
259
+ /** Stream del media sin acumularlo cuando hay que descargar. / Media stream without buffering when a download is needed. */
260
+ stream(): Promise<Readable>;
394
261
  }
395
- /**
396
- * Mensaje de video: dimensiones, duración, peso y miniatura.
397
- * Video message: dimensions, duration, size and thumbnail.
398
- */
399
- export declare class Video extends Message {
400
- /** @internal */
401
- private get _media();
402
- /** Ancho en píxeles. / Width in pixels. */
403
- get width(): number;
404
- /** Alto en píxeles. / Height in pixels. */
405
- get height(): number;
262
+ /** Mensaje de imagen. / Image message. */
263
+ export declare class Image extends Media {
264
+ }
265
+ /** Mensaje de video. / Video message. */
266
+ export declare class Video extends Media {
406
267
  /** Duración en segundos. / Duration in seconds. */
407
268
  get duration(): number;
408
- /** Peso en bytes. / Size in bytes. */
409
- get size(): number;
410
- /**
411
- * Miniatura JPEG embebida, o null.
412
- * Embedded JPEG thumbnail, or null.
413
- *
414
- * @returns Buffer de la miniatura o null / Thumbnail buffer or null
415
- */
416
- thumb(): Promise<Buffer | null>;
417
- content(): Promise<Buffer>;
418
269
  }
419
- /**
420
- * Mensaje de audio: nota de voz o archivo, con forma de onda del protocolo.
421
- * Audio message: voice note or file, with the protocol waveform.
422
- */
423
- export declare class Audio extends Message {
424
- /** @internal */
425
- private get _media();
270
+ /** Mensaje de audio: nota de voz o archivo. / Audio message: voice note or file. */
271
+ export declare class Audio extends Media {
426
272
  /** true si es nota de voz. / true when push-to-talk. */
427
273
  get ptt(): boolean;
428
274
  /** Duración en segundos. / Duration in seconds. */
429
275
  get duration(): number;
430
- /** Peso en bytes. / Size in bytes. */
431
- get size(): number;
432
276
  /** Forma de onda 0-100 lista para pintar. / Paint-ready 0-100 waveform. */
433
277
  get waveform(): number[];
434
- content(): Promise<Buffer>;
435
278
  }
436
- /**
437
- * Mensaje de sticker: dimensiones, peso y animación.
438
- * Sticker message: dimensions, size and animation.
439
- */
440
- export declare class Sticker extends Message {
441
- /** @internal */
442
- private get _media();
443
- /** Ancho en píxeles. / Width in pixels. */
444
- get width(): number;
445
- /** Alto en píxeles. / Height in pixels. */
446
- get height(): number;
279
+ /** Mensaje de sticker. / Sticker message. */
280
+ export declare class Sticker extends Media {
447
281
  /** true si el sticker es animado. / true when animated. */
448
282
  get animated(): boolean;
449
- /** Peso en bytes. / Size in bytes. */
450
- get size(): number;
451
- content(): Promise<Buffer>;
452
283
  }
453
- /**
454
- * Mensaje de documento; el MIME real vive en `mime` de la base.
455
- * Document message; the actual MIME lives in the base `mime`.
456
- */
457
- export declare class Document extends Message {
458
- /** @internal */
459
- private get _media();
284
+ /** Mensaje de documento; el MIME real vive en `mime`. / Document message; the actual MIME lives in `mime`. */
285
+ export declare class Document extends Media {
460
286
  /** Nombre del archivo. / File name. */
461
287
  get name(): string;
462
288
  /** Número de páginas (PDF); 0 cuando no aplica. / Page count (PDF); 0 when not applicable. */
463
289
  get pages(): number;
464
- /** Peso en bytes. / Size in bytes. */
465
- get size(): number;
466
- content(): Promise<Buffer>;
467
290
  }
468
- /**
469
- * Mensaje de ubicación, fija o en vivo.
470
- * Location message, static or live.
471
- */
291
+ /** Mensaje de ubicación, fija o en vivo. / Location message, static or live. */
472
292
  export declare class Location extends Message {
473
- /** @internal */
474
- private get _loc();
475
293
  /** Latitud en grados. / Latitude in degrees. */
476
294
  get lat(): number;
477
295
  /** Longitud en grados. / Longitude in degrees. */
@@ -486,10 +304,18 @@ export declare class Location extends Message {
486
304
  * Poll message: options with counts, per-contact votes and self-voting.
487
305
  */
488
306
  export declare class Poll extends Message {
489
- /** @internal */
490
- private get _poll();
307
+ /** @internal Bloque de la encuesta en el raw. / Raw poll block. */
308
+ get _poll(): proto.Message.IPollCreationMessage | null | undefined;
491
309
  /** @internal Updates de voto con los bytes normalizados post-engine. / Vote updates with post-engine normalized bytes. */
492
- private get _updates();
310
+ get _updates(): {
311
+ vote: {
312
+ selectedOptions: (Uint8Array<ArrayBufferLike> | Buffer<ArrayBuffer>)[];
313
+ } | null | undefined;
314
+ pollUpdateMessageKey?: (proto.IMessageKey | null);
315
+ senderTimestampMs?: (number | Long | null);
316
+ serverTimestampMs?: (number | Long | null);
317
+ unread?: (boolean | null);
318
+ }[];
493
319
  /** true si admite varias respuestas. / true when multi-select. */
494
320
  get multiple(): boolean;
495
321
  /** Opciones con su conteo de votos. / Options with their vote counts. */
@@ -497,35 +323,25 @@ export declare class Poll extends Message {
497
323
  name: string;
498
324
  count: number;
499
325
  }[];
500
- /**
501
- * Votos individuales: opción elegida y teléfono del votante.
502
- * Individual votes: chosen option and voter phone.
503
- *
504
- * @returns Lista de votos / Vote list
505
- */
326
+ /** Votos individuales: opción elegida y teléfono del votante. / Individual votes: chosen option and voter phone. */
506
327
  votes(): Promise<{
507
328
  name: string;
508
329
  contact: string;
509
330
  }[]>;
510
331
  /**
511
- * Vota en la encuesta con uno o varios índices. Cifra el voto (HMAC+AES-GCM) y lo
512
- * enruta al chat @lid con la identidad LID propia. Best-effort: el voto entrante
513
- * descifra correcto, pero WhatsApp no propaga el voto emitido desde un dispositivo
514
- * vinculado (companion).
515
- * Votes in the poll with one or more indexes. Encrypts the vote (HMAC+AES-GCM) and
516
- * routes it to the @lid chat with the own LID identity. Best-effort: incoming votes
517
- * decrypt fine, but WhatsApp does not propagate votes emitted from a linked
518
- * (companion) device.
332
+ * Vota con uno o varios índices: cifra el voto (HMAC+AES-GCM) y lo enruta al chat @lid
333
+ * con la identidad LID propia. Best-effort: WhatsApp no propaga el voto emitido desde un
334
+ * dispositivo vinculado.
335
+ * Votes with one or more indexes: encrypts the vote (HMAC+AES-GCM) and routes it to the
336
+ * @lid chat with the own LID identity. Best-effort: WhatsApp does not propagate votes
337
+ * emitted from a linked device.
519
338
  *
520
339
  * @param index - Índice o índices de la opción / Option index or indexes
521
340
  * @returns true si el voto se emitió / true when the vote was relayed
522
341
  */
523
342
  select(index: number | number[]): Promise<boolean>;
524
343
  }
525
- /**
526
- * Mensaje de tarjeta(s) de contacto.
527
- * Contact card(s) message.
528
- */
344
+ /** Mensaje de tarjeta(s) de contacto. / Contact card(s) message. */
529
345
  export declare class VCard extends Message {
530
346
  /** Contactos de la tarjeta. / Card contacts. */
531
347
  get contacts(): {
@@ -533,13 +349,10 @@ export declare class VCard extends Message {
533
349
  phone: string;
534
350
  }[];
535
351
  }
536
- /**
537
- * Mensaje de evento de calendario.
538
- * Calendar event message.
539
- */
352
+ /** Mensaje de evento de calendario. / Calendar event message. */
540
353
  export declare class Event extends Message {
541
- /** @internal */
542
- private get _event();
354
+ /** @internal Bloque del evento en el raw. / Raw event block. */
355
+ get _event(): proto.Message.IEventMessage | null | undefined;
543
356
  /** Nombre del evento. / Event name. */
544
357
  get name(): string;
545
358
  /** Inicio en ISO UTC. / Start as ISO UTC. */
@@ -557,16 +370,282 @@ export declare class Event extends Message {
557
370
  } | null;
558
371
  }
559
372
  /**
560
- * Factoría de Message: evalúa el tipo y retorna la instancia de la subclase correcta.
561
- * Acepta el documento persistido o el mensaje crudo de baileys — en ese caso el
562
- * documento se deriva aquí mismo (id, tipo, autor, caption, mime, fechas).
563
- * Message factory: evaluates the type and returns the right subclass instance. Accepts
564
- * the persisted document or the raw baileys message — in that case the document is
565
- * derived right here (id, type, author, caption, mime, dates).
373
+ * Mensaje ligado a la sesión viva: la misma clase con los envíos, las lecturas, las acciones
374
+ * por id y las subclases para `instanceof`.
375
+ * Message bound to the live session: the same class with sends, reads, by-id actions and the
376
+ * subclasses for `instanceof`.
566
377
  *
567
- * @param wa - Instancia principal / Main WhatsApp instance
568
- * @param raw - Documento persistido o WAMessage crudo / Persisted document or raw WAMessage
569
- * @returns Instancia del tipo correcto / Right-type instance
378
+ * @param init - Sesión activa: cliente, motor y socket / Active session: client, engine and socket
379
+ * @returns Clase `Message` con acceso a la sesión / `Message` class with session access
570
380
  */
571
- export declare function message(wa: WhatsApp, raw: Message['_raw'] | WAMessage): Message;
381
+ export declare function message(init: Init): {
382
+ new (init: Init, raw: Message["_raw"] | WAMessage): {
383
+ /** @internal Sesión dueña de la instancia. / Session owning the instance. */
384
+ readonly _init: Init;
385
+ /**
386
+ * @internal Documento persistido. `status`, `created_at` y `deleted_at` guardan los
387
+ * números del protocolo; los getters los presentan legibles.
388
+ * Persisted document. `status`, `created_at` and `deleted_at` keep the protocol numbers;
389
+ * getters expose them readable.
390
+ */
391
+ readonly _raw: {
392
+ id: string;
393
+ cid: string;
394
+ mid: string | null;
395
+ me: boolean;
396
+ type: "text" | "image" | "video" | "audio" | "sticker" | "document" | "location" | "poll" | "vcard" | "event";
397
+ author: string;
398
+ status: number;
399
+ starred: boolean;
400
+ forwarded: boolean;
401
+ created_at: number;
402
+ deleted_at: number | null;
403
+ mime: string;
404
+ caption: string;
405
+ edited: boolean;
406
+ multiple?: boolean;
407
+ reactions?: {
408
+ author: string;
409
+ emoji: string;
410
+ at: number;
411
+ }[];
412
+ viewed?: boolean | null;
413
+ raw: WAMessage;
414
+ };
415
+ /** Identificador del mensaje. / Message identifier. */
416
+ get id(): string;
417
+ /** Identificador del chat. / Chat identifier. */
418
+ get cid(): string;
419
+ /** Identificador del mensaje citado, o null. / Quoted message identifier, or null. */
420
+ get mid(): string | null;
421
+ /** JID del autor. / Author JID. */
422
+ get from(): string;
423
+ /** true si soy el autor. / true when I am the author. */
424
+ get me(): boolean;
425
+ /** Tipo del mensaje. / Message type. */
426
+ get type(): Message["_raw"]["type"];
427
+ /** Texto del mensaje o caption del media. / Message text or media caption. */
428
+ get caption(): string;
429
+ /** Estado legible del mensaje. / Readable message state. */
430
+ get status(): (typeof STATUS)[number];
431
+ /** true si el mensaje fue visto. / true when the message was seen. */
432
+ get read(): boolean;
433
+ /** true si está destacado. / true when starred. */
434
+ get starred(): boolean;
435
+ /** true si fue reenviado. / true when forwarded. */
436
+ get forwarded(): boolean;
437
+ /** true si fue editado. / true when edited. */
438
+ get edited(): boolean;
439
+ /** Fecha de creación en ISO UTC. / Creation date as ISO UTC. */
440
+ get created_at(): string;
441
+ /** Vencimiento del mensaje temporal en ISO UTC, o null. / Ephemeral expiration as ISO UTC, or null. */
442
+ get expires_at(): string | null;
443
+ /** MIME: text/plain en texto, text/json en poll/location/vcard/event, real en media. / MIME: text/plain for text, text/json for poll/location/vcard/event, actual for media. */
444
+ get mime(): string;
445
+ /** Motivo del rechazo cuando `status` es `error` (`restricted`, `invalid-session`, o el código crudo); null si no. / Rejection reason when `status` is `error` (`restricted`, `invalid-session`, or the raw code); null otherwise. */
446
+ get reason(): string | null;
447
+ /** Nombre del negocio verificado que firma el mensaje, o null. / Verified business name signing the message, or null. */
448
+ get business(): string | null;
449
+ /** true si es de una sola lectura (view-once). / true when view-once. */
450
+ get once(): boolean;
451
+ /** Contacto autor, desde el engine (ficha mínima si no está persistido). / Author contact, from the engine (minimal card when not persisted). */
452
+ author(): Promise<InstanceType<WhatsApp["Contact"]>>;
453
+ /** Chat al que pertenece el mensaje. / Chat the message belongs to. */
454
+ chat(): Promise<InstanceType<WhatsApp["Chat"]>>;
455
+ /** Mensaje citado cuando hay `mid`, o null. / Quoted message when `mid` exists, or null. */
456
+ message(): Promise<Message | null>;
457
+ /** Contenido persistido: texto, JSON del tipo, o binario del media. / Persisted content: text, per-type JSON, or media binary. */
458
+ content(): Promise<Buffer>;
459
+ /** Stream del contenido. / Content stream. */
460
+ stream(): Promise<Readable>;
461
+ /** Reacciones agrupadas por emoji con su conteo. / Reactions grouped by emoji with their count. */
462
+ reactions(): Promise<{
463
+ emoji: string;
464
+ count: number;
465
+ }[]>;
466
+ /**
467
+ * Reacciona al mensaje; el emoji vacío retira la reacción.
468
+ * Reacts to the message; an empty emoji removes it.
469
+ *
470
+ * @param emoji - Emoji o '' / Emoji or ''
471
+ */
472
+ react(emoji: string): Promise<boolean>;
473
+ /**
474
+ * Destaca o quita el destacado.
475
+ * Stars or unstars the message.
476
+ *
477
+ * @param value - true destaca / true stars
478
+ */
479
+ star(value: boolean): Promise<boolean>;
480
+ /** Marca el mensaje como leído. / Marks the message as read. */
481
+ seen(): Promise<boolean>;
482
+ /**
483
+ * Edita el caption del mensaje propio (texto, imagen o video).
484
+ * Edits the own message caption (text, image or video).
485
+ *
486
+ * @param caption - Texto nuevo / New text
487
+ * @returns false si el mensaje no es propio o su tipo no se puede editar / false when not own or its type cannot be edited
488
+ */
489
+ edit(caption: string): Promise<boolean>;
490
+ /**
491
+ * Reenvía el mensaje a otro chat.
492
+ * Forwards the message to another chat.
493
+ *
494
+ * @param target - CID, Chat o Contact destino / Target CID, Chat or Contact
495
+ * @returns false si el destino es irresoluble o el contenido no admite reenvío / false when the target cannot be resolved or the content cannot be forwarded
496
+ */
497
+ forward(target: string | Chat | Contact): Promise<boolean>;
498
+ /**
499
+ * Elimina el mensaje: solo en mi dispositivo por defecto, para todos con `true`.
500
+ * Deletes the message: this device only by default, for everyone with `true`.
501
+ *
502
+ * @param all - true elimina para todos / true deletes for everyone
503
+ */
504
+ delete(all?: boolean): Promise<boolean>;
505
+ /** Responde con texto. / Replies with text. */
506
+ text(caption: string, extra?: Omit<Extra, "mid">): Promise<Message | null>;
507
+ /** Responde con imagen. / Replies with an image. */
508
+ image(buf: Buffer, extra?: Omit<Extra, "mid"> & {
509
+ caption?: string;
510
+ }): Promise<Message | null>;
511
+ /** Responde con video. / Replies with a video. */
512
+ video(buf: Buffer, extra?: Omit<Extra, "mid"> & {
513
+ caption?: string;
514
+ }): Promise<Message | null>;
515
+ /** Responde con audio. / Replies with audio. */
516
+ audio(buf: Buffer, extra?: Omit<Extra, "mid"> & {
517
+ ptt?: boolean;
518
+ }): Promise<Message | null>;
519
+ /** Responde con ubicación. / Replies with a location. */
520
+ location(loc: {
521
+ lat: number;
522
+ lng: number;
523
+ }, extra?: Omit<Extra, "mid">): Promise<Message | null>;
524
+ /** Responde con encuesta. / Replies with a poll. */
525
+ poll(input: {
526
+ content: string;
527
+ options: {
528
+ content: string;
529
+ }[];
530
+ }, extra?: Omit<Extra, "mid"> & {
531
+ multiple?: boolean;
532
+ }): Promise<Message | null>;
533
+ /** Responde con documento. / Replies with a document. */
534
+ document(buf: Buffer, extra: Omit<Extra, "mid"> & {
535
+ file_name: string;
536
+ mimetype?: string;
537
+ caption?: string;
538
+ }): Promise<Message | null>;
539
+ /** Responde con tarjeta(s) de contacto. / Replies with contact card(s). */
540
+ vcard(contacts: {
541
+ name: string;
542
+ phone: string;
543
+ }[], extra?: Omit<Extra, "mid">): Promise<Message | null>;
544
+ /** Responde con evento. / Replies with an event. */
545
+ event(data: {
546
+ name: string;
547
+ caption?: string;
548
+ start: Date;
549
+ end?: Date;
550
+ place?: {
551
+ lat: number;
552
+ lng: number;
553
+ };
554
+ }, extra?: Omit<Extra, "mid">): Promise<Message | null>;
555
+ };
556
+ readonly Text: typeof Text;
557
+ readonly Image: typeof Image;
558
+ readonly Video: typeof Video;
559
+ readonly Audio: typeof Audio;
560
+ readonly Sticker: typeof Sticker;
561
+ readonly Document: typeof Document;
562
+ readonly Location: typeof Location;
563
+ readonly Poll: typeof Poll;
564
+ readonly VCard: typeof VCard;
565
+ readonly Event: typeof Event;
566
+ /**
567
+ * Mensaje por chat e id.
568
+ * Message by chat and id.
569
+ *
570
+ * @param cid - Teléfono, JID o LID del chat / Chat phone, JID or LID
571
+ * @param mid - Identificador del mensaje / Message identifier
572
+ */
573
+ get(cid: string, mid: string): Promise<Message | null>;
574
+ /**
575
+ * Pagina los mensajes del chat, del más reciente al más antiguo.
576
+ * Paginates chat messages, from the most recent to the oldest.
577
+ *
578
+ * @param cid - Teléfono, JID o LID del chat / Chat phone, JID or LID
579
+ * @param offset - Desplazamiento / Offset
580
+ * @param limit - Tamaño de página / Page size
581
+ */
582
+ list(cid: string, offset?: number, limit?: number): Promise<Message[]>;
583
+ /** Envía texto. / Sends text. */
584
+ text(cid: string, caption: string, extra?: Extra): Promise<Message | null>;
585
+ /** Envía imagen. / Sends an image. */
586
+ image(cid: string, buf: Buffer, extra?: Extra & {
587
+ caption?: string;
588
+ }): Promise<Message | null>;
589
+ /** Envía video. / Sends a video. */
590
+ video(cid: string, buf: Buffer, extra?: Extra & {
591
+ caption?: string;
592
+ }): Promise<Message | null>;
593
+ /** Envía audio. / Sends audio. */
594
+ audio(cid: string, buf: Buffer, extra?: Extra & {
595
+ ptt?: boolean;
596
+ }): Promise<Message | null>;
597
+ /** Envía ubicación. / Sends a location. */
598
+ location(cid: string, loc: {
599
+ lat: number;
600
+ lng: number;
601
+ }, extra?: Extra): Promise<Message | null>;
602
+ /** Envía encuesta. / Sends a poll. */
603
+ poll(cid: string, input: {
604
+ content: string;
605
+ options: {
606
+ content: string;
607
+ }[];
608
+ }, extra?: Extra & {
609
+ multiple?: boolean;
610
+ }): Promise<Message | null>;
611
+ /** Envía documento. / Sends a document. */
612
+ document(cid: string, buf: Buffer, extra: Extra & {
613
+ file_name: string;
614
+ mimetype?: string;
615
+ caption?: string;
616
+ }): Promise<Message | null>;
617
+ /** Envía tarjeta(s) de contacto. / Sends contact card(s). */
618
+ vcard(cid: string, contacts: {
619
+ name: string;
620
+ phone: string;
621
+ }[], extra?: Extra): Promise<Message | null>;
622
+ /** Envía evento. / Sends an event. */
623
+ event(cid: string, data: {
624
+ name: string;
625
+ caption?: string;
626
+ start: Date;
627
+ end?: Date;
628
+ place?: {
629
+ lat: number;
630
+ lng: number;
631
+ };
632
+ }, extra?: Extra): Promise<Message | null>;
633
+ /** Reacciona a un mensaje por id. / Reacts to a message by id. */
634
+ react(cid: string, mid: string, emoji: string): Promise<boolean>;
635
+ /** Destaca un mensaje por id. / Stars a message by id. */
636
+ star(cid: string, mid: string, value: boolean): Promise<boolean>;
637
+ /** Marca un mensaje como leído por id. / Marks a message as read by id. */
638
+ seen(cid: string, mid: string): Promise<boolean>;
639
+ /** Edita un mensaje por id. / Edits a message by id. */
640
+ edit(cid: string, mid: string, caption: string): Promise<boolean>;
641
+ /** Reenvía un mensaje por id. / Forwards a message by id. */
642
+ forward(cid: string, mid: string, target: string | Chat | Contact): Promise<boolean>;
643
+ /** Elimina un mensaje por id. / Deletes a message by id. */
644
+ delete(cid: string, mid: string, all?: boolean): Promise<boolean>;
645
+ /** Reacciones de un mensaje por id. / Reactions of a message by id. */
646
+ reactions(cid: string, mid: string): Promise<{
647
+ emoji: string;
648
+ count: number;
649
+ }[]>;
650
+ };
572
651
  export {};