@arcaelas/whatsapp 2.2.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +6 -10
- package/build/cjs/index.js +11 -10
- package/build/cjs/index.js.map +1 -1
- 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 +227 -0
- package/build/cjs/lib/chat/index.js +324 -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 +228 -0
- package/build/cjs/lib/message/index.js +678 -0
- package/build/cjs/lib/message/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 +179 -0
- package/build/cjs/lib/whatsapp/index.js +754 -0
- package/build/cjs/lib/whatsapp/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 +6 -10
- package/build/esm/index.js +4 -6
- package/build/esm/index.js.map +1 -1
- 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 +227 -0
- package/build/esm/lib/chat/index.js +319 -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 +228 -0
- package/build/esm/lib/message/index.js +666 -0
- package/build/esm/lib/message/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 +179 -0
- package/build/esm/lib/whatsapp/index.js +714 -0
- package/build/esm/lib/whatsapp/index.js.map +1 -0
- package/package.json +8 -6
- package/build/cjs/Chat.d.ts +0 -317
- package/build/cjs/Chat.js +0 -275
- package/build/cjs/Chat.js.map +0 -1
- package/build/cjs/Contact.d.ts +0 -1163
- package/build/cjs/Contact.js +0 -162
- package/build/cjs/Contact.js.map +0 -1
- package/build/cjs/Message.d.ts +0 -902
- package/build/cjs/Message.js +0 -515
- package/build/cjs/Message.js.map +0 -1
- package/build/cjs/WhatsApp.d.ts +0 -80
- package/build/cjs/WhatsApp.js +0 -412
- package/build/cjs/WhatsApp.js.map +0 -1
- package/build/cjs/store/driver/FileEngine.d.ts +0 -34
- package/build/cjs/store/driver/FileEngine.js +0 -86
- package/build/cjs/store/driver/FileEngine.js.map +0 -1
- package/build/cjs/store/driver/RedisEngine.d.ts +0 -47
- package/build/cjs/store/driver/RedisEngine.js +0 -70
- package/build/cjs/store/driver/RedisEngine.js.map +0 -1
- package/build/cjs/store/engine.d.ts +0 -53
- package/build/cjs/store/engine.js +0 -7
- package/build/cjs/store/engine.js.map +0 -1
- package/build/cjs/store/index.d.ts +0 -8
- package/build/cjs/store/index.js +0 -12
- package/build/cjs/store/index.js.map +0 -1
- package/build/esm/Chat.d.ts +0 -317
- package/build/esm/Chat.js +0 -270
- package/build/esm/Chat.js.map +0 -1
- package/build/esm/Contact.d.ts +0 -1163
- package/build/esm/Contact.js +0 -157
- package/build/esm/Contact.js.map +0 -1
- package/build/esm/Message.d.ts +0 -902
- package/build/esm/Message.js +0 -510
- package/build/esm/Message.js.map +0 -1
- package/build/esm/WhatsApp.d.ts +0 -80
- package/build/esm/WhatsApp.js +0 -372
- package/build/esm/WhatsApp.js.map +0 -1
- package/build/esm/store/driver/FileEngine.d.ts +0 -34
- package/build/esm/store/driver/FileEngine.js +0 -82
- package/build/esm/store/driver/FileEngine.js.map +0 -1
- package/build/esm/store/driver/RedisEngine.d.ts +0 -47
- package/build/esm/store/driver/RedisEngine.js +0 -66
- package/build/esm/store/driver/RedisEngine.js.map +0 -1
- package/build/esm/store/engine.d.ts +0 -53
- package/build/esm/store/engine.js +0 -6
- package/build/esm/store/engine.js.map +0 -1
- package/build/esm/store/index.d.ts +0 -8
- package/build/esm/store/index.js +0 -7
- package/build/esm/store/index.js.map +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file decorators.ts
|
|
3
|
+
* @description Sub-entry `@arcaelas/whatsapp/decorators` — API declarativa basada
|
|
4
|
+
* en decoradores Stage 3 para construir bots sobre el cliente WhatsApp.
|
|
5
|
+
* Sub-entry `@arcaelas/whatsapp/decorators` — Stage 3 decorator-based declarative
|
|
6
|
+
* API to build bots on top of the WhatsApp client.
|
|
7
|
+
*/
|
|
8
|
+
export { WhatsAppBot, Bot, on, guard, command, from, once, connect, disconnect, every, pipe, pair, HANDLERS, decorator, } from './lib/bot';
|
|
9
|
+
export type { HandlerMeta, BotSchema, WorkflowStep } from './lib/bot';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file decorators.ts
|
|
4
|
+
* @description Sub-entry `@arcaelas/whatsapp/decorators` — API declarativa basada
|
|
5
|
+
* en decoradores Stage 3 para construir bots sobre el cliente WhatsApp.
|
|
6
|
+
* Sub-entry `@arcaelas/whatsapp/decorators` — Stage 3 decorator-based declarative
|
|
7
|
+
* API to build bots on top of the WhatsApp client.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.decorator = exports.HANDLERS = exports.pair = exports.pipe = exports.every = exports.disconnect = exports.connect = exports.once = exports.from = exports.command = exports.guard = exports.on = exports.Bot = exports.WhatsAppBot = void 0;
|
|
11
|
+
var bot_1 = require("./lib/bot");
|
|
12
|
+
Object.defineProperty(exports, "WhatsAppBot", { enumerable: true, get: function () { return bot_1.WhatsAppBot; } });
|
|
13
|
+
Object.defineProperty(exports, "Bot", { enumerable: true, get: function () { return bot_1.Bot; } });
|
|
14
|
+
Object.defineProperty(exports, "on", { enumerable: true, get: function () { return bot_1.on; } });
|
|
15
|
+
Object.defineProperty(exports, "guard", { enumerable: true, get: function () { return bot_1.guard; } });
|
|
16
|
+
Object.defineProperty(exports, "command", { enumerable: true, get: function () { return bot_1.command; } });
|
|
17
|
+
Object.defineProperty(exports, "from", { enumerable: true, get: function () { return bot_1.from; } });
|
|
18
|
+
Object.defineProperty(exports, "once", { enumerable: true, get: function () { return bot_1.once; } });
|
|
19
|
+
Object.defineProperty(exports, "connect", { enumerable: true, get: function () { return bot_1.connect; } });
|
|
20
|
+
Object.defineProperty(exports, "disconnect", { enumerable: true, get: function () { return bot_1.disconnect; } });
|
|
21
|
+
Object.defineProperty(exports, "every", { enumerable: true, get: function () { return bot_1.every; } });
|
|
22
|
+
Object.defineProperty(exports, "pipe", { enumerable: true, get: function () { return bot_1.pipe; } });
|
|
23
|
+
Object.defineProperty(exports, "pair", { enumerable: true, get: function () { return bot_1.pair; } });
|
|
24
|
+
Object.defineProperty(exports, "HANDLERS", { enumerable: true, get: function () { return bot_1.HANDLERS; } });
|
|
25
|
+
Object.defineProperty(exports, "decorator", { enumerable: true, get: function () { return bot_1.decorator; } });
|
|
26
|
+
//# sourceMappingURL=decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../src/decorators.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,iCAemB;AAdf,kGAAA,WAAW,OAAA;AACX,0FAAA,GAAG,OAAA;AACH,yFAAA,EAAE,OAAA;AACF,4FAAA,KAAK,OAAA;AACL,8FAAA,OAAO,OAAA;AACP,2FAAA,IAAI,OAAA;AACJ,2FAAA,IAAI,OAAA;AACJ,8FAAA,OAAO,OAAA;AACP,iGAAA,UAAU,OAAA;AACV,4FAAA,KAAK,OAAA;AACL,2FAAA,IAAI,OAAA;AACJ,2FAAA,IAAI,OAAA;AACJ,+FAAA,QAAQ,OAAA;AACR,gGAAA,SAAS,OAAA"}
|
package/build/cjs/index.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file index.ts
|
|
3
|
-
* @description Punto de entrada público de la librería @arcaelas/whatsapp
|
|
3
|
+
* @description Punto de entrada público de la librería @arcaelas/whatsapp.
|
|
4
|
+
* Public entry point of the @arcaelas/whatsapp library.
|
|
4
5
|
*/
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
7
|
-
export
|
|
8
|
-
export type {
|
|
9
|
-
export type { IContactRaw } from './Contact';
|
|
10
|
-
export type { IMessage, IMessageIndex } from './Message';
|
|
11
|
-
export type { IWhatsApp } from './WhatsApp';
|
|
12
|
-
export { FileEngine, RedisEngine } from './store';
|
|
13
|
-
export { WhatsApp } from './WhatsApp';
|
|
6
|
+
export { WhatsApp, default } from './lib/whatsapp';
|
|
7
|
+
export type { IWhatsApp, DisconnectOptions, ReconnectOption } from './lib/whatsapp';
|
|
8
|
+
export { FileSystemEngine, RedisEngine } from './lib/store';
|
|
9
|
+
export type { Engine, RedisClient } from './lib/store';
|
package/build/cjs/index.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* @file index.ts
|
|
4
|
-
* @description Punto de entrada público de la librería @arcaelas/whatsapp
|
|
4
|
+
* @description Punto de entrada público de la librería @arcaelas/whatsapp.
|
|
5
|
+
* Public entry point of the @arcaelas/whatsapp library.
|
|
5
6
|
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
6
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(exports, "
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, "FileEngine", { enumerable: true, get: function () { return store_1.FileEngine; } });
|
|
11
|
+
exports.RedisEngine = exports.FileSystemEngine = exports.default = exports.WhatsApp = void 0;
|
|
12
|
+
var whatsapp_1 = require("./lib/whatsapp");
|
|
13
|
+
Object.defineProperty(exports, "WhatsApp", { enumerable: true, get: function () { return whatsapp_1.WhatsApp; } });
|
|
14
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(whatsapp_1).default; } });
|
|
15
|
+
var store_1 = require("./lib/store");
|
|
16
|
+
Object.defineProperty(exports, "FileSystemEngine", { enumerable: true, get: function () { return store_1.FileSystemEngine; } });
|
|
14
17
|
Object.defineProperty(exports, "RedisEngine", { enumerable: true, get: function () { return store_1.RedisEngine; } });
|
|
15
|
-
var WhatsApp_1 = require("./WhatsApp");
|
|
16
|
-
Object.defineProperty(exports, "WhatsApp", { enumerable: true, get: function () { return WhatsApp_1.WhatsApp; } });
|
|
17
18
|
//# sourceMappingURL=index.js.map
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AAEH,2CAAmD;AAA1C,oGAAA,QAAQ,OAAA;AAAE,oHAAA,OAAO,OAAA;AAG1B,qCAA4D;AAAnD,yGAAA,gBAAgB,OAAA;AAAE,oGAAA,WAAW,OAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file playground/bot/decorator.ts
|
|
3
|
+
* @description Infraestructura base de decoradores Stage 3 sobre WhatsApp.
|
|
4
|
+
* Base infrastructure for Stage 3 decorators over WhatsApp.
|
|
5
|
+
*/
|
|
6
|
+
import WhatsApp, { type IWhatsApp } from '../../lib/whatsapp';
|
|
7
|
+
export declare const HANDLERS: unique symbol;
|
|
8
|
+
export interface HandlerMeta {
|
|
9
|
+
method: string;
|
|
10
|
+
events: string[];
|
|
11
|
+
guards: Array<(...args: unknown[]) => boolean | Promise<boolean>>;
|
|
12
|
+
transforms: Array<(args: unknown[]) => unknown[] | Promise<unknown[]>>;
|
|
13
|
+
once: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface WorkflowStep {
|
|
16
|
+
index: number;
|
|
17
|
+
method: string;
|
|
18
|
+
}
|
|
19
|
+
export interface BotSchema {
|
|
20
|
+
handlers: Record<string, HandlerMeta>;
|
|
21
|
+
workflows: Record<string, WorkflowStep[]>;
|
|
22
|
+
}
|
|
23
|
+
type Metadata = Record<string | symbol, unknown>;
|
|
24
|
+
/**
|
|
25
|
+
* Registra un step dentro de un workflow. Uso interno del decorador `@pipe`.
|
|
26
|
+
* Registers a step inside a workflow. Internal use of the `@pipe` decorator.
|
|
27
|
+
*
|
|
28
|
+
* @param metadata - Metadata del contexto del decorador / Decorator context metadata
|
|
29
|
+
* @param workflow - Nombre del workflow / Workflow name
|
|
30
|
+
* @param step - Step a registrar (índice + nombre del método) / Step to register (index + method name)
|
|
31
|
+
*/
|
|
32
|
+
export declare function register_workflow_step(metadata: Metadata, workflow: string, step: WorkflowStep): void;
|
|
33
|
+
/**
|
|
34
|
+
* Factory para crear decoradores paramétricos Stage 3. El callback muta la metadata
|
|
35
|
+
* del handler mediante la entrada resuelta.
|
|
36
|
+
* Factory to build Stage 3 parametric decorators. The callback mutates the handler
|
|
37
|
+
* metadata via the resolved entry.
|
|
38
|
+
*
|
|
39
|
+
* @param callback - Mutador de la entrada del handler / Handler entry mutator
|
|
40
|
+
* @returns Decorador paramétrico listo para aplicarse a un método / Parametric decorator ready to be applied to a method
|
|
41
|
+
*/
|
|
42
|
+
export declare function decorator<P extends unknown[]>(callback: (metadata: Metadata, handler: HandlerMeta, params: P) => void): (...params: P) => (_value: unknown, context: ClassMethodDecoratorContext) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Clase base opcional para bots declarativos. El consumer extiende `WhatsAppBot`
|
|
45
|
+
* (o usa `@WhatsApp` como class decorator), declara métodos decorados y al
|
|
46
|
+
* `connect()` los listeners se cablean automáticamente contra el event emitter real.
|
|
47
|
+
* Optional base class for declarative bots. The consumer extends `WhatsAppBot`
|
|
48
|
+
* (or uses `@WhatsApp` as a class decorator), declares decorated methods and at
|
|
49
|
+
* `connect()` listeners get wired against the real event emitter automatically.
|
|
50
|
+
*/
|
|
51
|
+
export declare class WhatsAppBot extends WhatsApp {
|
|
52
|
+
constructor(options: IWhatsApp);
|
|
53
|
+
/**
|
|
54
|
+
* Inicia la conexión cableando previamente los handlers decorados. Los métodos
|
|
55
|
+
* `@pair` se invocan en paralelo con el `callback` opcional.
|
|
56
|
+
* Starts the connection wiring decorated handlers beforehand. `@pair` methods
|
|
57
|
+
* run in parallel alongside the optional `callback`.
|
|
58
|
+
*
|
|
59
|
+
* @param callback - Callback tradicional del PIN/QR (opcional si hay `@pair`) / Traditional PIN/QR callback (optional when `@pair` exists)
|
|
60
|
+
*/
|
|
61
|
+
connect(callback?: (auth: string | Buffer) => void | Promise<void>): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Recolecta los métodos marcados con `@pair` ligados a `this`.
|
|
64
|
+
* Collects methods marked with `@pair` bound to `this`.
|
|
65
|
+
*
|
|
66
|
+
* @returns Lista de funciones ligadas listas para invocar con el code / List of bound functions ready to invoke with the code
|
|
67
|
+
*/
|
|
68
|
+
private _collect_pair_methods;
|
|
69
|
+
/**
|
|
70
|
+
* Cablea los handlers decorados contra el event emitter: registra listeners
|
|
71
|
+
* (`@on`/`@once`), timers (`@every`) y workflows (`@pipe`).
|
|
72
|
+
* Wires decorated handlers against the event emitter: registers listeners
|
|
73
|
+
* (`@on`/`@once`), timers (`@every`) and workflows (`@pipe`).
|
|
74
|
+
*/
|
|
75
|
+
private _wire_handlers;
|
|
76
|
+
}
|
|
77
|
+
export default WhatsAppBot;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file playground/bot/decorator.ts
|
|
4
|
+
* @description Infraestructura base de decoradores Stage 3 sobre WhatsApp.
|
|
5
|
+
* Base infrastructure for Stage 3 decorators over WhatsApp.
|
|
6
|
+
*/
|
|
7
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
8
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
9
|
+
};
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.WhatsAppBot = exports.HANDLERS = void 0;
|
|
12
|
+
exports.register_workflow_step = register_workflow_step;
|
|
13
|
+
exports.decorator = decorator;
|
|
14
|
+
const whatsapp_1 = __importDefault(require("../../lib/whatsapp"));
|
|
15
|
+
Symbol.metadata ??= Symbol.for('Symbol.metadata');
|
|
16
|
+
exports.HANDLERS = Symbol('wa:handlers');
|
|
17
|
+
/**
|
|
18
|
+
* Recupera o inicializa el schema del bot y la entrada del método indicado.
|
|
19
|
+
* Retrieves or initializes the bot schema and the entry for the given method.
|
|
20
|
+
*
|
|
21
|
+
* @param metadata - Objeto metadata del contexto del decorador / Decorator context metadata object
|
|
22
|
+
* @param method_name - Nombre del método / Method name
|
|
23
|
+
* @returns Tupla `[schema, handler_meta]` para el método / Tuple `[schema, handler_meta]` for the method
|
|
24
|
+
*/
|
|
25
|
+
function resolve(metadata, method_name) {
|
|
26
|
+
let schema = metadata[exports.HANDLERS];
|
|
27
|
+
if (!schema) {
|
|
28
|
+
schema = { handlers: {}, workflows: {} };
|
|
29
|
+
metadata[exports.HANDLERS] = schema;
|
|
30
|
+
}
|
|
31
|
+
if (!schema.workflows) {
|
|
32
|
+
schema.workflows = {};
|
|
33
|
+
}
|
|
34
|
+
schema.handlers[method_name] ||= {
|
|
35
|
+
method: method_name,
|
|
36
|
+
events: [],
|
|
37
|
+
guards: [],
|
|
38
|
+
transforms: [],
|
|
39
|
+
once: false,
|
|
40
|
+
};
|
|
41
|
+
return [schema, schema.handlers[method_name]];
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Registra un step dentro de un workflow. Uso interno del decorador `@pipe`.
|
|
45
|
+
* Registers a step inside a workflow. Internal use of the `@pipe` decorator.
|
|
46
|
+
*
|
|
47
|
+
* @param metadata - Metadata del contexto del decorador / Decorator context metadata
|
|
48
|
+
* @param workflow - Nombre del workflow / Workflow name
|
|
49
|
+
* @param step - Step a registrar (índice + nombre del método) / Step to register (index + method name)
|
|
50
|
+
*/
|
|
51
|
+
function register_workflow_step(metadata, workflow, step) {
|
|
52
|
+
let schema = metadata[exports.HANDLERS];
|
|
53
|
+
if (!schema) {
|
|
54
|
+
schema = { handlers: {}, workflows: {} };
|
|
55
|
+
metadata[exports.HANDLERS] = schema;
|
|
56
|
+
}
|
|
57
|
+
if (!schema.workflows) {
|
|
58
|
+
schema.workflows = {};
|
|
59
|
+
}
|
|
60
|
+
schema.workflows[workflow] ||= [];
|
|
61
|
+
schema.workflows[workflow].push(step);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Factory para crear decoradores paramétricos Stage 3. El callback muta la metadata
|
|
65
|
+
* del handler mediante la entrada resuelta.
|
|
66
|
+
* Factory to build Stage 3 parametric decorators. The callback mutates the handler
|
|
67
|
+
* metadata via the resolved entry.
|
|
68
|
+
*
|
|
69
|
+
* @param callback - Mutador de la entrada del handler / Handler entry mutator
|
|
70
|
+
* @returns Decorador paramétrico listo para aplicarse a un método / Parametric decorator ready to be applied to a method
|
|
71
|
+
*/
|
|
72
|
+
function decorator(callback) {
|
|
73
|
+
return (...params) => (_value, context) => {
|
|
74
|
+
if (context.kind !== 'method') {
|
|
75
|
+
throw new Error(`Decorator only applicable to methods; got ${context.kind}`);
|
|
76
|
+
}
|
|
77
|
+
const metadata = context.metadata;
|
|
78
|
+
const method_name = String(context.name);
|
|
79
|
+
const [, handler] = resolve(metadata, method_name);
|
|
80
|
+
callback(metadata, handler, params);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Clase base opcional para bots declarativos. El consumer extiende `WhatsAppBot`
|
|
85
|
+
* (o usa `@WhatsApp` como class decorator), declara métodos decorados y al
|
|
86
|
+
* `connect()` los listeners se cablean automáticamente contra el event emitter real.
|
|
87
|
+
* Optional base class for declarative bots. The consumer extends `WhatsAppBot`
|
|
88
|
+
* (or uses `@WhatsApp` as a class decorator), declares decorated methods and at
|
|
89
|
+
* `connect()` listeners get wired against the real event emitter automatically.
|
|
90
|
+
*/
|
|
91
|
+
class WhatsAppBot extends whatsapp_1.default {
|
|
92
|
+
constructor(options) {
|
|
93
|
+
super(options);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Inicia la conexión cableando previamente los handlers decorados. Los métodos
|
|
97
|
+
* `@pair` se invocan en paralelo con el `callback` opcional.
|
|
98
|
+
* Starts the connection wiring decorated handlers beforehand. `@pair` methods
|
|
99
|
+
* run in parallel alongside the optional `callback`.
|
|
100
|
+
*
|
|
101
|
+
* @param callback - Callback tradicional del PIN/QR (opcional si hay `@pair`) / Traditional PIN/QR callback (optional when `@pair` exists)
|
|
102
|
+
*/
|
|
103
|
+
async connect(callback) {
|
|
104
|
+
this._wire_handlers();
|
|
105
|
+
const pair_methods = this._collect_pair_methods();
|
|
106
|
+
const final_callback = async (code) => {
|
|
107
|
+
await Promise.all(pair_methods.map((fn) => fn(code)));
|
|
108
|
+
if (callback) {
|
|
109
|
+
await callback(code);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return super.connect(final_callback);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Recolecta los métodos marcados con `@pair` ligados a `this`.
|
|
116
|
+
* Collects methods marked with `@pair` bound to `this`.
|
|
117
|
+
*
|
|
118
|
+
* @returns Lista de funciones ligadas listas para invocar con el code / List of bound functions ready to invoke with the code
|
|
119
|
+
*/
|
|
120
|
+
_collect_pair_methods() {
|
|
121
|
+
const out = [];
|
|
122
|
+
const metadata = this.constructor[Symbol.metadata];
|
|
123
|
+
if (metadata) {
|
|
124
|
+
const schema = metadata[exports.HANDLERS];
|
|
125
|
+
if (schema) {
|
|
126
|
+
for (const meta of Object.values(schema.handlers)) {
|
|
127
|
+
if (meta.events.includes('__pair')) {
|
|
128
|
+
const fn = this[meta.method];
|
|
129
|
+
if (typeof fn === 'function') {
|
|
130
|
+
out.push(fn.bind(this));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Cablea los handlers decorados contra el event emitter: registra listeners
|
|
140
|
+
* (`@on`/`@once`), timers (`@every`) y workflows (`@pipe`).
|
|
141
|
+
* Wires decorated handlers against the event emitter: registers listeners
|
|
142
|
+
* (`@on`/`@once`), timers (`@every`) and workflows (`@pipe`).
|
|
143
|
+
*/
|
|
144
|
+
_wire_handlers() {
|
|
145
|
+
const metadata = this.constructor[Symbol.metadata];
|
|
146
|
+
if (metadata) {
|
|
147
|
+
const schema = metadata[exports.HANDLERS];
|
|
148
|
+
if (schema) {
|
|
149
|
+
const intervals = [];
|
|
150
|
+
for (const meta of Object.values(schema.handlers)) {
|
|
151
|
+
const method = this[meta.method];
|
|
152
|
+
if (typeof method === 'function') {
|
|
153
|
+
const bound = method.bind(this);
|
|
154
|
+
const invoke = async (...args) => {
|
|
155
|
+
for (const g of meta.guards) {
|
|
156
|
+
if (!(await g(...args))) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
let current = args;
|
|
161
|
+
for (const t of meta.transforms) {
|
|
162
|
+
current = await t(current);
|
|
163
|
+
}
|
|
164
|
+
await bound(...current);
|
|
165
|
+
};
|
|
166
|
+
if (meta.events.length === 0 && (meta.guards.length > 0 || meta.transforms.length > 0)) {
|
|
167
|
+
meta.events.push('message:created');
|
|
168
|
+
}
|
|
169
|
+
for (const event of meta.events) {
|
|
170
|
+
if (event.startsWith('__every:')) {
|
|
171
|
+
const ms = parseInt(event.slice('__every:'.length), 10);
|
|
172
|
+
if (Number.isFinite(ms) && ms > 0) {
|
|
173
|
+
intervals.push({ ms, run: () => invoke() });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else if (event !== '__pair') {
|
|
177
|
+
const register = meta.once ? this.once.bind(this) : this.on.bind(this);
|
|
178
|
+
register(event, invoke);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (intervals.length > 0) {
|
|
184
|
+
let timer_ids = [];
|
|
185
|
+
this.on('connected', () => {
|
|
186
|
+
for (const { ms, run } of intervals) {
|
|
187
|
+
timer_ids.push(setInterval(() => void run(), ms));
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
this.on('disconnected', () => {
|
|
191
|
+
for (const id of timer_ids) {
|
|
192
|
+
clearInterval(id);
|
|
193
|
+
}
|
|
194
|
+
timer_ids = [];
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
for (const steps of Object.values(schema.workflows ?? {})) {
|
|
198
|
+
const sorted = [...steps].sort((a, b) => a.index - b.index);
|
|
199
|
+
const funcs = sorted
|
|
200
|
+
.map(({ method }) => {
|
|
201
|
+
const fn = this[method];
|
|
202
|
+
return typeof fn === 'function' ? fn.bind(this) : null;
|
|
203
|
+
})
|
|
204
|
+
.filter((f) => f !== null);
|
|
205
|
+
if (funcs.length > 0) {
|
|
206
|
+
this.on('message:created', (async (...args) => {
|
|
207
|
+
for (const fn of funcs) {
|
|
208
|
+
await fn(...args);
|
|
209
|
+
}
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.WhatsAppBot = WhatsAppBot;
|
|
218
|
+
exports.default = WhatsAppBot;
|
|
219
|
+
//# sourceMappingURL=decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../../../src/lib/bot/decorator.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;AA+DH,wDAeC;AAWD,8BAaC;AApGD,8DAA0D;AAEzD,MAAgC,CAAC,QAAQ,KAAK,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAEhE,QAAA,QAAQ,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAsB9C;;;;;;;GAOG;AACH,SAAS,OAAO,CAAC,QAAkB,EAAE,WAAmB;IACpD,IAAI,MAAM,GAAG,QAAQ,CAAC,gBAAQ,CAA0B,CAAC;IACzD,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,MAAM,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;QACzC,QAAQ,CAAC,gBAAQ,CAAC,GAAG,MAAM,CAAC;IAChC,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QACpB,MAAM,CAAC,SAAS,GAAG,EAAE,CAAC;IAC1B,CAAC;IACD,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK;QAC7B,MAAM,EAAE,WAAW;QACnB,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,EAAE;QACV,UAAU,EAAE,EAAE;QACd,IAAI,EAAE,KAAK;KACd,CAAC;IACF,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;AAClD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,sBAAsB,CAClC,QAAkB,EAClB,QAAgB,EAChB,IAAkB;IAElB,IAAI,MAAM,GAAG,QAAQ,CAAC,gBAAQ,CAA0B,CAAC;IACzD,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,MAAM,GAAG,EAAE,QAAQ,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CAAC,CAAC;gBACP,CAAC;gBAED,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,CAAC;oBACxD,MAAM,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;oBAC5D,MAAM,KAAK,GAAG,MAAM;yBACf,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;wBAChB,MAAM,EAAE,GAAI,IAA2C,CAAC,MAAM,CAAC,CAAC;wBAChE,OAAO,OAAO,EAAE,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;oBAC3D,CAAC,CAAC;yBACD,MAAM,CAAC,CAAC,CAAC,EAAwC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC;oBACrE,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBACnB,IAAI,CAAC,EAAE,CAAC,iBAAiB,EAAE,CAAC,KAAK,EAAE,GAAG,IAAe,EAAE,EAAE;4BACrD,KAAK,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC;gCACrB,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;4BACtB,CAAC;wBACL,CAAC,CAAU,CAAC,CAAC;oBACjB,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AArID,kCAqIC;AAED,kBAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file playground/bot/decorators.ts
|
|
3
|
+
* @description Decoradores públicos del bot.
|
|
4
|
+
* Public bot decorators.
|
|
5
|
+
*/
|
|
6
|
+
import type { IWhatsApp } from '../../lib/whatsapp';
|
|
7
|
+
import { WhatsAppBot } from './decorator';
|
|
8
|
+
/**
|
|
9
|
+
* Registra el método como listener del evento indicado. Apilable: varios `@on`
|
|
10
|
+
* sobre el mismo método crean múltiples suscripciones.
|
|
11
|
+
* Registers the method as a listener of the given event. Stackable: several
|
|
12
|
+
* `@on` on the same method produce multiple subscriptions.
|
|
13
|
+
*
|
|
14
|
+
* @param event - Nombre del evento del cliente / Client event name
|
|
15
|
+
*/
|
|
16
|
+
export declare const on: (event: string) => (_value: unknown, context: ClassMethodDecoratorContext) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Pre-chequeo del handler. Los guards se acumulan y se evalúan en orden con AND.
|
|
19
|
+
* Si el método no tiene `@on` explícito, se auto-registra a `message:created`.
|
|
20
|
+
* Handler pre-check. Guards accumulate and run in order with AND semantics.
|
|
21
|
+
* If the method has no explicit `@on`, it auto-registers to `message:created`.
|
|
22
|
+
*
|
|
23
|
+
* @param pred - Predicate que recibe los argumentos del evento / Predicate receiving the event arguments
|
|
24
|
+
*/
|
|
25
|
+
export declare const guard: (pred: (...args: unknown[]) => boolean | Promise<boolean>) => (_value: unknown, context: ClassMethodDecoratorContext) => void;
|
|
26
|
+
/**
|
|
27
|
+
* Marca el handler para ejecutarse una sola vez y luego auto-desuscribirse.
|
|
28
|
+
* Con `event` actúa como shortcut de `@on(event) + @once()`.
|
|
29
|
+
* Marks the handler to run once and then auto-unsubscribe. With `event` it acts
|
|
30
|
+
* as a shortcut of `@on(event) + @once()`.
|
|
31
|
+
*
|
|
32
|
+
* @param event - Evento opcional para combinar `@on + @once` en un solo decorador / Optional event to combine `@on + @once` in a single decorator
|
|
33
|
+
*/
|
|
34
|
+
export declare function once(event?: string): (_value: unknown, context: ClassMethodDecoratorContext) => void;
|
|
35
|
+
/**
|
|
36
|
+
* Alias semántico de `@on('connected')`. El método se invoca al establecerse
|
|
37
|
+
* la conexión con WhatsApp.
|
|
38
|
+
* Semantic alias of `@on('connected')`. The method runs when the WhatsApp
|
|
39
|
+
* connection opens.
|
|
40
|
+
*/
|
|
41
|
+
export declare function connect(): (_value: unknown, context: ClassMethodDecoratorContext) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Alias semántico de `@on('disconnected')`. El método se invoca al cerrarse
|
|
44
|
+
* la conexión con WhatsApp.
|
|
45
|
+
* Semantic alias of `@on('disconnected')`. The method runs when the WhatsApp
|
|
46
|
+
* connection closes.
|
|
47
|
+
*/
|
|
48
|
+
export declare function disconnect(): (_value: unknown, context: ClassMethodDecoratorContext) => void;
|
|
49
|
+
/**
|
|
50
|
+
* Ejecuta el método cada `ms` milisegundos mientras el bot esté conectado.
|
|
51
|
+
* Los timers arrancan en `connected` y se cancelan en `disconnected`.
|
|
52
|
+
* Runs the method every `ms` milliseconds while the bot is connected. Timers
|
|
53
|
+
* start on `connected` and are cancelled on `disconnected`.
|
|
54
|
+
*
|
|
55
|
+
* @param ms - Intervalo en milisegundos / Interval in milliseconds
|
|
56
|
+
*/
|
|
57
|
+
export declare function every(ms: number): (_value: unknown, context: ClassMethodDecoratorContext) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Marca el método como callback de pairing (PIN/QR). Múltiples métodos `@pair`
|
|
60
|
+
* se invocan en paralelo cuando baileys entrega el código.
|
|
61
|
+
* Marks the method as a pairing (PIN/QR) callback. Multiple `@pair` methods run
|
|
62
|
+
* in parallel when baileys delivers the code.
|
|
63
|
+
*/
|
|
64
|
+
export declare const pair: () => (_value: unknown, context: ClassMethodDecoratorContext) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Filtra por autor del mensaje. Acepta JID, LID o teléfono numérico; el string
|
|
67
|
+
* se normaliza vía `wa._resolve_jid` con cache lazy. Un array produce match OR.
|
|
68
|
+
* Filters by message author. Accepts JID, LID or numeric phone; the string is
|
|
69
|
+
* normalized via `wa._resolve_jid` with lazy cache. An array yields OR matching.
|
|
70
|
+
*
|
|
71
|
+
* @param source - Identificador(es) permitidos o predicate sobre `msg.from` / Allowed identifier(s) or predicate on `msg.from`
|
|
72
|
+
*/
|
|
73
|
+
export declare function from(source: string | string[] | ((jid: string) => boolean)): (_value: unknown, context: ClassMethodDecoratorContext) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Class decorator que convierte la clase en un bot WhatsApp con opciones default.
|
|
76
|
+
* La clase no necesita extender `WhatsAppBot` manualmente; el decorador produce
|
|
77
|
+
* una subclase que hereda de `WhatsAppBot` y copia los métodos + metadata del
|
|
78
|
+
* target. El constructor acepta un override parcial que se fusiona con las opts
|
|
79
|
+
* por default.
|
|
80
|
+
* Class decorator that turns the class into a WhatsApp bot with default options.
|
|
81
|
+
* The class does not need to extend `WhatsAppBot` manually; the decorator
|
|
82
|
+
* produces a subclass that inherits from `WhatsAppBot` and copies the target's
|
|
83
|
+
* methods and metadata. The constructor accepts a partial override that is
|
|
84
|
+
* merged with the default options.
|
|
85
|
+
*
|
|
86
|
+
* @param default_options - Opciones base para la instancia / Default options for the instance
|
|
87
|
+
*/
|
|
88
|
+
export declare function Bot(default_options: IWhatsApp): <T extends abstract new (...args: never[]) => object>(target: T, _context: ClassDecoratorContext) => new (override?: Partial<IWhatsApp>) => InstanceType<T> & WhatsAppBot;
|
|
89
|
+
/**
|
|
90
|
+
* Registra el método como paso de un workflow. Todos los steps del mismo
|
|
91
|
+
* `workflow` se ejecutan secuencialmente al recibir `message:created`, ordenados
|
|
92
|
+
* por `index`. Comparten los mismos argumentos (msg, chat, wa), por lo que las
|
|
93
|
+
* mutaciones sobre esos objetos son visibles en los steps posteriores.
|
|
94
|
+
* Registers the method as a step of a workflow. All steps of the same
|
|
95
|
+
* `workflow` run sequentially on `message:created`, ordered by `index`. They
|
|
96
|
+
* share the same arguments (msg, chat, wa), so mutations on those objects are
|
|
97
|
+
* visible to later steps.
|
|
98
|
+
*
|
|
99
|
+
* @param workflow - Nombre del workflow / Workflow name
|
|
100
|
+
* @param index - Posición dentro del workflow (ASC) / Position within the workflow (ASC)
|
|
101
|
+
*/
|
|
102
|
+
export declare function pipe(workflow: string, index: number): (_value: unknown, context: ClassMethodDecoratorContext) => void;
|
|
103
|
+
/**
|
|
104
|
+
* Registra el método como comando textual. Internamente aplica
|
|
105
|
+
* `@on('message:created')`, un guard que matchea el `pattern` y un transform
|
|
106
|
+
* que pasa `(msg, chat, args)` al método.
|
|
107
|
+
* Registers the method as a textual command. Internally applies
|
|
108
|
+
* `@on('message:created')`, a guard matching the `pattern` and a transform that
|
|
109
|
+
* passes `(msg, chat, args)` to the method.
|
|
110
|
+
*
|
|
111
|
+
* @param pattern - Prefijo textual o RegExp a matchear contra `msg.caption` / Text prefix or RegExp matched against `msg.caption`
|
|
112
|
+
*/
|
|
113
|
+
export declare function command(pattern: string | RegExp): (value: unknown, context: ClassMethodDecoratorContext) => void;
|