@arcaelas/whatsapp 6.1.3 → 7.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.
- package/README.md +19 -15
- package/build/cjs/index.d.ts +9 -5
- package/build/cjs/index.js +8 -7
- package/build/cjs/lib/bot/decorator.d.ts +2 -9
- package/build/cjs/lib/bot/decorator.js +0 -1
- package/build/cjs/lib/bot/decorators.d.ts +48 -4
- package/build/cjs/lib/bot/decorators.js +2 -2
- package/build/cjs/lib/chat/index.d.ts +144 -152
- package/build/cjs/lib/chat/index.js +138 -209
- package/build/cjs/lib/contact/index.d.ts +114 -80
- package/build/cjs/lib/contact/index.js +187 -94
- package/build/cjs/lib/message/index.d.ts +400 -321
- package/build/cjs/lib/message/index.js +425 -913
- package/build/cjs/lib/status/index.d.ts +22 -33
- package/build/cjs/lib/status/index.js +52 -93
- package/build/cjs/lib/store/index.d.ts +16 -0
- package/build/cjs/lib/store/index.js +29 -3
- package/build/cjs/lib/whatsapp/index.d.ts +44 -212
- package/build/cjs/lib/whatsapp/index.js +473 -1067
- package/build/esm/index.d.ts +9 -5
- package/build/esm/index.js +6 -4
- package/build/esm/lib/bot/decorator.d.ts +2 -9
- package/build/esm/lib/bot/decorator.js +1 -1
- package/build/esm/lib/bot/decorators.d.ts +48 -4
- package/build/esm/lib/bot/decorators.js +2 -2
- package/build/esm/lib/chat/index.d.ts +144 -152
- package/build/esm/lib/chat/index.js +139 -209
- package/build/esm/lib/contact/index.d.ts +114 -80
- package/build/esm/lib/contact/index.js +186 -94
- package/build/esm/lib/message/index.d.ts +400 -321
- package/build/esm/lib/message/index.js +422 -913
- package/build/esm/lib/status/index.d.ts +22 -33
- package/build/esm/lib/status/index.js +49 -93
- package/build/esm/lib/store/index.d.ts +16 -0
- package/build/esm/lib/store/index.js +25 -0
- package/build/esm/lib/whatsapp/index.d.ts +44 -212
- package/build/esm/lib/whatsapp/index.js +476 -1069
- package/package.json +1 -1
- package/build/cjs/lib/internal.d.ts +0 -40
- package/build/cjs/lib/internal.js +0 -38
- package/build/esm/lib/internal.d.ts +0 -40
- package/build/esm/lib/internal.js +0 -34
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ Node 20 o superior. El paquete se distribuye en ESM y CJS.
|
|
|
44
44
|
| Paquete | Necesario para |
|
|
45
45
|
| --- | --- |
|
|
46
46
|
| `@aws-sdk/client-s3` | `S3Engine` |
|
|
47
|
-
| `sharp` o `jimp` | `
|
|
47
|
+
| `sharp` o `jimp` | `cuenta.picture(...)` |
|
|
48
48
|
|
|
49
49
|
`RedisEngine` y `SQLiteEngine` no necesitan nada: reciben el cliente ya construido, así que servís vos el `ioredis`, `better-sqlite3` o `node:sqlite` que prefieras.
|
|
50
50
|
|
|
@@ -93,8 +93,8 @@ new WhatsApp({ engine, phone?, method?, autoclean?, reconnect?, sync? })
|
|
|
93
93
|
|
|
94
94
|
```ts
|
|
95
95
|
wa.engine // motor de persistencia
|
|
96
|
-
wa.
|
|
97
|
-
wa.
|
|
96
|
+
wa.Contact / wa.Chat / wa.Message // entidades, publicadas al conectar
|
|
97
|
+
await wa.account() // Account de la cuenta autenticada, o null sin usuario
|
|
98
98
|
|
|
99
99
|
await wa.connect(callback) // callback recibe el PIN (string) o el QR (Buffer PNG)
|
|
100
100
|
await wa.disconnect({ silent?, destroy? })
|
|
@@ -103,33 +103,37 @@ wa.on(event, handler) // devuelve la función para desuscribirse
|
|
|
103
103
|
wa.once(event, handler)
|
|
104
104
|
wa.off(event, handler)
|
|
105
105
|
wa.emit(event, ...args)
|
|
106
|
-
|
|
107
|
-
await wa.profile({ name?, content?, photo? }) // nombre público, bio y foto
|
|
108
|
-
await wa.feed({ content?, caption?, contacts }) // publica un estado
|
|
109
106
|
```
|
|
110
107
|
|
|
111
|
-
|
|
108
|
+
Las entidades y `account()` se publican dentro de `connect`, cuando el socket ya existe: antes de la primera conexión no están definidas. El estado interno (socket, credenciales, reintentos) vive en el closure de `connect` — no hay nada que hurgar en la instancia.
|
|
109
|
+
|
|
110
|
+
### La cuenta: `Account`
|
|
112
111
|
|
|
113
|
-
|
|
112
|
+
`await wa.account()` devuelve un `Account extends Contact`: todos los getters de un contacto (`name`, `phone`, `jid`, `lid`, `photo`) más las operaciones que solo existen para uno mismo.
|
|
114
113
|
|
|
115
114
|
```ts
|
|
116
|
-
await wa.
|
|
117
|
-
|
|
118
|
-
await
|
|
115
|
+
const cuenta = await wa.account();
|
|
116
|
+
|
|
117
|
+
await cuenta.rename('Ventas'); // nombre público
|
|
118
|
+
await cuenta.picture(buffer); // foto de perfil (Buffer o URL)
|
|
119
|
+
await cuenta.picture(null); // la elimina
|
|
120
|
+
await cuenta.content(); // lee la bio
|
|
121
|
+
await cuenta.content('Atendemos 9-18h'); // la actualiza
|
|
122
|
+
await cuenta.online(true); // presencia online/offline
|
|
119
123
|
|
|
120
|
-
const post = await
|
|
124
|
+
const post = await cuenta.post({
|
|
121
125
|
caption: '¡Estamos en vivo!',
|
|
122
|
-
|
|
126
|
+
audience: [contacto, 5491112345678, '584121234567@s.whatsapp.net', '999@lid'],
|
|
123
127
|
});
|
|
124
128
|
```
|
|
125
129
|
|
|
126
|
-
`
|
|
130
|
+
`audience` no es opcional: WhatsApp no entrega el estado a nadie fuera de esa lista, y acepta instancias de `Contact`, JIDs, LIDs o teléfonos. Con `buffer` se publica imagen o video —el tipo se deduce de la firma del binario— y `caption` queda como pie. La presencia arranca en offline (`markOnlineOnConnect: false`): `online()` es el único interruptor.
|
|
127
131
|
|
|
128
132
|
---
|
|
129
133
|
|
|
130
134
|
## Entidades
|
|
131
135
|
|
|
132
|
-
Cada entidad expone getters puros sobre su documento y métodos que actúan contra WhatsApp. `wa.Contact`, `wa.Chat` y `wa.Message` ya vienen ligados
|
|
136
|
+
Cada entidad expone getters puros sobre su documento y métodos que actúan contra WhatsApp. `wa.Contact`, `wa.Chat` y `wa.Message` ya vienen ligados a la sesión; las clases sueltas se importan del paquete cuando querés `instanceof`.
|
|
133
137
|
|
|
134
138
|
### Contact
|
|
135
139
|
|
package/build/cjs/index.d.ts
CHANGED
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
* @description Punto de entrada público de la librería @arcaelas/whatsapp.
|
|
4
4
|
* Public entry point of the @arcaelas/whatsapp library.
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
export
|
|
6
|
+
import WhatsApp from './lib/whatsapp';
|
|
7
|
+
export { WhatsApp };
|
|
8
|
+
export default WhatsApp;
|
|
9
|
+
export type IWhatsApp = ConstructorParameters<typeof WhatsApp>[0];
|
|
10
|
+
export type DisconnectOptions = NonNullable<Parameters<WhatsApp['disconnect']>[0]>;
|
|
11
|
+
export type ReconnectOption = NonNullable<IWhatsApp['reconnect']>;
|
|
8
12
|
export { FileSystemEngine, RedisEngine, S3Engine, SQLiteEngine, serialize, deserialize } from './lib/store';
|
|
9
13
|
export type { Engine, RedisClient, SQLiteDatabase } from './lib/store';
|
|
10
|
-
export { Contact, contact } from './lib/contact';
|
|
11
|
-
export { Chat, chat } from './lib/chat';
|
|
12
|
-
export { Message, message, Text, Image, Video, Audio, Sticker, Document, Location, Poll, VCard, Event } from './lib/message';
|
|
14
|
+
export { default as Contact, contact, Account } from './lib/contact';
|
|
15
|
+
export { default as Chat, chat } from './lib/chat';
|
|
16
|
+
export { default as Message, message, Text, Image, Video, Audio, Sticker, Document, Location, Poll, VCard, Event } from './lib/message';
|
|
13
17
|
export { Feed, TTL_MS as FEED_TTL_MS } from './lib/status';
|
package/build/cjs/index.js
CHANGED
|
@@ -8,10 +8,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
8
8
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.FEED_TTL_MS = exports.Feed = exports.Event = exports.VCard = exports.Poll = exports.Location = exports.Document = exports.Sticker = exports.Audio = exports.Video = exports.Image = exports.Text = exports.message = exports.Message = exports.chat = exports.Chat = exports.contact = exports.Contact = exports.deserialize = exports.serialize = exports.SQLiteEngine = exports.S3Engine = exports.RedisEngine = exports.FileSystemEngine = exports.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
exports.FEED_TTL_MS = exports.Feed = exports.Event = exports.VCard = exports.Poll = exports.Location = exports.Document = exports.Sticker = exports.Audio = exports.Video = exports.Image = exports.Text = exports.message = exports.Message = exports.chat = exports.Chat = exports.Account = exports.contact = exports.Contact = exports.deserialize = exports.serialize = exports.SQLiteEngine = exports.S3Engine = exports.RedisEngine = exports.FileSystemEngine = exports.WhatsApp = void 0;
|
|
12
|
+
const whatsapp_1 = __importDefault(require("./lib/whatsapp"));
|
|
13
|
+
exports.WhatsApp = whatsapp_1.default;
|
|
14
|
+
exports.default = whatsapp_1.default;
|
|
15
15
|
var store_1 = require("./lib/store");
|
|
16
16
|
Object.defineProperty(exports, "FileSystemEngine", { enumerable: true, get: function () { return store_1.FileSystemEngine; } });
|
|
17
17
|
Object.defineProperty(exports, "RedisEngine", { enumerable: true, get: function () { return store_1.RedisEngine; } });
|
|
@@ -20,13 +20,14 @@ Object.defineProperty(exports, "SQLiteEngine", { enumerable: true, get: function
|
|
|
20
20
|
Object.defineProperty(exports, "serialize", { enumerable: true, get: function () { return store_1.serialize; } });
|
|
21
21
|
Object.defineProperty(exports, "deserialize", { enumerable: true, get: function () { return store_1.deserialize; } });
|
|
22
22
|
var contact_1 = require("./lib/contact");
|
|
23
|
-
Object.defineProperty(exports, "Contact", { enumerable: true, get: function () { return contact_1.
|
|
23
|
+
Object.defineProperty(exports, "Contact", { enumerable: true, get: function () { return __importDefault(contact_1).default; } });
|
|
24
24
|
Object.defineProperty(exports, "contact", { enumerable: true, get: function () { return contact_1.contact; } });
|
|
25
|
+
Object.defineProperty(exports, "Account", { enumerable: true, get: function () { return contact_1.Account; } });
|
|
25
26
|
var chat_1 = require("./lib/chat");
|
|
26
|
-
Object.defineProperty(exports, "Chat", { enumerable: true, get: function () { return chat_1.
|
|
27
|
+
Object.defineProperty(exports, "Chat", { enumerable: true, get: function () { return __importDefault(chat_1).default; } });
|
|
27
28
|
Object.defineProperty(exports, "chat", { enumerable: true, get: function () { return chat_1.chat; } });
|
|
28
29
|
var message_1 = require("./lib/message");
|
|
29
|
-
Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return message_1.
|
|
30
|
+
Object.defineProperty(exports, "Message", { enumerable: true, get: function () { return __importDefault(message_1).default; } });
|
|
30
31
|
Object.defineProperty(exports, "message", { enumerable: true, get: function () { return message_1.message; } });
|
|
31
32
|
Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return message_1.Text; } });
|
|
32
33
|
Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return message_1.Image; } });
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* @description Infraestructura base de decoradores Stage 3 sobre WhatsApp.
|
|
4
4
|
* Base infrastructure for Stage 3 decorators over WhatsApp.
|
|
5
5
|
*/
|
|
6
|
-
import WhatsApp
|
|
6
|
+
import WhatsApp from '../../lib/whatsapp';
|
|
7
|
+
type IWhatsApp = ConstructorParameters<typeof WhatsApp>[0];
|
|
7
8
|
export declare const HANDLERS: unique symbol;
|
|
8
9
|
export interface HandlerMeta {
|
|
9
10
|
method: string;
|
|
@@ -21,14 +22,6 @@ export interface BotSchema {
|
|
|
21
22
|
workflows: Record<string, WorkflowStep[]>;
|
|
22
23
|
}
|
|
23
24
|
type Metadata = Record<string | symbol, unknown>;
|
|
24
|
-
/**
|
|
25
|
-
* Recupera o inicializa el `BotSchema` almacenado en la metadata del contexto.
|
|
26
|
-
* Retrieves or initializes the `BotSchema` stored in the context metadata.
|
|
27
|
-
*
|
|
28
|
-
* @param metadata - Objeto metadata del contexto del decorador / Decorator context metadata object
|
|
29
|
-
* @returns Schema del bot garantizado con `handlers` y `workflows` / Bot schema guaranteed to have `handlers` and `workflows`
|
|
30
|
-
*/
|
|
31
|
-
export declare function ensure_schema(metadata: Metadata): BotSchema;
|
|
32
25
|
/**
|
|
33
26
|
* Recupera o inicializa el schema del bot y la entrada del método indicado.
|
|
34
27
|
* Retrieves or initializes the bot schema and the entry for the given method.
|
|
@@ -9,7 +9,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
};
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.WhatsAppBot = exports.HANDLERS = void 0;
|
|
12
|
-
exports.ensure_schema = ensure_schema;
|
|
13
12
|
exports.resolve = resolve;
|
|
14
13
|
exports.register_workflow_step = register_workflow_step;
|
|
15
14
|
exports.decorator = decorator;
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* @description Decoradores públicos del bot.
|
|
4
4
|
* Public bot decorators.
|
|
5
5
|
*/
|
|
6
|
-
import type
|
|
6
|
+
import type WhatsApp from '../../lib/whatsapp';
|
|
7
|
+
type IWhatsApp = ConstructorParameters<typeof WhatsApp>[0];
|
|
7
8
|
import { WhatsAppBot } from './decorator';
|
|
8
9
|
/**
|
|
9
10
|
* Registra el método como listener del evento indicado. Apilable: varios `@on`
|
|
@@ -13,7 +14,21 @@ import { WhatsAppBot } from './decorator';
|
|
|
13
14
|
*
|
|
14
15
|
* @param event - Nombre del evento del cliente / Client event name
|
|
15
16
|
*/
|
|
16
|
-
export declare const on: (event: string) => (_value: unknown, context: ClassMethodDecoratorContext
|
|
17
|
+
export declare const on: (event: string) => (_value: unknown, context: ClassMethodDecoratorContext
|
|
18
|
+
/**
|
|
19
|
+
* Ejecuta el método con un retardo de `ms` milisegundos entre ejecuciones,
|
|
20
|
+
* usando `setTimeout` recursivo. A diferencia de `@every`, la siguiente
|
|
21
|
+
* ejecución solo empieza cuando la anterior ha terminado — nunca hay
|
|
22
|
+
* ejecuciones en paralelo. Arranca en `connected` y se detiene en
|
|
23
|
+
* `disconnected`.
|
|
24
|
+
* Runs the method with `ms` milliseconds between executions using a recursive
|
|
25
|
+
* `setTimeout`. Unlike `@every`, the next execution only starts after the
|
|
26
|
+
* previous one finishes — executions never overlap. Starts on `connected`
|
|
27
|
+
* and stops on `disconnected`.
|
|
28
|
+
*
|
|
29
|
+
* @param ms - Retardo entre ejecuciones en milisegundos / Delay between executions in milliseconds
|
|
30
|
+
*/
|
|
31
|
+
) => void;
|
|
17
32
|
/**
|
|
18
33
|
* Pre-chequeo del handler. Los guards se acumulan y se evalúan en orden con AND.
|
|
19
34
|
* Si el método no tiene `@on` explícito, se auto-registra a `message:created`.
|
|
@@ -22,7 +37,21 @@ export declare const on: (event: string) => (_value: unknown, context: ClassMeth
|
|
|
22
37
|
*
|
|
23
38
|
* @param pred - Predicate que recibe los argumentos del evento / Predicate receiving the event arguments
|
|
24
39
|
*/
|
|
25
|
-
export declare const guard: (pred: (...args: unknown[]) => boolean | Promise<boolean>) => (_value: unknown, context: ClassMethodDecoratorContext
|
|
40
|
+
export declare const guard: (pred: (...args: unknown[]) => boolean | Promise<boolean>) => (_value: unknown, context: ClassMethodDecoratorContext
|
|
41
|
+
/**
|
|
42
|
+
* Ejecuta el método con un retardo de `ms` milisegundos entre ejecuciones,
|
|
43
|
+
* usando `setTimeout` recursivo. A diferencia de `@every`, la siguiente
|
|
44
|
+
* ejecución solo empieza cuando la anterior ha terminado — nunca hay
|
|
45
|
+
* ejecuciones en paralelo. Arranca en `connected` y se detiene en
|
|
46
|
+
* `disconnected`.
|
|
47
|
+
* Runs the method with `ms` milliseconds between executions using a recursive
|
|
48
|
+
* `setTimeout`. Unlike `@every`, the next execution only starts after the
|
|
49
|
+
* previous one finishes — executions never overlap. Starts on `connected`
|
|
50
|
+
* and stops on `disconnected`.
|
|
51
|
+
*
|
|
52
|
+
* @param ms - Retardo entre ejecuciones en milisegundos / Delay between executions in milliseconds
|
|
53
|
+
*/
|
|
54
|
+
) => void;
|
|
26
55
|
/**
|
|
27
56
|
* Marca el handler para ejecutarse una sola vez y luego auto-desuscribirse.
|
|
28
57
|
* Con `event` actúa como shortcut de `@on(event) + @once()`.
|
|
@@ -79,7 +108,21 @@ export declare function delay(ms: number): (_value: unknown, context: ClassMetho
|
|
|
79
108
|
* Marks the method as a pairing (PIN/QR) callback. Multiple `@pair` methods run
|
|
80
109
|
* in parallel when baileys delivers the code.
|
|
81
110
|
*/
|
|
82
|
-
export declare const pair: () => (_value: unknown, context: ClassMethodDecoratorContext
|
|
111
|
+
export declare const pair: () => (_value: unknown, context: ClassMethodDecoratorContext
|
|
112
|
+
/**
|
|
113
|
+
* Ejecuta el método con un retardo de `ms` milisegundos entre ejecuciones,
|
|
114
|
+
* usando `setTimeout` recursivo. A diferencia de `@every`, la siguiente
|
|
115
|
+
* ejecución solo empieza cuando la anterior ha terminado — nunca hay
|
|
116
|
+
* ejecuciones en paralelo. Arranca en `connected` y se detiene en
|
|
117
|
+
* `disconnected`.
|
|
118
|
+
* Runs the method with `ms` milliseconds between executions using a recursive
|
|
119
|
+
* `setTimeout`. Unlike `@every`, the next execution only starts after the
|
|
120
|
+
* previous one finishes — executions never overlap. Starts on `connected`
|
|
121
|
+
* and stops on `disconnected`.
|
|
122
|
+
*
|
|
123
|
+
* @param ms - Retardo entre ejecuciones en milisegundos / Delay between executions in milliseconds
|
|
124
|
+
*/
|
|
125
|
+
) => void;
|
|
83
126
|
/**
|
|
84
127
|
* Filtra por autor del mensaje. Acepta JID, LID o teléfono numérico; el string
|
|
85
128
|
* se normaliza con la resolución interna del cliente y cache lazy. Un array produce match OR.
|
|
@@ -129,3 +172,4 @@ export declare function pipe(workflow: string, index: number): (_value: unknown,
|
|
|
129
172
|
* @param pattern - Prefijo textual o RegExp a matchear contra `msg.caption` / Text prefix or RegExp matched against `msg.caption`
|
|
130
173
|
*/
|
|
131
174
|
export declare function command(pattern: string | RegExp): (value: unknown, context: ClassMethodDecoratorContext) => void;
|
|
175
|
+
export {};
|
|
@@ -15,7 +15,7 @@ exports.from = from;
|
|
|
15
15
|
exports.Bot = Bot;
|
|
16
16
|
exports.pipe = pipe;
|
|
17
17
|
exports.command = command;
|
|
18
|
-
const
|
|
18
|
+
const store_1 = require("../../lib/store");
|
|
19
19
|
const decorator_1 = require("./decorator");
|
|
20
20
|
/**
|
|
21
21
|
* Registra el método como listener del evento indicado. Apilable: varios `@on`
|
|
@@ -147,7 +147,7 @@ function from(source) {
|
|
|
147
147
|
if (resolved === null) {
|
|
148
148
|
resolved = new Set();
|
|
149
149
|
for (const raw of list) {
|
|
150
|
-
const r = await (0,
|
|
150
|
+
const r = await (0, store_1.jid_of)(wa.engine, raw);
|
|
151
151
|
if (r) {
|
|
152
152
|
resolved.add(r);
|
|
153
153
|
}
|