@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.
Files changed (93) hide show
  1. package/build/cjs/_index.d.ts +14 -0
  2. package/build/cjs/_index.js +366 -0
  3. package/build/cjs/_index.js.map +1 -0
  4. package/build/cjs/decorators.d.ts +9 -0
  5. package/build/cjs/decorators.js +26 -0
  6. package/build/cjs/decorators.js.map +1 -0
  7. package/build/cjs/index.d.ts +11 -0
  8. package/build/cjs/index.js +21 -0
  9. package/build/cjs/index.js.map +1 -0
  10. package/build/cjs/lib/bot/decorator.d.ts +77 -0
  11. package/build/cjs/lib/bot/decorator.js +219 -0
  12. package/build/cjs/lib/bot/decorator.js.map +1 -0
  13. package/build/cjs/lib/bot/decorators.d.ts +113 -0
  14. package/build/cjs/lib/bot/decorators.js +253 -0
  15. package/build/cjs/lib/bot/decorators.js.map +1 -0
  16. package/build/cjs/lib/bot/index.d.ts +3 -0
  17. package/build/cjs/lib/bot/index.js +20 -0
  18. package/build/cjs/lib/bot/index.js.map +1 -0
  19. package/build/cjs/lib/chat/index.d.ts +252 -0
  20. package/build/cjs/lib/chat/index.js +314 -0
  21. package/build/cjs/lib/chat/index.js.map +1 -0
  22. package/build/cjs/lib/contact/index.d.ts +203 -0
  23. package/build/cjs/lib/contact/index.js +226 -0
  24. package/build/cjs/lib/contact/index.js.map +1 -0
  25. package/build/cjs/lib/message/index.d.ts +277 -0
  26. package/build/cjs/lib/message/index.js +773 -0
  27. package/build/cjs/lib/message/index.js.map +1 -0
  28. package/build/cjs/lib/status/index.d.ts +85 -0
  29. package/build/cjs/lib/status/index.js +137 -0
  30. package/build/cjs/lib/status/index.js.map +1 -0
  31. package/build/cjs/lib/store/engine/index.d.ts +34 -0
  32. package/build/cjs/lib/store/engine/index.js +13 -0
  33. package/build/cjs/lib/store/engine/index.js.map +1 -0
  34. package/build/cjs/lib/store/engine/lib/file_system/index.d.ts +56 -0
  35. package/build/cjs/lib/store/engine/lib/file_system/index.js +160 -0
  36. package/build/cjs/lib/store/engine/lib/file_system/index.js.map +1 -0
  37. package/build/cjs/lib/store/engine/lib/redis/index.d.ts +82 -0
  38. package/build/cjs/lib/store/engine/lib/redis/index.js +132 -0
  39. package/build/cjs/lib/store/engine/lib/redis/index.js.map +1 -0
  40. package/build/cjs/lib/store/index.d.ts +22 -0
  41. package/build/cjs/lib/store/index.js +38 -0
  42. package/build/cjs/lib/store/index.js.map +1 -0
  43. package/build/cjs/lib/whatsapp/index.d.ts +185 -0
  44. package/build/cjs/lib/whatsapp/index.js +882 -0
  45. package/build/cjs/lib/whatsapp/index.js.map +1 -0
  46. package/build/cjs/package.json +1 -0
  47. package/build/esm/_index.d.ts +14 -0
  48. package/build/esm/_index.js +364 -0
  49. package/build/esm/_index.js.map +1 -0
  50. package/build/esm/decorators.d.ts +9 -0
  51. package/build/esm/decorators.js +9 -0
  52. package/build/esm/decorators.js.map +1 -0
  53. package/build/esm/index.d.ts +11 -0
  54. package/build/esm/index.js +9 -0
  55. package/build/esm/index.js.map +1 -0
  56. package/build/esm/lib/bot/decorator.d.ts +77 -0
  57. package/build/esm/lib/bot/decorator.js +210 -0
  58. package/build/esm/lib/bot/decorator.js.map +1 -0
  59. package/build/esm/lib/bot/decorators.d.ts +113 -0
  60. package/build/esm/lib/bot/decorators.js +242 -0
  61. package/build/esm/lib/bot/decorators.js.map +1 -0
  62. package/build/esm/lib/bot/index.d.ts +3 -0
  63. package/build/esm/lib/bot/index.js +3 -0
  64. package/build/esm/lib/bot/index.js.map +1 -0
  65. package/build/esm/lib/chat/index.d.ts +252 -0
  66. package/build/esm/lib/chat/index.js +309 -0
  67. package/build/esm/lib/chat/index.js.map +1 -0
  68. package/build/esm/lib/contact/index.d.ts +203 -0
  69. package/build/esm/lib/contact/index.js +221 -0
  70. package/build/esm/lib/contact/index.js.map +1 -0
  71. package/build/esm/lib/message/index.d.ts +277 -0
  72. package/build/esm/lib/message/index.js +761 -0
  73. package/build/esm/lib/message/index.js.map +1 -0
  74. package/build/esm/lib/status/index.d.ts +85 -0
  75. package/build/esm/lib/status/index.js +133 -0
  76. package/build/esm/lib/status/index.js.map +1 -0
  77. package/build/esm/lib/store/engine/index.d.ts +34 -0
  78. package/build/esm/lib/store/engine/index.js +8 -0
  79. package/build/esm/lib/store/engine/index.js.map +1 -0
  80. package/build/esm/lib/store/engine/lib/file_system/index.d.ts +56 -0
  81. package/build/esm/lib/store/engine/lib/file_system/index.js +156 -0
  82. package/build/esm/lib/store/engine/lib/file_system/index.js.map +1 -0
  83. package/build/esm/lib/store/engine/lib/redis/index.d.ts +82 -0
  84. package/build/esm/lib/store/engine/lib/redis/index.js +128 -0
  85. package/build/esm/lib/store/engine/lib/redis/index.js.map +1 -0
  86. package/build/esm/lib/store/index.d.ts +22 -0
  87. package/build/esm/lib/store/index.js +31 -0
  88. package/build/esm/lib/store/index.js.map +1 -0
  89. package/build/esm/lib/whatsapp/index.d.ts +185 -0
  90. package/build/esm/lib/whatsapp/index.js +842 -0
  91. package/build/esm/lib/whatsapp/index.js.map +1 -0
  92. package/build/esm/package.json +1 -0
  93. package/package.json +1 -1
@@ -0,0 +1,210 @@
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 from '../../lib/whatsapp/index.js';
7
+ Symbol.metadata ??= Symbol.for('Symbol.metadata');
8
+ export const HANDLERS = Symbol('wa:handlers');
9
+ /**
10
+ * Recupera o inicializa el schema del bot y la entrada del método indicado.
11
+ * Retrieves or initializes the bot schema and the entry for the given method.
12
+ *
13
+ * @param metadata - Objeto metadata del contexto del decorador / Decorator context metadata object
14
+ * @param method_name - Nombre del método / Method name
15
+ * @returns Tupla `[schema, handler_meta]` para el método / Tuple `[schema, handler_meta]` for the method
16
+ */
17
+ function resolve(metadata, method_name) {
18
+ let schema = metadata[HANDLERS];
19
+ if (!schema) {
20
+ schema = { handlers: {}, workflows: {} };
21
+ metadata[HANDLERS] = schema;
22
+ }
23
+ if (!schema.workflows) {
24
+ schema.workflows = {};
25
+ }
26
+ schema.handlers[method_name] ||= {
27
+ method: method_name,
28
+ events: [],
29
+ guards: [],
30
+ transforms: [],
31
+ once: false,
32
+ };
33
+ return [schema, schema.handlers[method_name]];
34
+ }
35
+ /**
36
+ * Registra un step dentro de un workflow. Uso interno del decorador `@pipe`.
37
+ * Registers a step inside a workflow. Internal use of the `@pipe` decorator.
38
+ *
39
+ * @param metadata - Metadata del contexto del decorador / Decorator context metadata
40
+ * @param workflow - Nombre del workflow / Workflow name
41
+ * @param step - Step a registrar (índice + nombre del método) / Step to register (index + method name)
42
+ */
43
+ export function register_workflow_step(metadata, workflow, step) {
44
+ let schema = metadata[HANDLERS];
45
+ if (!schema) {
46
+ schema = { handlers: {}, workflows: {} };
47
+ metadata[HANDLERS] = schema;
48
+ }
49
+ if (!schema.workflows) {
50
+ schema.workflows = {};
51
+ }
52
+ schema.workflows[workflow] ||= [];
53
+ schema.workflows[workflow].push(step);
54
+ }
55
+ /**
56
+ * Factory para crear decoradores paramétricos Stage 3. El callback muta la metadata
57
+ * del handler mediante la entrada resuelta.
58
+ * Factory to build Stage 3 parametric decorators. The callback mutates the handler
59
+ * metadata via the resolved entry.
60
+ *
61
+ * @param callback - Mutador de la entrada del handler / Handler entry mutator
62
+ * @returns Decorador paramétrico listo para aplicarse a un método / Parametric decorator ready to be applied to a method
63
+ */
64
+ export function decorator(callback) {
65
+ return (...params) => (_value, context) => {
66
+ if (context.kind !== 'method') {
67
+ throw new Error(`Decorator only applicable to methods; got ${context.kind}`);
68
+ }
69
+ const metadata = context.metadata;
70
+ const method_name = String(context.name);
71
+ const [, handler] = resolve(metadata, method_name);
72
+ callback(metadata, handler, params);
73
+ };
74
+ }
75
+ /**
76
+ * Clase base opcional para bots declarativos. El consumer extiende `WhatsAppBot`
77
+ * (o usa `@WhatsApp` como class decorator), declara métodos decorados y al
78
+ * `connect()` los listeners se cablean automáticamente contra el event emitter real.
79
+ * Optional base class for declarative bots. The consumer extends `WhatsAppBot`
80
+ * (or uses `@WhatsApp` as a class decorator), declares decorated methods and at
81
+ * `connect()` listeners get wired against the real event emitter automatically.
82
+ */
83
+ export class WhatsAppBot extends WhatsApp {
84
+ constructor(options) {
85
+ super(options);
86
+ }
87
+ /**
88
+ * Inicia la conexión cableando previamente los handlers decorados. Los métodos
89
+ * `@pair` se invocan en paralelo con el `callback` opcional.
90
+ * Starts the connection wiring decorated handlers beforehand. `@pair` methods
91
+ * run in parallel alongside the optional `callback`.
92
+ *
93
+ * @param callback - Callback tradicional del PIN/QR (opcional si hay `@pair`) / Traditional PIN/QR callback (optional when `@pair` exists)
94
+ */
95
+ async connect(callback) {
96
+ this._wire_handlers();
97
+ const pair_methods = this._collect_pair_methods();
98
+ const final_callback = async (code) => {
99
+ await Promise.all(pair_methods.map((fn) => fn(code)));
100
+ if (callback) {
101
+ await callback(code);
102
+ }
103
+ };
104
+ return super.connect(final_callback);
105
+ }
106
+ /**
107
+ * Recolecta los métodos marcados con `@pair` ligados a `this`.
108
+ * Collects methods marked with `@pair` bound to `this`.
109
+ *
110
+ * @returns Lista de funciones ligadas listas para invocar con el code / List of bound functions ready to invoke with the code
111
+ */
112
+ _collect_pair_methods() {
113
+ const out = [];
114
+ const metadata = this.constructor[Symbol.metadata];
115
+ if (metadata) {
116
+ const schema = metadata[HANDLERS];
117
+ if (schema) {
118
+ for (const meta of Object.values(schema.handlers)) {
119
+ if (meta.events.includes('__pair')) {
120
+ const fn = this[meta.method];
121
+ if (typeof fn === 'function') {
122
+ out.push(fn.bind(this));
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }
128
+ return out;
129
+ }
130
+ /**
131
+ * Cablea los handlers decorados contra el event emitter: registra listeners
132
+ * (`@on`/`@once`), timers (`@every`) y workflows (`@pipe`).
133
+ * Wires decorated handlers against the event emitter: registers listeners
134
+ * (`@on`/`@once`), timers (`@every`) and workflows (`@pipe`).
135
+ */
136
+ _wire_handlers() {
137
+ const metadata = this.constructor[Symbol.metadata];
138
+ if (metadata) {
139
+ const schema = metadata[HANDLERS];
140
+ if (schema) {
141
+ const intervals = [];
142
+ for (const meta of Object.values(schema.handlers)) {
143
+ const method = this[meta.method];
144
+ if (typeof method === 'function') {
145
+ const bound = method.bind(this);
146
+ const invoke = async (...args) => {
147
+ for (const g of meta.guards) {
148
+ if (!(await g(...args))) {
149
+ return;
150
+ }
151
+ }
152
+ let current = args;
153
+ for (const t of meta.transforms) {
154
+ current = await t(current);
155
+ }
156
+ await bound(...current);
157
+ };
158
+ if (meta.events.length === 0 && (meta.guards.length > 0 || meta.transforms.length > 0)) {
159
+ meta.events.push('message:created');
160
+ }
161
+ for (const event of meta.events) {
162
+ if (event.startsWith('__every:')) {
163
+ const ms = parseInt(event.slice('__every:'.length), 10);
164
+ if (Number.isFinite(ms) && ms > 0) {
165
+ intervals.push({ ms, run: () => invoke() });
166
+ }
167
+ }
168
+ else if (event !== '__pair') {
169
+ const register = meta.once ? this.once.bind(this) : this.on.bind(this);
170
+ register(event, invoke);
171
+ }
172
+ }
173
+ }
174
+ }
175
+ if (intervals.length > 0) {
176
+ let timer_ids = [];
177
+ this.on('connected', () => {
178
+ for (const { ms, run } of intervals) {
179
+ timer_ids.push(setInterval(() => void run(), ms));
180
+ }
181
+ });
182
+ this.on('disconnected', () => {
183
+ for (const id of timer_ids) {
184
+ clearInterval(id);
185
+ }
186
+ timer_ids = [];
187
+ });
188
+ }
189
+ for (const steps of Object.values(schema.workflows ?? {})) {
190
+ const sorted = [...steps].sort((a, b) => a.index - b.index);
191
+ const funcs = sorted
192
+ .map(({ method }) => {
193
+ const fn = this[method];
194
+ return typeof fn === 'function' ? fn.bind(this) : null;
195
+ })
196
+ .filter((f) => f !== null);
197
+ if (funcs.length > 0) {
198
+ this.on('message:created', (async (...args) => {
199
+ for (const fn of funcs) {
200
+ await fn(...args);
201
+ }
202
+ }));
203
+ }
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
+ export default WhatsAppBot;
210
+ //# sourceMappingURL=decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorator.js","sourceRoot":"","sources":["../../../../src/lib/bot/decorator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,QAA4B,MAAM,gBAAgB,CAAC;AAEzD,MAAgC,CAAC,QAAQ,KAAK,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;AAE7E,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC;AAsB9C;;;;;;;GAOG;AACH,SAAS,OAAO,CAAC,QAAkB,EAAE,WAAmB;IACpD,IAAI,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAA0B,CAAC;IACzD,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,MAAM,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;QACzC,QAAQ,CAAC,QAAQ,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,MAAM,UAAU,sBAAsB,CAClC,QAAkB,EAClB,QAAgB,EAChB,IAAkB;IAElB,IAAI,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAA0B,CAAC;IACzD,IAAI,CAAC,MA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B,CAAC;wBACD,SAAS,GAAG,EAAE,CAAC;oBACnB,CAAC,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;AAED,eAAe,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/index.js';
7
+ import { WhatsAppBot } from './decorator.js';
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;
@@ -0,0 +1,242 @@
1
+ /**
2
+ * @file playground/bot/decorators.ts
3
+ * @description Decoradores públicos del bot.
4
+ * Public bot decorators.
5
+ */
6
+ import { WhatsAppBot, decorator, HANDLERS, register_workflow_step, } from './decorator.js';
7
+ /**
8
+ * Registra el método como listener del evento indicado. Apilable: varios `@on`
9
+ * sobre el mismo método crean múltiples suscripciones.
10
+ * Registers the method as a listener of the given event. Stackable: several
11
+ * `@on` on the same method produce multiple subscriptions.
12
+ *
13
+ * @param event - Nombre del evento del cliente / Client event name
14
+ */
15
+ export const on = decorator((_meta, h, [event]) => {
16
+ if (!h.events.includes(event)) {
17
+ h.events.push(event);
18
+ }
19
+ });
20
+ /**
21
+ * Pre-chequeo del handler. Los guards se acumulan y se evalúan en orden con AND.
22
+ * Si el método no tiene `@on` explícito, se auto-registra a `message:created`.
23
+ * Handler pre-check. Guards accumulate and run in order with AND semantics.
24
+ * If the method has no explicit `@on`, it auto-registers to `message:created`.
25
+ *
26
+ * @param pred - Predicate que recibe los argumentos del evento / Predicate receiving the event arguments
27
+ */
28
+ export const guard = decorator((_meta, h, [pred]) => {
29
+ h.guards.push(pred);
30
+ });
31
+ /**
32
+ * Marca el handler para ejecutarse una sola vez y luego auto-desuscribirse.
33
+ * Con `event` actúa como shortcut de `@on(event) + @once()`.
34
+ * Marks the handler to run once and then auto-unsubscribe. With `event` it acts
35
+ * as a shortcut of `@on(event) + @once()`.
36
+ *
37
+ * @param event - Evento opcional para combinar `@on + @once` en un solo decorador / Optional event to combine `@on + @once` in a single decorator
38
+ */
39
+ export function once(event) {
40
+ return (_value, context) => {
41
+ if (context.kind !== 'method') {
42
+ throw new Error('@once only applicable to methods');
43
+ }
44
+ const metadata = context.metadata;
45
+ if (!metadata[HANDLERS]) {
46
+ metadata[HANDLERS] = { handlers: {}, workflows: {} };
47
+ }
48
+ const schema = metadata[HANDLERS];
49
+ const method_name = String(context.name);
50
+ schema.handlers[method_name] ||= {
51
+ method: method_name,
52
+ events: [],
53
+ guards: [],
54
+ transforms: [],
55
+ once: false,
56
+ };
57
+ schema.handlers[method_name].once = true;
58
+ if (event && !schema.handlers[method_name].events.includes(event)) {
59
+ schema.handlers[method_name].events.push(event);
60
+ }
61
+ };
62
+ }
63
+ /**
64
+ * Alias semántico de `@on('connected')`. El método se invoca al establecerse
65
+ * la conexión con WhatsApp.
66
+ * Semantic alias of `@on('connected')`. The method runs when the WhatsApp
67
+ * connection opens.
68
+ */
69
+ export function connect() {
70
+ return on('connected');
71
+ }
72
+ /**
73
+ * Alias semántico de `@on('disconnected')`. El método se invoca al cerrarse
74
+ * la conexión con WhatsApp.
75
+ * Semantic alias of `@on('disconnected')`. The method runs when the WhatsApp
76
+ * connection closes.
77
+ */
78
+ export function disconnect() {
79
+ return on('disconnected');
80
+ }
81
+ /**
82
+ * Ejecuta el método cada `ms` milisegundos mientras el bot esté conectado.
83
+ * Los timers arrancan en `connected` y se cancelan en `disconnected`.
84
+ * Runs the method every `ms` milliseconds while the bot is connected. Timers
85
+ * start on `connected` and are cancelled on `disconnected`.
86
+ *
87
+ * @param ms - Intervalo en milisegundos / Interval in milliseconds
88
+ */
89
+ export function every(ms) {
90
+ return decorator((_meta, h) => {
91
+ h.events.push(`__every:${ms}`);
92
+ })();
93
+ }
94
+ /**
95
+ * Marca el método como callback de pairing (PIN/QR). Múltiples métodos `@pair`
96
+ * se invocan en paralelo cuando baileys entrega el código.
97
+ * Marks the method as a pairing (PIN/QR) callback. Multiple `@pair` methods run
98
+ * in parallel when baileys delivers the code.
99
+ */
100
+ export const pair = decorator((_meta, h) => {
101
+ if (!h.events.includes('__pair')) {
102
+ h.events.push('__pair');
103
+ }
104
+ });
105
+ /**
106
+ * Filtra por autor del mensaje. Acepta JID, LID o teléfono numérico; el string
107
+ * se normaliza vía `wa._resolve_jid` con cache lazy. Un array produce match OR.
108
+ * Filters by message author. Accepts JID, LID or numeric phone; the string is
109
+ * normalized via `wa._resolve_jid` with lazy cache. An array yields OR matching.
110
+ *
111
+ * @param source - Identificador(es) permitidos o predicate sobre `msg.from` / Allowed identifier(s) or predicate on `msg.from`
112
+ */
113
+ export function from(source) {
114
+ return decorator((_meta, h) => {
115
+ if (typeof source === 'function') {
116
+ h.guards.push((...args) => source(args[0].from));
117
+ }
118
+ else {
119
+ const list = Array.isArray(source) ? source : [source];
120
+ let resolved = null;
121
+ h.guards.push(async (...args) => {
122
+ const msg = args[0];
123
+ const wa = args[args.length - 1];
124
+ if (resolved === null) {
125
+ resolved = new Set();
126
+ for (const raw of list) {
127
+ const r = await wa._resolve_jid(raw);
128
+ if (r) {
129
+ resolved.add(r);
130
+ }
131
+ }
132
+ }
133
+ return resolved.has(msg.from);
134
+ });
135
+ }
136
+ })();
137
+ }
138
+ /**
139
+ * Class decorator que convierte la clase en un bot WhatsApp con opciones default.
140
+ * La clase no necesita extender `WhatsAppBot` manualmente; el decorador produce
141
+ * una subclase que hereda de `WhatsAppBot` y copia los métodos + metadata del
142
+ * target. El constructor acepta un override parcial que se fusiona con las opts
143
+ * por default.
144
+ * Class decorator that turns the class into a WhatsApp bot with default options.
145
+ * The class does not need to extend `WhatsAppBot` manually; the decorator
146
+ * produces a subclass that inherits from `WhatsAppBot` and copies the target's
147
+ * methods and metadata. The constructor accepts a partial override that is
148
+ * merged with the default options.
149
+ *
150
+ * @param default_options - Opciones base para la instancia / Default options for the instance
151
+ */
152
+ export function Bot(default_options) {
153
+ return function (target, _context) {
154
+ const Mixed = class extends WhatsAppBot {
155
+ constructor(override) {
156
+ super({ ...default_options, ...(override ?? {}) });
157
+ }
158
+ };
159
+ for (const key of Object.getOwnPropertyNames(target.prototype)) {
160
+ if (key !== 'constructor') {
161
+ const desc = Object.getOwnPropertyDescriptor(target.prototype, key);
162
+ if (desc) {
163
+ Object.defineProperty(Mixed.prototype, key, desc);
164
+ }
165
+ }
166
+ }
167
+ const meta = target[Symbol.metadata];
168
+ if (meta !== undefined) {
169
+ Object.defineProperty(Mixed, Symbol.metadata, {
170
+ value: meta,
171
+ enumerable: true,
172
+ configurable: true,
173
+ writable: true,
174
+ });
175
+ }
176
+ return Mixed;
177
+ };
178
+ }
179
+ /**
180
+ * Registra el método como paso de un workflow. Todos los steps del mismo
181
+ * `workflow` se ejecutan secuencialmente al recibir `message:created`, ordenados
182
+ * por `index`. Comparten los mismos argumentos (msg, chat, wa), por lo que las
183
+ * mutaciones sobre esos objetos son visibles en los steps posteriores.
184
+ * Registers the method as a step of a workflow. All steps of the same
185
+ * `workflow` run sequentially on `message:created`, ordered by `index`. They
186
+ * share the same arguments (msg, chat, wa), so mutations on those objects are
187
+ * visible to later steps.
188
+ *
189
+ * @param workflow - Nombre del workflow / Workflow name
190
+ * @param index - Posición dentro del workflow (ASC) / Position within the workflow (ASC)
191
+ */
192
+ export function pipe(workflow, index) {
193
+ return (_value, context) => {
194
+ if (context.kind !== 'method') {
195
+ throw new Error('@pipe only applicable to methods');
196
+ }
197
+ const metadata = context.metadata;
198
+ register_workflow_step(metadata, workflow, {
199
+ index,
200
+ method: String(context.name),
201
+ });
202
+ };
203
+ }
204
+ /**
205
+ * Registra el método como comando textual. Internamente aplica
206
+ * `@on('message:created')`, un guard que matchea el `pattern` y un transform
207
+ * que pasa `(msg, chat, args)` al método.
208
+ * Registers the method as a textual command. Internally applies
209
+ * `@on('message:created')`, a guard matching the `pattern` and a transform that
210
+ * passes `(msg, chat, args)` to the method.
211
+ *
212
+ * @param pattern - Prefijo textual o RegExp a matchear contra `msg.caption` / Text prefix or RegExp matched against `msg.caption`
213
+ */
214
+ export function command(pattern) {
215
+ return (value, context) => {
216
+ on('message:created')(value, context);
217
+ guard((...args) => {
218
+ const msg = args[0];
219
+ const text = msg.caption ?? '';
220
+ if (typeof pattern === 'string') {
221
+ return text.startsWith(pattern);
222
+ }
223
+ return pattern.test(text);
224
+ })(value, context);
225
+ const metadata = context.metadata;
226
+ const schema = metadata[HANDLERS];
227
+ const handler = schema.handlers[String(context.name)];
228
+ handler.transforms.push((args) => {
229
+ const msg = args[0];
230
+ const chat = args[1];
231
+ const text = msg.caption ?? '';
232
+ if (typeof pattern === 'string') {
233
+ const rest = text.slice(pattern.length).trim();
234
+ const parsed = rest.length > 0 ? rest.split(/\s+/) : [];
235
+ return [msg, chat, parsed];
236
+ }
237
+ const match = pattern.exec(text);
238
+ return [msg, chat, match ? match.slice(1) : []];
239
+ });
240
+ };
241
+ }
242
+ //# sourceMappingURL=decorators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/lib/bot/decorators.ts"],"names":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CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;gBAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBACxD,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;YAC/B,CAAC;YACD,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjC,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { WhatsAppBot, HANDLERS, decorator } from './decorator.js';
2
+ export type { HandlerMeta, BotSchema, WorkflowStep } from './decorator.js';
3
+ export { on, guard, command, from, once, connect, disconnect, every, pipe, pair, Bot } from './decorators.js';
@@ -0,0 +1,3 @@
1
+ export { WhatsAppBot, HANDLERS, decorator } from './decorator.js';
2
+ export { on, guard, command, from, once, connect, disconnect, every, pipe, pair, Bot } from './decorators.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/bot/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC"}