@arcaelas/whatsapp 4.4.0 → 5.1.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 (97) hide show
  1. package/build/cjs/index.d.ts +6 -4
  2. package/build/cjs/index.js +22 -2
  3. package/build/cjs/index.js.map +1 -1
  4. package/build/cjs/lib/bot/decorator.d.ts +2 -0
  5. package/build/cjs/lib/bot/decorator.js +6 -0
  6. package/build/cjs/lib/bot/decorator.js.map +1 -1
  7. package/build/cjs/lib/chat/index.d.ts +340 -204
  8. package/build/cjs/lib/chat/index.js +225 -213
  9. package/build/cjs/lib/chat/index.js.map +1 -1
  10. package/build/cjs/lib/contact/index.d.ts +162 -179
  11. package/build/cjs/lib/contact/index.js +96 -190
  12. package/build/cjs/lib/contact/index.js.map +1 -1
  13. package/build/cjs/lib/internal.d.ts +40 -0
  14. package/build/cjs/lib/internal.js +39 -0
  15. package/build/cjs/lib/internal.js.map +1 -0
  16. package/build/cjs/lib/message/index.d.ts +463 -278
  17. package/build/cjs/lib/message/index.js +830 -710
  18. package/build/cjs/lib/message/index.js.map +1 -1
  19. package/build/cjs/lib/status/index.d.ts +60 -70
  20. package/build/cjs/lib/status/index.js +106 -111
  21. package/build/cjs/lib/status/index.js.map +1 -1
  22. package/build/cjs/lib/store/engine/index.d.ts +21 -7
  23. package/build/cjs/lib/store/engine/index.js +6 -3
  24. package/build/cjs/lib/store/engine/index.js.map +1 -1
  25. package/build/cjs/lib/store/engine/lib/file_system/index.d.ts +38 -8
  26. package/build/cjs/lib/store/engine/lib/file_system/index.js +92 -67
  27. package/build/cjs/lib/store/engine/lib/file_system/index.js.map +1 -1
  28. package/build/cjs/lib/store/engine/lib/index.d.ts +112 -0
  29. package/build/cjs/lib/store/engine/lib/index.js +213 -0
  30. package/build/cjs/lib/store/engine/lib/index.js.map +1 -0
  31. package/build/cjs/lib/store/engine/lib/redis/index.d.ts +28 -13
  32. package/build/cjs/lib/store/engine/lib/redis/index.js +56 -42
  33. package/build/cjs/lib/store/engine/lib/redis/index.js.map +1 -1
  34. package/build/cjs/lib/store/engine/lib/s3/index.d.ts +44 -1
  35. package/build/cjs/lib/store/engine/lib/s3/index.js +112 -64
  36. package/build/cjs/lib/store/engine/lib/s3/index.js.map +1 -1
  37. package/build/cjs/lib/store/engine/lib/sqlite/index.d.ts +98 -0
  38. package/build/cjs/lib/store/engine/lib/sqlite/index.js +114 -0
  39. package/build/cjs/lib/store/engine/lib/sqlite/index.js.map +1 -0
  40. package/build/cjs/lib/store/index.d.ts +7 -3
  41. package/build/cjs/lib/store/index.js +14 -4
  42. package/build/cjs/lib/store/index.js.map +1 -1
  43. package/build/cjs/lib/whatsapp/index.d.ts +117 -63
  44. package/build/cjs/lib/whatsapp/index.js +404 -184
  45. package/build/cjs/lib/whatsapp/index.js.map +1 -1
  46. package/build/cjs/test.d.ts +1 -0
  47. package/build/cjs/test.js +72 -0
  48. package/build/cjs/test.js.map +1 -0
  49. package/build/esm/index.d.ts +6 -4
  50. package/build/esm/index.js +5 -2
  51. package/build/esm/index.js.map +1 -1
  52. package/build/esm/lib/bot/decorator.d.ts +2 -0
  53. package/build/esm/lib/bot/decorator.js +6 -0
  54. package/build/esm/lib/bot/decorator.js.map +1 -1
  55. package/build/esm/lib/chat/index.d.ts +340 -204
  56. package/build/esm/lib/chat/index.js +225 -213
  57. package/build/esm/lib/chat/index.js.map +1 -1
  58. package/build/esm/lib/contact/index.d.ts +162 -179
  59. package/build/esm/lib/contact/index.js +96 -189
  60. package/build/esm/lib/contact/index.js.map +1 -1
  61. package/build/esm/lib/internal.d.ts +40 -0
  62. package/build/esm/lib/internal.js +35 -0
  63. package/build/esm/lib/internal.js.map +1 -0
  64. package/build/esm/lib/message/index.d.ts +463 -278
  65. package/build/esm/lib/message/index.js +825 -705
  66. package/build/esm/lib/message/index.js.map +1 -1
  67. package/build/esm/lib/status/index.d.ts +60 -70
  68. package/build/esm/lib/status/index.js +105 -110
  69. package/build/esm/lib/status/index.js.map +1 -1
  70. package/build/esm/lib/store/engine/index.d.ts +21 -7
  71. package/build/esm/lib/store/engine/index.js +4 -2
  72. package/build/esm/lib/store/engine/index.js.map +1 -1
  73. package/build/esm/lib/store/engine/lib/file_system/index.d.ts +38 -8
  74. package/build/esm/lib/store/engine/lib/file_system/index.js +92 -67
  75. package/build/esm/lib/store/engine/lib/file_system/index.js.map +1 -1
  76. package/build/esm/lib/store/engine/lib/index.d.ts +112 -0
  77. package/build/esm/lib/store/engine/lib/index.js +206 -0
  78. package/build/esm/lib/store/engine/lib/index.js.map +1 -0
  79. package/build/esm/lib/store/engine/lib/redis/index.d.ts +28 -13
  80. package/build/esm/lib/store/engine/lib/redis/index.js +54 -40
  81. package/build/esm/lib/store/engine/lib/redis/index.js.map +1 -1
  82. package/build/esm/lib/store/engine/lib/s3/index.d.ts +44 -1
  83. package/build/esm/lib/store/engine/lib/s3/index.js +111 -63
  84. package/build/esm/lib/store/engine/lib/s3/index.js.map +1 -1
  85. package/build/esm/lib/store/engine/lib/sqlite/index.d.ts +98 -0
  86. package/build/esm/lib/store/engine/lib/sqlite/index.js +110 -0
  87. package/build/esm/lib/store/engine/lib/sqlite/index.js.map +1 -0
  88. package/build/esm/lib/store/index.d.ts +7 -3
  89. package/build/esm/lib/store/index.js +13 -4
  90. package/build/esm/lib/store/index.js.map +1 -1
  91. package/build/esm/lib/whatsapp/index.d.ts +117 -63
  92. package/build/esm/lib/whatsapp/index.js +406 -186
  93. package/build/esm/lib/whatsapp/index.js.map +1 -1
  94. package/build/esm/test.d.ts +1 -0
  95. package/build/esm/test.js +67 -0
  96. package/build/esm/test.js.map +1 -0
  97. package/package.json +2 -2
@@ -1,333 +1,544 @@
1
1
  /**
2
2
  * @file message/index.ts
3
- * @description Entidad Message — una sola clase base que recibe `{wa, doc}` en el constructor.
4
- * Subclases especializadas (Text, Image, Video, Audio, Gps, Poll) override `content()` según su tipo.
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.
5
8
  */
6
9
  import { type WAMessage } from 'baileys';
7
10
  import { Readable } from 'node:stream';
8
- import { Chat, chat } from '../../lib/chat';
9
- import { Contact, contact } from '../../lib/contact';
11
+ import { Chat } from '../../lib/chat';
12
+ import { Contact } from '../../lib/contact';
10
13
  import type { WhatsApp } from '../../lib/whatsapp';
11
- /** Destino aceptado por `forward`: CID (string), Chat o Contact. */
12
- export type ForwardTarget = string | Chat | Contact;
13
- type ChatInstance = InstanceType<ReturnType<typeof chat>>;
14
- type ContactInstance = InstanceType<ReturnType<typeof contact>>;
15
- /** Tipos de mensaje internos (no expuestos como getter público). */
16
- export type MessageType = 'text' | 'image' | 'video' | 'audio' | 'location' | 'poll' | 'document' | 'vcard' | 'event';
17
- export declare enum MessageStatus {
18
- ERROR = 0,
19
- PENDING = 1,
20
- SERVER_ACK = 2,
21
- DELIVERED = 3,
22
- READ = 4,
23
- PLAYED = 5
24
- }
25
- export interface SendOptions {
14
+ /** Estados legibles indexados por el status numérico de baileys. / Readable states indexed by the baileys numeric status. */
15
+ declare const STATUS: readonly ["error", "pending", "sent", "delivered", "read", "played"];
16
+ type SendExtra = {
26
17
  mid?: string;
27
- }
28
- export interface SendMediaOptions extends SendOptions {
29
- caption?: string;
30
- }
31
- export interface SendAudioOptions extends SendOptions {
32
- ptt?: boolean;
33
- }
34
- export interface SendPollOptions extends SendOptions {
35
- /** true para selección múltiple; default false (single). / true for multi-select; default false (single). */
36
- multiple?: boolean;
37
- }
38
- export interface SendDocumentOptions extends SendOptions {
39
- /** Nombre del archivo mostrado al receptor. / File name shown to the recipient. */
40
- file_name: string;
41
- /** MIME real del contenido; default `application/octet-stream`. / Real content MIME; defaults to `application/octet-stream`. */
42
- mimetype?: string;
43
- /** Texto adjunto opcional. / Optional attached caption. */
44
- caption?: string;
45
- }
46
- export interface VCardInput {
47
- /** Nombre mostrado del contacto. / Contact display name. */
48
- name: string;
49
- /** Teléfono en formato internacional. / Phone in international format. */
50
- phone: string;
51
- }
52
- export interface EventInput {
53
- /** Nombre del evento. / Event name. */
54
- name: string;
55
- /** Descripción opcional (texto del evento, expuesto como `caption`). / Optional description (event text, exposed as `caption`). */
56
- caption?: string;
57
- /** Fecha/hora de inicio. / Start date/time. */
58
- start: Date;
59
- /** Fecha/hora de fin opcional. / Optional end date/time. */
60
- end?: Date;
61
- /** Ubicación opcional. / Optional location. */
62
- place?: {
63
- lat: number;
64
- lng: number;
65
- };
66
- }
67
- export interface LocationOptions {
68
- lat: number;
69
- lng: number;
70
- live?: boolean;
71
- }
72
- export interface PollOptions {
73
- content: string;
74
- options: Array<{
75
- content: string;
76
- }>;
77
- }
18
+ once?: boolean;
19
+ };
78
20
  /**
79
- * Documento persistido del mensaje.
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, …)`).
80
27
  */
81
- export interface IMessage {
82
- id: string;
83
- cid: string;
84
- mid: string | null;
85
- me: boolean;
86
- type: MessageType;
87
- author: string;
88
- status: MessageStatus;
89
- starred: boolean;
90
- forwarded: boolean;
91
- created_at: number;
92
- deleted_at: number | null;
93
- mime: string;
94
- caption: string;
95
- edited: boolean;
28
+ export declare class Message {
29
+ readonly _wa: WhatsApp;
30
+ readonly _raw: {
31
+ id: string;
32
+ cid: string;
33
+ mid: string | null;
34
+ me: boolean;
35
+ type: 'text' | 'image' | 'video' | 'audio' | 'sticker' | 'document' | 'location' | 'poll' | 'vcard' | 'event';
36
+ author: string;
37
+ status: number;
38
+ starred: boolean;
39
+ forwarded: boolean;
40
+ created_at: number;
41
+ deleted_at: number | null;
42
+ mime: string;
43
+ caption: string;
44
+ edited: boolean;
45
+ multiple?: boolean;
46
+ reactions?: {
47
+ author: string;
48
+ emoji: string;
49
+ at: number;
50
+ }[];
51
+ viewed?: boolean | null;
52
+ raw: WAMessage;
53
+ };
96
54
  /**
97
- * Solo para polls: discriminador explícito de selección múltiple seteado al enviar.
98
- * Cuando está definido, `Poll.multiple` lo prefiere sobre el conteo del proto
99
- * (WhatsApp normaliza `selectableOptionsCount` en el echo de polls auto-emitidos
100
- * y pierde el discriminador, por eso necesitamos persistirlo nosotros).
101
- * Poll-only: explicit multi-select flag set at send time. When defined, `Poll.multiple`
102
- * prefers it over the proto count (WhatsApp normalizes `selectableOptionsCount` on
103
- * own-poll echo, losing the discriminator).
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).
104
61
  */
105
- multiple?: boolean;
106
- raw: WAMessage;
107
- }
108
- /**
109
- * Construye el documento IMessage desde el raw de baileys.
110
- */
111
- export declare function build_message_doc(raw: WAMessage, self_id?: string, edited?: boolean): IMessage;
112
- /**
113
- * Clase base del mensaje. Una sola clase — toda la API de instancia vive aquí.
114
- * Base message class. Single class — all instance API lives here.
115
- */
116
- export declare class Message {
117
- /** @internal */
118
- protected readonly _wa: WhatsApp;
119
- /** @internal */
120
- protected readonly _doc: IMessage;
121
- /** @internal Cache de la promesa de `author()` para evitar engine round-trips repetidos. */
122
- private _author_cache;
123
- /** @internal Cache de la promesa de `chat()` para evitar engine round-trips repetidos. */
124
- private _chat_cache;
125
- constructor(options: {
126
- wa: WhatsApp;
127
- doc: IMessage;
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;
128
85
  });
86
+ /** Identificador del mensaje. / Message identifier. */
129
87
  get id(): string;
88
+ /** Identificador del chat del mensaje. / Message chat identifier. */
130
89
  get cid(): string;
131
- get type(): MessageType;
132
- /** JID del autor del mensaje. Para acceso síncrono sin hidratar el Contact. */
133
- get from(): string;
134
- /** MIME type del contenido. `text/plain` para texto, `application/json` para location/poll, mimetype real para media. */
135
- get mime(): string;
90
+ /** Identificador del mensaje citado, o null. / Quoted message identifier, or null. */
136
91
  get mid(): string | null;
92
+ /** JID del autor, para acceso síncrono. / Author JID, for sync access. */
93
+ get from(): string;
94
+ /** true si soy el autor. / true when I am the author. */
137
95
  get me(): boolean;
96
+ /** Tipo del mensaje. / Message type. */
97
+ 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
+ /** Texto del mensaje o caption del media. / Message text or media caption. */
138
101
  get caption(): string;
102
+ /** Estado legible del mensaje. / Readable message state. */
103
+ get status(): (typeof STATUS)[number];
104
+ /** true si el mensaje fue visto. / true when the message was seen. */
105
+ get read(): boolean;
106
+ /** true si está destacado. / true when starred. */
139
107
  get starred(): boolean;
108
+ /** true si fue reenviado. / true when forwarded. */
140
109
  get forwarded(): boolean;
141
- get once(): boolean;
142
- get created_at(): number;
143
- get deleted_at(): number | null;
144
- get status(): MessageStatus;
110
+ /** true si fue editado. / true when edited. */
145
111
  get edited(): boolean;
112
+ /** true si es de una sola lectura (view-once). / true when view-once. */
113
+ get once(): boolean;
114
+ /** Fecha de creación en ISO UTC. / Creation date as ISO UTC. */
115
+ get created_at(): string;
116
+ /** Vencimiento del mensaje temporal en ISO UTC, o null. / Ephemeral expiration as ISO UTC, or null. */
117
+ get expires_at(): string | null;
118
+ /**
119
+ * Contacto autor del mensaje, desde el engine (ficha mínima si no está persistido).
120
+ * Message author contact, from the engine (minimal card when not persisted).
121
+ *
122
+ * @returns Contacto / Contact
123
+ */
124
+ author(): Promise<InstanceType<WhatsApp['Contact']>>;
125
+ /**
126
+ * Chat al que pertenece el mensaje.
127
+ * Chat the message belongs to.
128
+ *
129
+ * @returns Chat / Chat
130
+ */
131
+ chat(): Promise<InstanceType<WhatsApp['Chat']>>;
146
132
  /**
147
- * Contacto del autor (resuelve vía `wa.Contact.get`; fallback a instancia mínima).
148
- * Memoizado por instancia: la primera llamada va al engine; las siguientes
149
- * reutilizan la misma promesa sin nuevos round-trips.
150
- * Author contact (resolves via `wa.Contact.get`; falls back to a minimal instance).
151
- * Instance-memoized: first call hits the engine; subsequent calls reuse the
152
- * same promise without further round-trips.
133
+ * Mensaje citado cuando hay `mid`, o null.
134
+ * Quoted message when `mid` exists, or null.
135
+ *
136
+ * @returns Mensaje citado o null / Quoted message or null
153
137
  */
154
- author(): Promise<ContactInstance>;
138
+ message(): Promise<Message | null>;
155
139
  /**
156
- * Chat al que pertenece el mensaje. Memoizado por instancia: la primera llamada
157
- * va al engine; las siguientes reutilizan la misma promesa.
158
- * Chat the message belongs to. Instance-memoized: first call hits the engine;
159
- * subsequent calls reuse the same promise.
140
+ * Contenido del mensaje: texto como su caption, media como binario, y
141
+ * poll/location/vcard/event como JSON.
142
+ * Message content: text as its caption, media as binary, and
143
+ * poll/location/vcard/event as JSON.
144
+ *
145
+ * @returns Buffer del contenido / Content buffer
160
146
  */
161
- chat(): Promise<ChatInstance>;
162
- /** Contenido sin parsear, directo del engine. Las subclases override según su tipo. */
163
147
  content(): Promise<Buffer>;
164
148
  /**
165
- * Devuelve un `Readable` con los bytes del mensaje. Para media (image/video/audio)
166
- * lee desde el cache del engine o, si falta, descarga desde baileys. Para text/location/poll
167
- * retorna el mismo binario que `content()` envuelto en un Readable.
168
- * Returns a `Readable` of the message bytes. For media (image/video/audio) it reads
169
- * from the engine cache or, if missing, downloads from baileys. For text/location/poll
170
- * it wraps the `content()` buffer in a Readable.
149
+ * Stream del contenido; para media descarga de baileys si el cache falta.
150
+ * Content stream; media falls back to a baileys download when the cache is missing.
151
+ *
152
+ * @returns Readable del contenido / Content readable
171
153
  */
172
154
  stream(): Promise<Readable>;
173
- /** Reacciona al mensaje (emoji vacío para retirar). */
155
+ /**
156
+ * Reacciones del mensaje agrupadas por emoji con su conteo.
157
+ * Message reactions grouped by emoji with their count.
158
+ *
159
+ * @returns Conteo por emoji / Per-emoji count
160
+ */
161
+ reactions(): Promise<{
162
+ emoji: string;
163
+ count: number;
164
+ }[]>;
165
+ /**
166
+ * Reacciona al mensaje; el emoji vacío retira la reacción.
167
+ * Reacts to the message; an empty emoji removes the reaction.
168
+ *
169
+ * @param emoji - Emoji o '' / Emoji or ''
170
+ * @returns true si se envió / true when sent
171
+ */
174
172
  react(emoji: string): Promise<boolean>;
175
- /** Reenvía el mensaje a un destino (CID, Chat o Contact). */
176
- forward(target: ForwardTarget): Promise<boolean>;
177
- /** Marca el mensaje como leído. */
178
- seen(): Promise<boolean>;
179
- /** Destaca/retira destacado del mensaje. */
173
+ /**
174
+ * Destaca o quita el destacado del mensaje.
175
+ * Stars or unstars the message.
176
+ *
177
+ * @param value - true destaca / true stars
178
+ * @returns true si se envió / true when sent
179
+ */
180
180
  star(value: boolean): Promise<boolean>;
181
- /** Elimina el mensaje. `all=true` (default) borra para todos; `all=false` borra sólo en mi dispositivo. */
181
+ /**
182
+ * Marca el mensaje como leído.
183
+ * Marks the message as read.
184
+ *
185
+ * @returns true si se envió / true when sent
186
+ */
187
+ seen(): Promise<boolean>;
188
+ /**
189
+ * Edita el caption del mensaje propio (texto, imagen o video).
190
+ * Edits the own message caption (text, image or video).
191
+ *
192
+ * @param caption - Texto nuevo / New text
193
+ * @returns true si se editó / true when edited
194
+ */
195
+ edit(caption: string): Promise<boolean>;
196
+ /**
197
+ * Reenvía el mensaje a otro chat.
198
+ * Forwards the message to another chat.
199
+ *
200
+ * @param target - CID, Chat o Contact destino / Target CID, Chat or Contact
201
+ * @returns true si se reenvió / true when forwarded
202
+ */
203
+ forward(target: string | Chat | Contact): Promise<boolean>;
204
+ /**
205
+ * Elimina el mensaje: solo en mi dispositivo por defecto, para todos con `true`.
206
+ * Deletes the message: this device only by default, for everyone with `true`.
207
+ *
208
+ * @param all - true elimina para todos / true deletes for everyone
209
+ * @returns true si se eliminó / true when deleted
210
+ */
182
211
  delete(all?: boolean): Promise<boolean>;
183
- /** Edita el texto/caption del mensaje (solo propios editables). */
184
- edit(text: string): Promise<boolean>;
185
- /** Observa cambios sobre este mensaje. Retorna unsubscribe. / Watches this message. Returns unsubscribe. */
186
- watch(handler: (msg: Message) => void): () => void;
187
- /** Responde con texto. */
188
- text(caption: string, opts?: SendOptions): Promise<Message | null>;
189
- /** Responde con imagen. */
190
- image(buf: Buffer, opts?: SendMediaOptions): Promise<Message | null>;
191
- /** Responde con video. */
192
- video(buf: Buffer, opts?: SendMediaOptions): Promise<Message | null>;
193
- /** Responde con audio. */
194
- audio(buf: Buffer, opts?: SendAudioOptions): Promise<Message | null>;
195
- /** Responde con ubicación. */
196
- location(loc: LocationOptions, opts?: SendOptions): Promise<Message | null>;
197
- /** Responde con encuesta. */
198
- poll(poll: PollOptions, opts?: SendPollOptions): Promise<Message | null>;
199
- /** Responde con documento. */
200
- document(buf: Buffer, opts: SendDocumentOptions): Promise<Message | null>;
201
- /** Responde con tarjeta(s) de contacto. */
202
- vcard(contacts: VCardInput[], opts?: SendOptions): Promise<Message | null>;
203
- /** Responde con evento. */
204
- event(data: EventInput, opts?: SendOptions): Promise<Message | null>;
212
+ /** Responde con texto. / Replies with text. */
213
+ text(caption: string, extra?: Omit<SendExtra, 'mid'>): Promise<Message | null>;
214
+ /** Responde con imagen. / Replies with an image. */
215
+ image(buf: Buffer, extra?: Omit<SendExtra, 'mid'> & {
216
+ caption?: string;
217
+ }): Promise<Message | null>;
218
+ /** Responde con video. / Replies with a video. */
219
+ video(buf: Buffer, extra?: Omit<SendExtra, 'mid'> & {
220
+ caption?: string;
221
+ }): Promise<Message | null>;
222
+ /** Responde con audio. / Replies with audio. */
223
+ audio(buf: Buffer, extra?: Omit<SendExtra, 'mid'> & {
224
+ ptt?: boolean;
225
+ }): Promise<Message | null>;
226
+ /** Responde con ubicación. / Replies with a location. */
227
+ location(loc: {
228
+ lat: number;
229
+ lng: number;
230
+ }, extra?: Omit<SendExtra, 'mid'>): Promise<Message | null>;
231
+ /** Responde con encuesta. / Replies with a poll. */
232
+ poll(input: {
233
+ content: string;
234
+ options: {
235
+ content: string;
236
+ }[];
237
+ }, extra?: Omit<SendExtra, 'mid'> & {
238
+ multiple?: boolean;
239
+ }): Promise<Message | null>;
240
+ /** Responde con documento. / Replies with a document. */
241
+ document(buf: Buffer, extra: Omit<SendExtra, 'mid'> & {
242
+ file_name: string;
243
+ mimetype?: string;
244
+ caption?: string;
245
+ }): Promise<Message | null>;
246
+ /** Responde con tarjeta(s) de contacto. / Replies with contact card(s). */
247
+ vcard(contacts: {
248
+ name: string;
249
+ phone: string;
250
+ }[], extra?: Omit<SendExtra, 'mid'>): Promise<Message | null>;
251
+ /** Responde con evento. / Replies with an event. */
252
+ event(data: {
253
+ name: string;
254
+ caption?: string;
255
+ start: Date;
256
+ end?: Date;
257
+ place?: {
258
+ lat: number;
259
+ lng: number;
260
+ };
261
+ }, extra?: Omit<SendExtra, 'mid'>): Promise<Message | null>;
262
+ /**
263
+ * Obtiene un mensaje por chat y id.
264
+ * Retrieves a message by chat and id.
265
+ *
266
+ * @param wa - Cliente dueño / Owner client
267
+ * @param cid - Identificador del chat / Chat identifier
268
+ * @param mid - Identificador del mensaje / Message identifier
269
+ * @returns Mensaje o null / Message or null
270
+ */
271
+ static get(wa: WhatsApp, cid: string, mid: string): Promise<Message | null>;
272
+ /**
273
+ * Pagina los mensajes de un chat desde el más reciente.
274
+ * Paginates chat messages from the most recent one.
275
+ *
276
+ * @param wa - Cliente dueño / Owner client
277
+ * @param cid - Identificador del chat / Chat identifier
278
+ * @param offset - Desplazamiento / Offset
279
+ * @param limit - Tamaño de página / Page size
280
+ * @returns Página de mensajes / Message page
281
+ */
282
+ static list(wa: WhatsApp, cid: string, offset?: number, limit?: number): Promise<Message[]>;
283
+ /** Envía texto. / Sends text. */
284
+ static text(wa: WhatsApp, cid: string, caption: string, extra?: SendExtra): Promise<Message | null>;
285
+ /** Envía imagen. / Sends an image. */
286
+ static image(wa: WhatsApp, cid: string, buf: Buffer, extra?: SendExtra & {
287
+ caption?: string;
288
+ }): Promise<Message | null>;
289
+ /** Envía video. / Sends a video. */
290
+ static video(wa: WhatsApp, cid: string, buf: Buffer, extra?: SendExtra & {
291
+ caption?: string;
292
+ }): Promise<Message | null>;
293
+ /** Envía audio. / Sends audio. */
294
+ static audio(wa: WhatsApp, cid: string, buf: Buffer, extra?: SendExtra & {
295
+ ptt?: boolean;
296
+ }): Promise<Message | null>;
297
+ /** Envía ubicación. / Sends a location. */
298
+ static location(wa: WhatsApp, cid: string, loc: {
299
+ lat: number;
300
+ lng: number;
301
+ }, extra?: SendExtra): Promise<Message | null>;
302
+ /** Envía encuesta. / Sends a poll. */
303
+ static poll(wa: WhatsApp, cid: string, input: {
304
+ content: string;
305
+ options: {
306
+ content: string;
307
+ }[];
308
+ }, extra?: SendExtra & {
309
+ multiple?: boolean;
310
+ }): Promise<Message | null>;
311
+ /** Envía documento. / Sends a document. */
312
+ static document(wa: WhatsApp, cid: string, buf: Buffer, extra: SendExtra & {
313
+ file_name: string;
314
+ mimetype?: string;
315
+ caption?: string;
316
+ }): Promise<Message | null>;
317
+ /** Envía tarjeta(s) de contacto. / Sends contact card(s). */
318
+ static vcard(wa: WhatsApp, cid: string, contacts: {
319
+ name: string;
320
+ phone: string;
321
+ }[], extra?: SendExtra): Promise<Message | null>;
322
+ /** Envía evento. / Sends an event. */
323
+ static event(wa: WhatsApp, cid: string, data: {
324
+ name: string;
325
+ caption?: string;
326
+ start: Date;
327
+ end?: Date;
328
+ place?: {
329
+ lat: number;
330
+ lng: number;
331
+ };
332
+ }, extra?: SendExtra): Promise<Message | null>;
333
+ /** Reacciona a un mensaje por id. / Reacts to a message by id. */
334
+ static react(wa: WhatsApp, cid: string, mid: string, emoji: string): Promise<boolean>;
335
+ /** Destaca un mensaje por id. / Stars a message by id. */
336
+ static star(wa: WhatsApp, cid: string, mid: string, value: boolean): Promise<boolean>;
337
+ /** Marca un mensaje como leído por id. / Marks a message as read by id. */
338
+ static seen(wa: WhatsApp, cid: string, mid: string): Promise<boolean>;
339
+ /** Edita un mensaje por id. / Edits a message by id. */
340
+ static edit(wa: WhatsApp, cid: string, mid: string, caption: string): Promise<boolean>;
341
+ /** Reenvía un mensaje por id. / Forwards a message by id. */
342
+ static forward(wa: WhatsApp, cid: string, mid: string, target: string | Chat | Contact): Promise<boolean>;
343
+ /** Elimina un mensaje por id. / Deletes a message by id. */
344
+ static delete(wa: WhatsApp, cid: string, mid: string, all?: boolean): Promise<boolean>;
345
+ /** Reacciones de un mensaje por id. / Reactions of a message by id. */
346
+ static reactions(wa: WhatsApp, cid: string, mid: string): Promise<{
347
+ emoji: string;
348
+ count: number;
349
+ }[]>;
205
350
  }
206
351
  /**
207
- * Mensaje de texto. Override `content()` para retornar el caption como Buffer sin pasar por engine.
208
- * Text message. Overrides `content()` returning caption as Buffer directly.
352
+ * Mensaje de texto; `preview()` expone la tarjeta del enlace embebido.
353
+ * Text message; `preview()` exposes the embedded link card.
209
354
  */
210
355
  export declare class Text extends Message {
211
- content(): Promise<Buffer>;
356
+ /**
357
+ * Preview del enlace del texto, o null cuando no trae metadata.
358
+ * Text link preview, or null when it carries no metadata.
359
+ *
360
+ * @returns { link, name, content, thumb } o null / { link, name, content, thumb } or null
361
+ */
362
+ preview(): Promise<{
363
+ link: string;
364
+ name: string | null;
365
+ content: string | null;
366
+ thumb: Buffer | null;
367
+ } | null>;
212
368
  }
213
369
  /**
214
- * Mensaje de imagen. Hereda `stream()` de la clase base; `content()` drena el stream.
215
- * Image message. Inherits `stream()` from the base class; `content()` drains the stream.
370
+ * Mensaje de imagen: dimensiones, peso y miniatura.
371
+ * Image message: dimensions, size and thumbnail.
216
372
  */
217
373
  export declare class Image extends Message {
374
+ /** @internal */
375
+ private get _media();
376
+ /** Ancho en píxeles. / Width in pixels. */
377
+ get width(): number;
378
+ /** Alto en píxeles. / Height in pixels. */
379
+ get height(): number;
380
+ /** Peso en bytes. / Size in bytes. */
381
+ get size(): number;
382
+ /**
383
+ * Miniatura JPEG embebida, o null.
384
+ * Embedded JPEG thumbnail, or null.
385
+ *
386
+ * @returns Buffer de la miniatura o null / Thumbnail buffer or null
387
+ */
388
+ thumb(): Promise<Buffer | null>;
218
389
  content(): Promise<Buffer>;
219
390
  }
220
391
  /**
221
- * Mensaje de video. Hereda `stream()` de la clase base; `content()` drena el stream.
222
- * Video message. Inherits `stream()` from the base class; `content()` drains the stream.
392
+ * Mensaje de video: dimensiones, duración, peso y miniatura.
393
+ * Video message: dimensions, duration, size and thumbnail.
223
394
  */
224
395
  export declare class Video extends Message {
396
+ /** @internal */
397
+ private get _media();
398
+ /** Ancho en píxeles. / Width in pixels. */
399
+ get width(): number;
400
+ /** Alto en píxeles. / Height in pixels. */
401
+ get height(): number;
402
+ /** Duración en segundos. / Duration in seconds. */
403
+ get duration(): number;
404
+ /** Peso en bytes. / Size in bytes. */
405
+ get size(): number;
406
+ /**
407
+ * Miniatura JPEG embebida, o null.
408
+ * Embedded JPEG thumbnail, or null.
409
+ *
410
+ * @returns Buffer de la miniatura o null / Thumbnail buffer or null
411
+ */
412
+ thumb(): Promise<Buffer | null>;
225
413
  content(): Promise<Buffer>;
226
414
  }
227
415
  /**
228
- * Mensaje de audio. Hereda `stream()` de la clase base; `content()` drena el stream.
229
- * `ptt` indica si es nota de voz (push-to-talk).
230
- * Audio message. Inherits `stream()` from the base class; `content()` drains the stream.
231
- * `ptt` flags voice notes.
416
+ * Mensaje de audio: nota de voz o archivo, con forma de onda del protocolo.
417
+ * Audio message: voice note or file, with the protocol waveform.
232
418
  */
233
419
  export declare class Audio extends Message {
234
- /** true si es nota de voz (push-to-talk). / true if push-to-talk voice note. */
420
+ /** @internal */
421
+ private get _media();
422
+ /** true si es nota de voz. / true when push-to-talk. */
235
423
  get ptt(): boolean;
424
+ /** Duración en segundos. / Duration in seconds. */
425
+ get duration(): number;
426
+ /** Peso en bytes. / Size in bytes. */
427
+ get size(): number;
428
+ /** Forma de onda 0-100 lista para pintar. / Paint-ready 0-100 waveform. */
429
+ get waveform(): number[];
236
430
  content(): Promise<Buffer>;
237
431
  }
238
432
  /**
239
- * Mensaje de ubicación. Agrega getters sync `lat`, `lng`, `link` derivados del raw.
240
- * Location message. Adds sync getters `lat`, `lng`, `link` derived from raw.
433
+ * Mensaje de sticker: dimensiones, peso y animación.
434
+ * Sticker message: dimensions, size and animation.
241
435
  */
242
- export declare class Gps extends Message {
436
+ export declare class Sticker extends Message {
437
+ /** @internal */
438
+ private get _media();
439
+ /** Ancho en píxeles. / Width in pixels. */
440
+ get width(): number;
441
+ /** Alto en píxeles. / Height in pixels. */
442
+ get height(): number;
443
+ /** true si el sticker es animado. / true when animated. */
444
+ get animated(): boolean;
445
+ /** Peso en bytes. / Size in bytes. */
446
+ get size(): number;
447
+ content(): Promise<Buffer>;
448
+ }
449
+ /**
450
+ * Mensaje de documento; el MIME real vive en `mime` de la base.
451
+ * Document message; the actual MIME lives in the base `mime`.
452
+ */
453
+ export declare class Document extends Message {
454
+ /** Peso en bytes. / Size in bytes. */
455
+ get size(): number;
456
+ content(): Promise<Buffer>;
457
+ }
458
+ /**
459
+ * Mensaje de ubicación, fija o en vivo.
460
+ * Location message, static or live.
461
+ */
462
+ export declare class Location extends Message {
463
+ /** @internal */
243
464
  private get _loc();
244
465
  /** Latitud en grados. / Latitude in degrees. */
245
466
  get lat(): number;
246
467
  /** Longitud en grados. / Longitude in degrees. */
247
468
  get lng(): number;
248
- /** URL de Google Maps apuntando a la coordenada. / Google Maps URL for the coordinate. */
249
- get link(): string;
250
469
  /** true si es ubicación en tiempo real. / true when live location. */
251
470
  get live(): boolean;
471
+ /** URL de Google Maps de la coordenada. / Google Maps URL for the coordinate. */
472
+ get link(): string;
252
473
  }
253
474
  /**
254
- * Mensaje de encuesta. `caption` es la pregunta (heredada); agrega `options[]` con conteo y `multiple`.
255
- * Poll message. `caption` is the question (inherited); adds `options[]` with counts and `multiple`.
475
+ * Mensaje de encuesta: opciones con conteo, votos por contacto y voto propio.
476
+ * Poll message: options with counts, per-contact votes and self-voting.
256
477
  */
257
478
  export declare class Poll extends Message {
479
+ /** @internal */
258
480
  private get _poll();
259
- /**
260
- * true si admite múltiples respuestas. Lee primero el flag explícito persistido
261
- * al enviar (caso propio, donde WhatsApp pierde el discriminador en el echo);
262
- * fallback al `selectableOptionsCount` del proto (polls foráneos o de UI móvil).
263
- * true if the poll accepts multiple answers. Prefers the persisted send-time
264
- * flag (own polls, since WhatsApp drops the discriminator on echo); falls back
265
- * to the proto `selectableOptionsCount` (foreign or mobile-UI polls).
266
- */
481
+ /** @internal Updates de voto con los bytes normalizados post-engine. / Vote updates with post-engine normalized bytes. */
482
+ private get _updates();
483
+ /** true si admite varias respuestas. / true when multi-select. */
267
484
  get multiple(): boolean;
268
- /** Opciones con conteo de votos actualizado. / Options with up-to-date vote counts. */
485
+ /** Opciones con su conteo de votos. / Options with their vote counts. */
269
486
  get options(): {
270
- content: string;
487
+ name: string;
271
488
  count: number;
272
489
  }[];
273
490
  /**
274
- * Vota en la encuesta. Acepta un índice o lista de índices (para `multiple`).
275
- * Votes in the poll. Accepts a single index or list (for `multiple`).
491
+ * Votos individuales: opción elegida y teléfono del votante.
492
+ * Individual votes: chosen option and voter phone.
493
+ *
494
+ * @returns Lista de votos / Vote list
495
+ */
496
+ votes(): Promise<{
497
+ name: string;
498
+ contact: string;
499
+ }[]>;
500
+ /**
501
+ * Vota en la encuesta con uno o varios índices. Cifra el voto (HMAC+AES-GCM) y lo
502
+ * enruta al chat @lid con la identidad LID propia. Best-effort: el voto entrante
503
+ * descifra correcto, pero WhatsApp no propaga el voto emitido desde un dispositivo
504
+ * vinculado (companion).
505
+ * Votes in the poll with one or more indexes. Encrypts the vote (HMAC+AES-GCM) and
506
+ * routes it to the @lid chat with the own LID identity. Best-effort: incoming votes
507
+ * decrypt fine, but WhatsApp does not propagate votes emitted from a linked
508
+ * (companion) device.
509
+ *
510
+ * @param index - Índice o índices de la opción / Option index or indexes
511
+ * @returns true si el voto se emitió / true when the vote was relayed
276
512
  */
277
513
  select(index: number | number[]): Promise<boolean>;
278
514
  }
279
515
  /**
280
- * Mensaje de documento. WhatsApp permite enviar cualquier archivo (PDF, imagen,
281
- * audio, video, etc.) como documento; lo que lo distingue de image/video/audio es
282
- * el tipo de mensaje (`documentMessage`), no el mimetype. Hereda `stream()` de la
283
- * clase base; `content()` drena el stream (cache → download).
284
- * Document message. WhatsApp lets you send any file (PDF, image, audio, video…)
285
- * as a document; what sets it apart from image/video/audio is the message type
286
- * (`documentMessage`), not the mimetype. Inherits `stream()` from the base class;
287
- * `content()` drains the stream (cache → download).
288
- */
289
- export declare class Document extends Message {
290
- private get _doc_msg();
291
- /** Nombre del archivo. / File name. */
292
- get file_name(): string;
293
- /** Tamaño en bytes (0 si se desconoce). / Size in bytes (0 if unknown). */
294
- get size(): number;
295
- /** Número de páginas (PDF); 0 si no aplica. / Page count (PDF); 0 when not applicable. */
296
- get pages(): number;
297
- /** Título del documento. / Document title. */
298
- get title(): string;
299
- content(): Promise<Buffer>;
300
- }
301
- /**
302
- * Mensaje de tarjeta(s) de contacto (vCard). Unifica `contactMessage` (uno) y
303
- * `contactsArrayMessage` (varios) bajo una sola lista `contacts`.
304
- * Contact card message (vCard). Unifies `contactMessage` (single) and
305
- * `contactsArrayMessage` (multiple) under a single `contacts` list.
516
+ * Mensaje de tarjeta(s) de contacto.
517
+ * Contact card(s) message.
306
518
  */
307
519
  export declare class VCard extends Message {
308
- /** Contactos de la tarjeta con nombre y teléfono. / Card contacts with name and phone. */
520
+ /** Contactos de la tarjeta. / Card contacts. */
309
521
  get contacts(): {
310
522
  name: string;
311
523
  phone: string;
312
524
  }[];
313
525
  }
314
526
  /**
315
- * Mensaje de evento de calendario (`eventMessage`): nombre, descripción, rango de
316
- * fechas, estado de cancelación, link de unión y ubicación.
317
- * Calendar event message (`eventMessage`): name, description, date range,
318
- * cancellation state, join link and location.
527
+ * Mensaje de evento de calendario.
528
+ * Calendar event message.
319
529
  */
320
530
  export declare class Event extends Message {
531
+ /** @internal */
321
532
  private get _event();
322
533
  /** Nombre del evento. / Event name. */
323
534
  get name(): string;
324
- /** Epoch ms de inicio. / Start epoch ms. */
325
- get start(): number;
326
- /** Epoch ms de fin, o null. / End epoch ms, or null. */
327
- get end(): number | null;
328
- /** true si el evento fue cancelado. / true if the event was canceled. */
535
+ /** Inicio en ISO UTC. / Start as ISO UTC. */
536
+ get start(): string;
537
+ /** Fin en ISO UTC, o null. / End as ISO UTC, or null. */
538
+ get end(): string | null;
539
+ /** true si fue cancelado. / true when canceled. */
329
540
  get canceled(): boolean;
330
- /** Link de unión (audio/video), si aplica. / Join link (audio/video), if any. */
541
+ /** Link de unión, si aplica. / Join link, if any. */
331
542
  get link(): string;
332
543
  /** Ubicación del evento, o null. / Event location, or null. */
333
544
  get place(): {
@@ -336,42 +547,16 @@ export declare class Event extends Message {
336
547
  } | null;
337
548
  }
338
549
  /**
339
- * Factoría que enlaza los statics a `wa` y expone las subclases.
340
- * Factory binding statics to `wa` and exposing subclasses.
550
+ * Factoría de Message: evalúa el tipo y retorna la instancia de la subclase correcta.
551
+ * Acepta el documento persistido o el mensaje crudo de baileys — en ese caso el
552
+ * documento se deriva aquí mismo (id, tipo, autor, caption, mime, fechas).
553
+ * Message factory: evaluates the type and returns the right subclass instance. Accepts
554
+ * the persisted document or the raw baileys message — in that case the document is
555
+ * derived right here (id, type, author, caption, mime, dates).
556
+ *
557
+ * @param wa - Instancia principal / Main WhatsApp instance
558
+ * @param raw - Documento persistido o WAMessage crudo / Persisted document or raw WAMessage
559
+ * @returns Instancia del tipo correcto / Right-type instance
341
560
  */
342
- export declare function message(wa: WhatsApp): {
343
- Text: typeof Text;
344
- Image: typeof Image;
345
- Video: typeof Video;
346
- Audio: typeof Audio;
347
- Gps: typeof Gps;
348
- Poll: typeof Poll;
349
- Document: typeof Document;
350
- VCard: typeof VCard;
351
- Event: typeof Event;
352
- build_message_doc: typeof build_message_doc;
353
- build_instance: (doc: IMessage) => Promise<Message>;
354
- /** Obtiene un mensaje por CID/MID. */
355
- get(cid: string, mid: string): Promise<Message | null>;
356
- /** Pagina mensajes de un chat. */
357
- list(cid: string, offset?: number, limit?: number): Promise<Message[]>;
358
- /** Cuenta mensajes de un chat. */
359
- count(cid: string): Promise<number>;
360
- text(cid: string, caption: string, opts?: SendOptions): Promise<Message | null>;
361
- image(cid: string, buf: Buffer, opts?: SendMediaOptions): Promise<Message | null>;
362
- video(cid: string, buf: Buffer, opts?: SendMediaOptions): Promise<Message | null>;
363
- audio(cid: string, buf: Buffer, opts?: SendAudioOptions): Promise<Message | null>;
364
- location(cid: string, loc: LocationOptions, opts?: SendOptions): Promise<Message | null>;
365
- poll(cid: string, p: PollOptions, opts?: SendPollOptions): Promise<Message | null>;
366
- document(cid: string, buf: Buffer, opts: SendDocumentOptions): Promise<Message | null>;
367
- vcard(cid: string, contacts: VCardInput[], opts?: SendOptions): Promise<Message | null>;
368
- event(cid: string, data: EventInput, opts?: SendOptions): Promise<Message | null>;
369
- edit(cid: string, mid: string, text: string): Promise<boolean>;
370
- delete(cid: string, mid: string, all?: boolean): Promise<boolean>;
371
- react(cid: string, mid: string, emoji: string): Promise<boolean>;
372
- forward(cid: string, mid: string, target: ForwardTarget): Promise<boolean>;
373
- seen(cid: string, mid: string): Promise<boolean>;
374
- star(cid: string, mid: string, value: boolean): Promise<boolean>;
375
- watch(cid: string, mid: string, handler: (msg: Message) => void): () => void;
376
- };
561
+ export declare function message(wa: WhatsApp, raw: Message['_raw'] | WAMessage): Message;
377
562
  export {};