@arcaelas/whatsapp 4.5.0 → 6.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 (106) hide show
  1. package/README.md +282 -239
  2. package/build/cjs/decorators.js +0 -1
  3. package/build/cjs/index.d.ts +6 -4
  4. package/build/cjs/index.js +22 -3
  5. package/build/cjs/lib/bot/decorator.d.ts +2 -0
  6. package/build/cjs/lib/bot/decorator.js +6 -1
  7. package/build/cjs/lib/bot/decorators.d.ts +2 -2
  8. package/build/cjs/lib/bot/decorators.js +4 -4
  9. package/build/cjs/lib/bot/index.js +0 -1
  10. package/build/cjs/lib/chat/index.d.ts +381 -204
  11. package/build/cjs/lib/chat/index.js +243 -212
  12. package/build/cjs/lib/contact/index.d.ts +162 -179
  13. package/build/cjs/lib/contact/index.js +96 -191
  14. package/build/cjs/lib/internal.d.ts +40 -0
  15. package/build/cjs/lib/internal.js +38 -0
  16. package/build/cjs/lib/message/index.d.ts +468 -289
  17. package/build/cjs/lib/message/index.js +871 -743
  18. package/build/cjs/lib/status/index.d.ts +60 -70
  19. package/build/cjs/lib/status/index.js +106 -112
  20. package/build/cjs/lib/store/engine/index.d.ts +35 -7
  21. package/build/cjs/lib/store/engine/index.js +6 -4
  22. package/build/cjs/lib/store/engine/lib/file_system/index.d.ts +48 -8
  23. package/build/cjs/lib/store/engine/lib/file_system/index.js +117 -66
  24. package/build/cjs/lib/store/engine/lib/index.d.ts +112 -0
  25. package/build/cjs/lib/store/engine/lib/index.js +212 -0
  26. package/build/cjs/lib/store/engine/lib/redis/index.d.ts +44 -15
  27. package/build/cjs/lib/store/engine/lib/redis/index.js +75 -43
  28. package/build/cjs/lib/store/engine/lib/s3/index.d.ts +44 -1
  29. package/build/cjs/lib/store/engine/lib/s3/index.js +112 -65
  30. package/build/cjs/lib/store/engine/lib/sqlite/index.d.ts +110 -0
  31. package/build/cjs/lib/store/engine/lib/sqlite/index.js +132 -0
  32. package/build/cjs/lib/store/index.d.ts +7 -3
  33. package/build/cjs/lib/store/index.js +14 -5
  34. package/build/cjs/lib/whatsapp/index.d.ts +106 -68
  35. package/build/cjs/lib/whatsapp/index.js +393 -167
  36. package/build/esm/decorators.js +0 -1
  37. package/build/esm/index.d.ts +6 -4
  38. package/build/esm/index.js +5 -3
  39. package/build/esm/lib/bot/decorator.d.ts +2 -0
  40. package/build/esm/lib/bot/decorator.js +6 -1
  41. package/build/esm/lib/bot/decorators.d.ts +2 -2
  42. package/build/esm/lib/bot/decorators.js +4 -4
  43. package/build/esm/lib/bot/index.js +0 -1
  44. package/build/esm/lib/chat/index.d.ts +381 -204
  45. package/build/esm/lib/chat/index.js +243 -212
  46. package/build/esm/lib/contact/index.d.ts +162 -179
  47. package/build/esm/lib/contact/index.js +96 -190
  48. package/build/esm/lib/internal.d.ts +40 -0
  49. package/build/esm/lib/internal.js +34 -0
  50. package/build/esm/lib/message/index.d.ts +468 -289
  51. package/build/esm/lib/message/index.js +866 -738
  52. package/build/esm/lib/status/index.d.ts +60 -70
  53. package/build/esm/lib/status/index.js +105 -111
  54. package/build/esm/lib/store/engine/index.d.ts +35 -7
  55. package/build/esm/lib/store/engine/index.js +4 -3
  56. package/build/esm/lib/store/engine/lib/file_system/index.d.ts +48 -8
  57. package/build/esm/lib/store/engine/lib/file_system/index.js +117 -66
  58. package/build/esm/lib/store/engine/lib/index.d.ts +112 -0
  59. package/build/esm/lib/store/engine/lib/index.js +205 -0
  60. package/build/esm/lib/store/engine/lib/redis/index.d.ts +44 -15
  61. package/build/esm/lib/store/engine/lib/redis/index.js +73 -41
  62. package/build/esm/lib/store/engine/lib/s3/index.d.ts +44 -1
  63. package/build/esm/lib/store/engine/lib/s3/index.js +111 -64
  64. package/build/esm/lib/store/engine/lib/sqlite/index.d.ts +110 -0
  65. package/build/esm/lib/store/engine/lib/sqlite/index.js +128 -0
  66. package/build/esm/lib/store/index.d.ts +7 -3
  67. package/build/esm/lib/store/index.js +13 -5
  68. package/build/esm/lib/whatsapp/index.d.ts +106 -68
  69. package/build/esm/lib/whatsapp/index.js +395 -169
  70. package/package.json +25 -6
  71. package/build/cjs/decorators.js.map +0 -1
  72. package/build/cjs/index.js.map +0 -1
  73. package/build/cjs/lib/bot/decorator.js.map +0 -1
  74. package/build/cjs/lib/bot/decorators.js.map +0 -1
  75. package/build/cjs/lib/bot/index.js.map +0 -1
  76. package/build/cjs/lib/chat/index.js.map +0 -1
  77. package/build/cjs/lib/contact/index.js.map +0 -1
  78. package/build/cjs/lib/message/index.js.map +0 -1
  79. package/build/cjs/lib/status/index.js.map +0 -1
  80. package/build/cjs/lib/store/engine/index.js.map +0 -1
  81. package/build/cjs/lib/store/engine/lib/file_system/index.js.map +0 -1
  82. package/build/cjs/lib/store/engine/lib/redis/index.js.map +0 -1
  83. package/build/cjs/lib/store/engine/lib/s3/index.js.map +0 -1
  84. package/build/cjs/lib/store/index.js.map +0 -1
  85. package/build/cjs/lib/whatsapp/index.js.map +0 -1
  86. package/build/cjs/test.d.ts +0 -1
  87. package/build/cjs/test.js +0 -71
  88. package/build/cjs/test.js.map +0 -1
  89. package/build/esm/decorators.js.map +0 -1
  90. package/build/esm/index.js.map +0 -1
  91. package/build/esm/lib/bot/decorator.js.map +0 -1
  92. package/build/esm/lib/bot/decorators.js.map +0 -1
  93. package/build/esm/lib/bot/index.js.map +0 -1
  94. package/build/esm/lib/chat/index.js.map +0 -1
  95. package/build/esm/lib/contact/index.js.map +0 -1
  96. package/build/esm/lib/message/index.js.map +0 -1
  97. package/build/esm/lib/status/index.js.map +0 -1
  98. package/build/esm/lib/store/engine/index.js.map +0 -1
  99. package/build/esm/lib/store/engine/lib/file_system/index.js.map +0 -1
  100. package/build/esm/lib/store/engine/lib/redis/index.js.map +0 -1
  101. package/build/esm/lib/store/engine/lib/s3/index.js.map +0 -1
  102. package/build/esm/lib/store/index.js.map +0 -1
  103. package/build/esm/lib/whatsapp/index.js.map +0 -1
  104. package/build/esm/test.d.ts +0 -1
  105. package/build/esm/test.js +0 -66
  106. package/build/esm/test.js.map +0 -1
@@ -1,345 +1,550 @@
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;
146
118
  /**
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.
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
153
123
  */
154
- author(): Promise<ContactInstance>;
124
+ author(): Promise<InstanceType<WhatsApp['Contact']>>;
155
125
  /**
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.
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']>>;
132
+ /**
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
137
+ */
138
+ message(): Promise<Message | null>;
139
+ /**
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
+ /** @internal */
455
+ private get _media();
456
+ /** Nombre del archivo. / File name. */
457
+ get name(): string;
458
+ /** Número de páginas (PDF); 0 cuando no aplica. / Page count (PDF); 0 when not applicable. */
459
+ get pages(): number;
460
+ /** Peso en bytes. / Size in bytes. */
461
+ get size(): number;
462
+ content(): Promise<Buffer>;
463
+ }
464
+ /**
465
+ * Mensaje de ubicación, fija o en vivo.
466
+ * Location message, static or live.
467
+ */
468
+ export declare class Location extends Message {
469
+ /** @internal */
243
470
  private get _loc();
244
471
  /** Latitud en grados. / Latitude in degrees. */
245
472
  get lat(): number;
246
473
  /** Longitud en grados. / Longitude in degrees. */
247
474
  get lng(): number;
248
- /** URL de Google Maps apuntando a la coordenada. / Google Maps URL for the coordinate. */
249
- get link(): string;
250
475
  /** true si es ubicación en tiempo real. / true when live location. */
251
476
  get live(): boolean;
477
+ /** URL de Google Maps de la coordenada. / Google Maps URL for the coordinate. */
478
+ get link(): string;
252
479
  }
253
480
  /**
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`.
481
+ * Mensaje de encuesta: opciones con conteo, votos por contacto y voto propio.
482
+ * Poll message: options with counts, per-contact votes and self-voting.
256
483
  */
257
484
  export declare class Poll extends Message {
485
+ /** @internal */
258
486
  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
- */
487
+ /** @internal Updates de voto con los bytes normalizados post-engine. / Vote updates with post-engine normalized bytes. */
488
+ private get _updates();
489
+ /** true si admite varias respuestas. / true when multi-select. */
267
490
  get multiple(): boolean;
268
- /** Opciones con conteo de votos actualizado. / Options with up-to-date vote counts. */
491
+ /** Opciones con su conteo de votos. / Options with their vote counts. */
269
492
  get options(): {
270
- content: string;
493
+ name: string;
271
494
  count: number;
272
495
  }[];
273
496
  /**
274
- * Vota en la encuesta. Acepta un índice o lista de índices (para `multiple`).
275
- * Cifra el voto (HMAC+AES-GCM, igual que baileys.decryptPollVote) y lo enruta al chat
276
- * @lid del contacto con la identidad LID propia, replicando byte a byte un voto entrante
277
- * que sí descifra. El voto ENTRANTE (contacto → este cliente) funciona; el voto propio
278
- * de este cliente aplicado a una encuesta NO se refleja en el teléfono del destinatario
279
- * cuando este cliente es un dispositivo vinculado (companion): estructura, identidades y
280
- * addressing coinciden con un voto válido, pero WhatsApp no lo propaga. Best-effort.
497
+ * Votos individuales: opción elegida y teléfono del votante.
498
+ * Individual votes: chosen option and voter phone.
281
499
  *
282
- * Votes in the poll. Encrypts the vote (HMAC+AES-GCM, same as baileys.decryptPollVote)
283
- * and routes it to the contact's @lid chat with our own LID identity, mirroring a working
284
- * incoming vote byte-for-byte. INCOMING votes work; a self-vote from this client does NOT
285
- * show on the recipient's phone when this client is a linked (companion) device — the
286
- * structure, identities and addressing match a valid vote but WhatsApp won't propagate it.
287
- * Best-effort.
500
+ * @returns Lista de votos / Vote list
501
+ */
502
+ votes(): Promise<{
503
+ name: string;
504
+ contact: string;
505
+ }[]>;
506
+ /**
507
+ * Vota en la encuesta con uno o varios índices. Cifra el voto (HMAC+AES-GCM) y lo
508
+ * enruta al chat @lid con la identidad LID propia. Best-effort: el voto entrante
509
+ * descifra correcto, pero WhatsApp no propaga el voto emitido desde un dispositivo
510
+ * vinculado (companion).
511
+ * Votes in the poll with one or more indexes. Encrypts the vote (HMAC+AES-GCM) and
512
+ * routes it to the @lid chat with the own LID identity. Best-effort: incoming votes
513
+ * decrypt fine, but WhatsApp does not propagate votes emitted from a linked
514
+ * (companion) device.
515
+ *
516
+ * @param index - Índice o índices de la opción / Option index or indexes
517
+ * @returns true si el voto se emitió / true when the vote was relayed
288
518
  */
289
519
  select(index: number | number[]): Promise<boolean>;
290
520
  }
291
521
  /**
292
- * Mensaje de documento. WhatsApp permite enviar cualquier archivo (PDF, imagen,
293
- * audio, video, etc.) como documento; lo que lo distingue de image/video/audio es
294
- * el tipo de mensaje (`documentMessage`), no el mimetype. Hereda `stream()` de la
295
- * clase base; `content()` drena el stream (cache → download).
296
- * Document message. WhatsApp lets you send any file (PDF, image, audio, video…)
297
- * as a document; what sets it apart from image/video/audio is the message type
298
- * (`documentMessage`), not the mimetype. Inherits `stream()` from the base class;
299
- * `content()` drains the stream (cache → download).
300
- */
301
- export declare class Document extends Message {
302
- private get _doc_msg();
303
- /** Nombre del archivo. / File name. */
304
- get file_name(): string;
305
- /** Tamaño en bytes (0 si se desconoce). / Size in bytes (0 if unknown). */
306
- get size(): number;
307
- /** Número de páginas (PDF); 0 si no aplica. / Page count (PDF); 0 when not applicable. */
308
- get pages(): number;
309
- /** Título del documento. / Document title. */
310
- get title(): string;
311
- content(): Promise<Buffer>;
312
- }
313
- /**
314
- * Mensaje de tarjeta(s) de contacto (vCard). Unifica `contactMessage` (uno) y
315
- * `contactsArrayMessage` (varios) bajo una sola lista `contacts`.
316
- * Contact card message (vCard). Unifies `contactMessage` (single) and
317
- * `contactsArrayMessage` (multiple) under a single `contacts` list.
522
+ * Mensaje de tarjeta(s) de contacto.
523
+ * Contact card(s) message.
318
524
  */
319
525
  export declare class VCard extends Message {
320
- /** Contactos de la tarjeta con nombre y teléfono. / Card contacts with name and phone. */
526
+ /** Contactos de la tarjeta. / Card contacts. */
321
527
  get contacts(): {
322
528
  name: string;
323
529
  phone: string;
324
530
  }[];
325
531
  }
326
532
  /**
327
- * Mensaje de evento de calendario (`eventMessage`): nombre, descripción, rango de
328
- * fechas, estado de cancelación, link de unión y ubicación.
329
- * Calendar event message (`eventMessage`): name, description, date range,
330
- * cancellation state, join link and location.
533
+ * Mensaje de evento de calendario.
534
+ * Calendar event message.
331
535
  */
332
536
  export declare class Event extends Message {
537
+ /** @internal */
333
538
  private get _event();
334
539
  /** Nombre del evento. / Event name. */
335
540
  get name(): string;
336
- /** Epoch ms de inicio. / Start epoch ms. */
337
- get start(): number;
338
- /** Epoch ms de fin, o null. / End epoch ms, or null. */
339
- get end(): number | null;
340
- /** true si el evento fue cancelado. / true if the event was canceled. */
541
+ /** Inicio en ISO UTC. / Start as ISO UTC. */
542
+ get start(): string;
543
+ /** Fin en ISO UTC, o null. / End as ISO UTC, or null. */
544
+ get end(): string | null;
545
+ /** true si fue cancelado. / true when canceled. */
341
546
  get canceled(): boolean;
342
- /** Link de unión (audio/video), si aplica. / Join link (audio/video), if any. */
547
+ /** Link de unión, si aplica. / Join link, if any. */
343
548
  get link(): string;
344
549
  /** Ubicación del evento, o null. / Event location, or null. */
345
550
  get place(): {
@@ -348,42 +553,16 @@ export declare class Event extends Message {
348
553
  } | null;
349
554
  }
350
555
  /**
351
- * Factoría que enlaza los statics a `wa` y expone las subclases.
352
- * Factory binding statics to `wa` and exposing subclasses.
556
+ * Factoría de Message: evalúa el tipo y retorna la instancia de la subclase correcta.
557
+ * Acepta el documento persistido o el mensaje crudo de baileys — en ese caso el
558
+ * documento se deriva aquí mismo (id, tipo, autor, caption, mime, fechas).
559
+ * Message factory: evaluates the type and returns the right subclass instance. Accepts
560
+ * the persisted document or the raw baileys message — in that case the document is
561
+ * derived right here (id, type, author, caption, mime, dates).
562
+ *
563
+ * @param wa - Instancia principal / Main WhatsApp instance
564
+ * @param raw - Documento persistido o WAMessage crudo / Persisted document or raw WAMessage
565
+ * @returns Instancia del tipo correcto / Right-type instance
353
566
  */
354
- export declare function message(wa: WhatsApp): {
355
- Text: typeof Text;
356
- Image: typeof Image;
357
- Video: typeof Video;
358
- Audio: typeof Audio;
359
- Gps: typeof Gps;
360
- Poll: typeof Poll;
361
- Document: typeof Document;
362
- VCard: typeof VCard;
363
- Event: typeof Event;
364
- build_message_doc: typeof build_message_doc;
365
- build_instance: (doc: IMessage) => Promise<Message>;
366
- /** Obtiene un mensaje por CID/MID. */
367
- get(cid: string, mid: string): Promise<Message | null>;
368
- /** Pagina mensajes de un chat. */
369
- list(cid: string, offset?: number, limit?: number): Promise<Message[]>;
370
- /** Cuenta mensajes de un chat. */
371
- count(cid: string): Promise<number>;
372
- text(cid: string, caption: string, opts?: SendOptions): Promise<Message | null>;
373
- image(cid: string, buf: Buffer, opts?: SendMediaOptions): Promise<Message | null>;
374
- video(cid: string, buf: Buffer, opts?: SendMediaOptions): Promise<Message | null>;
375
- audio(cid: string, buf: Buffer, opts?: SendAudioOptions): Promise<Message | null>;
376
- location(cid: string, loc: LocationOptions, opts?: SendOptions): Promise<Message | null>;
377
- poll(cid: string, p: PollOptions, opts?: SendPollOptions): Promise<Message | null>;
378
- document(cid: string, buf: Buffer, opts: SendDocumentOptions): Promise<Message | null>;
379
- vcard(cid: string, contacts: VCardInput[], opts?: SendOptions): Promise<Message | null>;
380
- event(cid: string, data: EventInput, opts?: SendOptions): Promise<Message | null>;
381
- edit(cid: string, mid: string, text: string): Promise<boolean>;
382
- delete(cid: string, mid: string, all?: boolean): Promise<boolean>;
383
- react(cid: string, mid: string, emoji: string): Promise<boolean>;
384
- forward(cid: string, mid: string, target: ForwardTarget): Promise<boolean>;
385
- seen(cid: string, mid: string): Promise<boolean>;
386
- star(cid: string, mid: string, value: boolean): Promise<boolean>;
387
- watch(cid: string, mid: string, handler: (msg: Message) => void): () => void;
388
- };
567
+ export declare function message(wa: WhatsApp, raw: Message['_raw'] | WAMessage): Message;
389
568
  export {};