@arcaelas/whatsapp 3.1.1 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/_index.d.ts +14 -0
- package/build/cjs/_index.js +366 -0
- package/build/cjs/_index.js.map +1 -0
- package/build/cjs/decorators.d.ts +9 -0
- package/build/cjs/decorators.js +26 -0
- package/build/cjs/decorators.js.map +1 -0
- package/build/cjs/index.d.ts +11 -0
- package/build/cjs/index.js +21 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/lib/bot/decorator.d.ts +77 -0
- package/build/cjs/lib/bot/decorator.js +219 -0
- package/build/cjs/lib/bot/decorator.js.map +1 -0
- package/build/cjs/lib/bot/decorators.d.ts +113 -0
- package/build/cjs/lib/bot/decorators.js +253 -0
- package/build/cjs/lib/bot/decorators.js.map +1 -0
- package/build/cjs/lib/bot/index.d.ts +3 -0
- package/build/cjs/lib/bot/index.js +20 -0
- package/build/cjs/lib/bot/index.js.map +1 -0
- package/build/cjs/lib/chat/index.d.ts +252 -0
- package/build/cjs/lib/chat/index.js +314 -0
- package/build/cjs/lib/chat/index.js.map +1 -0
- package/build/cjs/lib/contact/index.d.ts +203 -0
- package/build/cjs/lib/contact/index.js +226 -0
- package/build/cjs/lib/contact/index.js.map +1 -0
- package/build/cjs/lib/message/index.d.ts +277 -0
- package/build/cjs/lib/message/index.js +773 -0
- package/build/cjs/lib/message/index.js.map +1 -0
- package/build/cjs/lib/status/index.d.ts +85 -0
- package/build/cjs/lib/status/index.js +137 -0
- package/build/cjs/lib/status/index.js.map +1 -0
- package/build/cjs/lib/store/engine/index.d.ts +34 -0
- package/build/cjs/lib/store/engine/index.js +13 -0
- package/build/cjs/lib/store/engine/index.js.map +1 -0
- package/build/cjs/lib/store/engine/lib/file_system/index.d.ts +56 -0
- package/build/cjs/lib/store/engine/lib/file_system/index.js +160 -0
- package/build/cjs/lib/store/engine/lib/file_system/index.js.map +1 -0
- package/build/cjs/lib/store/engine/lib/redis/index.d.ts +82 -0
- package/build/cjs/lib/store/engine/lib/redis/index.js +132 -0
- package/build/cjs/lib/store/engine/lib/redis/index.js.map +1 -0
- package/build/cjs/lib/store/index.d.ts +22 -0
- package/build/cjs/lib/store/index.js +38 -0
- package/build/cjs/lib/store/index.js.map +1 -0
- package/build/cjs/lib/whatsapp/index.d.ts +185 -0
- package/build/cjs/lib/whatsapp/index.js +882 -0
- package/build/cjs/lib/whatsapp/index.js.map +1 -0
- package/build/cjs/package.json +1 -0
- package/build/esm/_index.d.ts +14 -0
- package/build/esm/_index.js +364 -0
- package/build/esm/_index.js.map +1 -0
- package/build/esm/decorators.d.ts +9 -0
- package/build/esm/decorators.js +9 -0
- package/build/esm/decorators.js.map +1 -0
- package/build/esm/index.d.ts +11 -0
- package/build/esm/index.js +9 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/lib/bot/decorator.d.ts +77 -0
- package/build/esm/lib/bot/decorator.js +210 -0
- package/build/esm/lib/bot/decorator.js.map +1 -0
- package/build/esm/lib/bot/decorators.d.ts +113 -0
- package/build/esm/lib/bot/decorators.js +242 -0
- package/build/esm/lib/bot/decorators.js.map +1 -0
- package/build/esm/lib/bot/index.d.ts +3 -0
- package/build/esm/lib/bot/index.js +3 -0
- package/build/esm/lib/bot/index.js.map +1 -0
- package/build/esm/lib/chat/index.d.ts +252 -0
- package/build/esm/lib/chat/index.js +309 -0
- package/build/esm/lib/chat/index.js.map +1 -0
- package/build/esm/lib/contact/index.d.ts +203 -0
- package/build/esm/lib/contact/index.js +221 -0
- package/build/esm/lib/contact/index.js.map +1 -0
- package/build/esm/lib/message/index.d.ts +277 -0
- package/build/esm/lib/message/index.js +761 -0
- package/build/esm/lib/message/index.js.map +1 -0
- package/build/esm/lib/status/index.d.ts +85 -0
- package/build/esm/lib/status/index.js +133 -0
- package/build/esm/lib/status/index.js.map +1 -0
- package/build/esm/lib/store/engine/index.d.ts +34 -0
- package/build/esm/lib/store/engine/index.js +8 -0
- package/build/esm/lib/store/engine/index.js.map +1 -0
- package/build/esm/lib/store/engine/lib/file_system/index.d.ts +56 -0
- package/build/esm/lib/store/engine/lib/file_system/index.js +156 -0
- package/build/esm/lib/store/engine/lib/file_system/index.js.map +1 -0
- package/build/esm/lib/store/engine/lib/redis/index.d.ts +82 -0
- package/build/esm/lib/store/engine/lib/redis/index.js +128 -0
- package/build/esm/lib/store/engine/lib/redis/index.js.map +1 -0
- package/build/esm/lib/store/index.d.ts +22 -0
- package/build/esm/lib/store/index.js +31 -0
- package/build/esm/lib/store/index.js.map +1 -0
- package/build/esm/lib/whatsapp/index.d.ts +185 -0
- package/build/esm/lib/whatsapp/index.js +842 -0
- package/build/esm/lib/whatsapp/index.js.map +1 -0
- package/build/esm/package.json +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
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.
|
|
5
|
+
*/
|
|
6
|
+
import { type WAMessage } from 'baileys';
|
|
7
|
+
import { Readable } from 'node:stream';
|
|
8
|
+
import { Chat, chat } from '../../lib/chat/index.js';
|
|
9
|
+
import { Contact, contact } from '../../lib/contact/index.js';
|
|
10
|
+
import type { WhatsApp } from '../../lib/whatsapp/index.js';
|
|
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';
|
|
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 {
|
|
26
|
+
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 LocationOptions {
|
|
39
|
+
lat: number;
|
|
40
|
+
lng: number;
|
|
41
|
+
live?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface PollOptions {
|
|
44
|
+
content: string;
|
|
45
|
+
options: Array<{
|
|
46
|
+
content: string;
|
|
47
|
+
}>;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Documento persistido del mensaje.
|
|
51
|
+
*/
|
|
52
|
+
export interface IMessage {
|
|
53
|
+
id: string;
|
|
54
|
+
cid: string;
|
|
55
|
+
mid: string | null;
|
|
56
|
+
me: boolean;
|
|
57
|
+
type: MessageType;
|
|
58
|
+
author: string;
|
|
59
|
+
status: MessageStatus;
|
|
60
|
+
starred: boolean;
|
|
61
|
+
forwarded: boolean;
|
|
62
|
+
created_at: number;
|
|
63
|
+
deleted_at: number | null;
|
|
64
|
+
mime: string;
|
|
65
|
+
caption: string;
|
|
66
|
+
edited: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Solo para polls: discriminador explícito de selección múltiple seteado al enviar.
|
|
69
|
+
* Cuando está definido, `Poll.multiple` lo prefiere sobre el conteo del proto
|
|
70
|
+
* (WhatsApp normaliza `selectableOptionsCount` en el echo de polls auto-emitidos
|
|
71
|
+
* y pierde el discriminador, por eso necesitamos persistirlo nosotros).
|
|
72
|
+
* Poll-only: explicit multi-select flag set at send time. When defined, `Poll.multiple`
|
|
73
|
+
* prefers it over the proto count (WhatsApp normalizes `selectableOptionsCount` on
|
|
74
|
+
* own-poll echo, losing the discriminator).
|
|
75
|
+
*/
|
|
76
|
+
multiple?: boolean;
|
|
77
|
+
raw: WAMessage;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Construye el documento IMessage desde el raw de baileys.
|
|
81
|
+
*/
|
|
82
|
+
export declare function build_message_doc(raw: WAMessage, self_id?: string, edited?: boolean): IMessage;
|
|
83
|
+
/**
|
|
84
|
+
* Clase base del mensaje. Una sola clase — toda la API de instancia vive aquí.
|
|
85
|
+
* Base message class. Single class — all instance API lives here.
|
|
86
|
+
*/
|
|
87
|
+
export declare class Message {
|
|
88
|
+
/** @internal */
|
|
89
|
+
protected readonly _wa: WhatsApp;
|
|
90
|
+
/** @internal */
|
|
91
|
+
protected readonly _doc: IMessage;
|
|
92
|
+
/** @internal Cache de la promesa de `author()` para evitar engine round-trips repetidos. */
|
|
93
|
+
private _author_cache;
|
|
94
|
+
/** @internal Cache de la promesa de `chat()` para evitar engine round-trips repetidos. */
|
|
95
|
+
private _chat_cache;
|
|
96
|
+
constructor(options: {
|
|
97
|
+
wa: WhatsApp;
|
|
98
|
+
doc: IMessage;
|
|
99
|
+
});
|
|
100
|
+
get id(): string;
|
|
101
|
+
get cid(): string;
|
|
102
|
+
get type(): MessageType;
|
|
103
|
+
/** JID del autor del mensaje. Para acceso síncrono sin hidratar el Contact. */
|
|
104
|
+
get from(): string;
|
|
105
|
+
/** MIME type del contenido. `text/plain` para texto, `application/json` para location/poll, mimetype real para media. */
|
|
106
|
+
get mime(): string;
|
|
107
|
+
get mid(): string | null;
|
|
108
|
+
get me(): boolean;
|
|
109
|
+
get caption(): string;
|
|
110
|
+
get starred(): boolean;
|
|
111
|
+
get forwarded(): boolean;
|
|
112
|
+
get once(): boolean;
|
|
113
|
+
get created_at(): number;
|
|
114
|
+
get deleted_at(): number | null;
|
|
115
|
+
get status(): MessageStatus;
|
|
116
|
+
get edited(): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Contacto del autor (resuelve vía `wa.Contact.get`; fallback a instancia mínima).
|
|
119
|
+
* Memoizado por instancia: la primera llamada va al engine; las siguientes
|
|
120
|
+
* reutilizan la misma promesa sin nuevos round-trips.
|
|
121
|
+
* Author contact (resolves via `wa.Contact.get`; falls back to a minimal instance).
|
|
122
|
+
* Instance-memoized: first call hits the engine; subsequent calls reuse the
|
|
123
|
+
* same promise without further round-trips.
|
|
124
|
+
*/
|
|
125
|
+
author(): Promise<ContactInstance>;
|
|
126
|
+
/**
|
|
127
|
+
* Chat al que pertenece el mensaje. Memoizado por instancia: la primera llamada
|
|
128
|
+
* va al engine; las siguientes reutilizan la misma promesa.
|
|
129
|
+
* Chat the message belongs to. Instance-memoized: first call hits the engine;
|
|
130
|
+
* subsequent calls reuse the same promise.
|
|
131
|
+
*/
|
|
132
|
+
chat(): Promise<ChatInstance>;
|
|
133
|
+
/** Contenido sin parsear, directo del engine. Las subclases override según su tipo. */
|
|
134
|
+
content(): Promise<Buffer>;
|
|
135
|
+
/**
|
|
136
|
+
* Devuelve un `Readable` con los bytes del mensaje. Para media (image/video/audio)
|
|
137
|
+
* lee desde el cache del engine o, si falta, descarga desde baileys. Para text/location/poll
|
|
138
|
+
* retorna el mismo binario que `content()` envuelto en un Readable.
|
|
139
|
+
* Returns a `Readable` of the message bytes. For media (image/video/audio) it reads
|
|
140
|
+
* from the engine cache or, if missing, downloads from baileys. For text/location/poll
|
|
141
|
+
* it wraps the `content()` buffer in a Readable.
|
|
142
|
+
*/
|
|
143
|
+
stream(): Promise<Readable>;
|
|
144
|
+
/** Reacciona al mensaje (emoji vacío para retirar). */
|
|
145
|
+
react(emoji: string): Promise<boolean>;
|
|
146
|
+
/** Reenvía el mensaje a un destino (CID, Chat o Contact). */
|
|
147
|
+
forward(target: ForwardTarget): Promise<boolean>;
|
|
148
|
+
/** Marca el mensaje como leído. */
|
|
149
|
+
seen(): Promise<boolean>;
|
|
150
|
+
/** Destaca/retira destacado del mensaje. */
|
|
151
|
+
star(value: boolean): Promise<boolean>;
|
|
152
|
+
/** Elimina el mensaje. `all=true` (default) borra para todos; `all=false` borra sólo en mi dispositivo. */
|
|
153
|
+
delete(all?: boolean): Promise<boolean>;
|
|
154
|
+
/** Edita el texto/caption del mensaje (solo propios editables). */
|
|
155
|
+
edit(text: string): Promise<boolean>;
|
|
156
|
+
/** Observa cambios sobre este mensaje. Retorna unsubscribe. / Watches this message. Returns unsubscribe. */
|
|
157
|
+
watch(handler: (msg: Message) => void): () => void;
|
|
158
|
+
/** Responde con texto. */
|
|
159
|
+
text(caption: string, opts?: SendOptions): Promise<Message | null>;
|
|
160
|
+
/** Responde con imagen. */
|
|
161
|
+
image(buf: Buffer, opts?: SendMediaOptions): Promise<Message | null>;
|
|
162
|
+
/** Responde con video. */
|
|
163
|
+
video(buf: Buffer, opts?: SendMediaOptions): Promise<Message | null>;
|
|
164
|
+
/** Responde con audio. */
|
|
165
|
+
audio(buf: Buffer, opts?: SendAudioOptions): Promise<Message | null>;
|
|
166
|
+
/** Responde con ubicación. */
|
|
167
|
+
location(loc: LocationOptions, opts?: SendOptions): Promise<Message | null>;
|
|
168
|
+
/** Responde con encuesta. */
|
|
169
|
+
poll(poll: PollOptions, opts?: SendPollOptions): Promise<Message | null>;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Mensaje de texto. Override `content()` para retornar el caption como Buffer sin pasar por engine.
|
|
173
|
+
* Text message. Overrides `content()` returning caption as Buffer directly.
|
|
174
|
+
*/
|
|
175
|
+
export declare class Text extends Message {
|
|
176
|
+
content(): Promise<Buffer>;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Mensaje de imagen. Hereda `stream()` de la clase base; `content()` drena el stream.
|
|
180
|
+
* Image message. Inherits `stream()` from the base class; `content()` drains the stream.
|
|
181
|
+
*/
|
|
182
|
+
export declare class Image extends Message {
|
|
183
|
+
content(): Promise<Buffer>;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Mensaje de video. Hereda `stream()` de la clase base; `content()` drena el stream.
|
|
187
|
+
* Video message. Inherits `stream()` from the base class; `content()` drains the stream.
|
|
188
|
+
*/
|
|
189
|
+
export declare class Video extends Message {
|
|
190
|
+
content(): Promise<Buffer>;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Mensaje de audio. Hereda `stream()` de la clase base; `content()` drena el stream.
|
|
194
|
+
* `ptt` indica si es nota de voz (push-to-talk).
|
|
195
|
+
* Audio message. Inherits `stream()` from the base class; `content()` drains the stream.
|
|
196
|
+
* `ptt` flags voice notes.
|
|
197
|
+
*/
|
|
198
|
+
export declare class Audio extends Message {
|
|
199
|
+
/** true si es nota de voz (push-to-talk). / true if push-to-talk voice note. */
|
|
200
|
+
get ptt(): boolean;
|
|
201
|
+
content(): Promise<Buffer>;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Mensaje de ubicación. Agrega getters sync `lat`, `lng`, `link` derivados del raw.
|
|
205
|
+
* Location message. Adds sync getters `lat`, `lng`, `link` derived from raw.
|
|
206
|
+
*/
|
|
207
|
+
export declare class Gps extends Message {
|
|
208
|
+
private get _loc();
|
|
209
|
+
/** Latitud en grados. / Latitude in degrees. */
|
|
210
|
+
get lat(): number;
|
|
211
|
+
/** Longitud en grados. / Longitude in degrees. */
|
|
212
|
+
get lng(): number;
|
|
213
|
+
/** URL de Google Maps apuntando a la coordenada. / Google Maps URL for the coordinate. */
|
|
214
|
+
get link(): string;
|
|
215
|
+
/** true si es ubicación en tiempo real. / true when live location. */
|
|
216
|
+
get live(): boolean;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Mensaje de encuesta. `caption` es la pregunta (heredada); agrega `options[]` con conteo y `multiple`.
|
|
220
|
+
* Poll message. `caption` is the question (inherited); adds `options[]` with counts and `multiple`.
|
|
221
|
+
*/
|
|
222
|
+
export declare class Poll extends Message {
|
|
223
|
+
private get _poll();
|
|
224
|
+
/**
|
|
225
|
+
* true si admite múltiples respuestas. Lee primero el flag explícito persistido
|
|
226
|
+
* al enviar (caso propio, donde WhatsApp pierde el discriminador en el echo);
|
|
227
|
+
* fallback al `selectableOptionsCount` del proto (polls foráneos o de UI móvil).
|
|
228
|
+
* true if the poll accepts multiple answers. Prefers the persisted send-time
|
|
229
|
+
* flag (own polls, since WhatsApp drops the discriminator on echo); falls back
|
|
230
|
+
* to the proto `selectableOptionsCount` (foreign or mobile-UI polls).
|
|
231
|
+
*/
|
|
232
|
+
get multiple(): boolean;
|
|
233
|
+
/** Opciones con conteo de votos actualizado. / Options with up-to-date vote counts. */
|
|
234
|
+
get options(): {
|
|
235
|
+
content: string;
|
|
236
|
+
count: number;
|
|
237
|
+
}[];
|
|
238
|
+
/**
|
|
239
|
+
* Vota en la encuesta. Acepta un índice o lista de índices (para `multiple`).
|
|
240
|
+
* Votes in the poll. Accepts a single index or list (for `multiple`).
|
|
241
|
+
*/
|
|
242
|
+
select(index: number | number[]): Promise<boolean>;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Factoría que enlaza los statics a `wa` y expone las subclases.
|
|
246
|
+
* Factory binding statics to `wa` and exposing subclasses.
|
|
247
|
+
*/
|
|
248
|
+
export declare function message(wa: WhatsApp): {
|
|
249
|
+
Text: typeof Text;
|
|
250
|
+
Image: typeof Image;
|
|
251
|
+
Video: typeof Video;
|
|
252
|
+
Audio: typeof Audio;
|
|
253
|
+
Gps: typeof Gps;
|
|
254
|
+
Poll: typeof Poll;
|
|
255
|
+
build_message_doc: typeof build_message_doc;
|
|
256
|
+
build_instance: (doc: IMessage) => Promise<Message>;
|
|
257
|
+
/** Obtiene un mensaje por CID/MID. */
|
|
258
|
+
get(cid: string, mid: string): Promise<Message | null>;
|
|
259
|
+
/** Pagina mensajes de un chat. */
|
|
260
|
+
list(cid: string, offset?: number, limit?: number): Promise<Message[]>;
|
|
261
|
+
/** Cuenta mensajes de un chat. */
|
|
262
|
+
count(cid: string): Promise<number>;
|
|
263
|
+
text(cid: string, caption: string, opts?: SendOptions): Promise<Message | null>;
|
|
264
|
+
image(cid: string, buf: Buffer, opts?: SendMediaOptions): Promise<Message | null>;
|
|
265
|
+
video(cid: string, buf: Buffer, opts?: SendMediaOptions): Promise<Message | null>;
|
|
266
|
+
audio(cid: string, buf: Buffer, opts?: SendAudioOptions): Promise<Message | null>;
|
|
267
|
+
location(cid: string, loc: LocationOptions, opts?: SendOptions): Promise<Message | null>;
|
|
268
|
+
poll(cid: string, p: PollOptions, opts?: SendPollOptions): Promise<Message | null>;
|
|
269
|
+
edit(cid: string, mid: string, text: string): Promise<boolean>;
|
|
270
|
+
delete(cid: string, mid: string, all?: boolean): Promise<boolean>;
|
|
271
|
+
react(cid: string, mid: string, emoji: string): Promise<boolean>;
|
|
272
|
+
forward(cid: string, mid: string, target: ForwardTarget): Promise<boolean>;
|
|
273
|
+
seen(cid: string, mid: string): Promise<boolean>;
|
|
274
|
+
star(cid: string, mid: string, value: boolean): Promise<boolean>;
|
|
275
|
+
watch(cid: string, mid: string, handler: (msg: Message) => void): () => void;
|
|
276
|
+
};
|
|
277
|
+
export {};
|