@arcaelas/whatsapp 2.2.0 → 3.0.2

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 (127) hide show
  1. package/build/cjs/decorators.d.ts +9 -0
  2. package/build/cjs/decorators.js +26 -0
  3. package/build/cjs/decorators.js.map +1 -0
  4. package/build/cjs/index.d.ts +6 -10
  5. package/build/cjs/index.js +11 -10
  6. package/build/cjs/index.js.map +1 -1
  7. package/build/cjs/lib/bot/decorator.d.ts +77 -0
  8. package/build/cjs/lib/bot/decorator.js +219 -0
  9. package/build/cjs/lib/bot/decorator.js.map +1 -0
  10. package/build/cjs/lib/bot/decorators.d.ts +113 -0
  11. package/build/cjs/lib/bot/decorators.js +253 -0
  12. package/build/cjs/lib/bot/decorators.js.map +1 -0
  13. package/build/cjs/lib/bot/index.d.ts +3 -0
  14. package/build/cjs/lib/bot/index.js +20 -0
  15. package/build/cjs/lib/bot/index.js.map +1 -0
  16. package/build/cjs/lib/chat/index.d.ts +227 -0
  17. package/build/cjs/lib/chat/index.js +324 -0
  18. package/build/cjs/lib/chat/index.js.map +1 -0
  19. package/build/cjs/lib/contact/index.d.ts +203 -0
  20. package/build/cjs/lib/contact/index.js +226 -0
  21. package/build/cjs/lib/contact/index.js.map +1 -0
  22. package/build/cjs/lib/message/index.d.ts +237 -0
  23. package/build/cjs/lib/message/index.js +685 -0
  24. package/build/cjs/lib/message/index.js.map +1 -0
  25. package/build/cjs/lib/store/engine/index.d.ts +34 -0
  26. package/build/cjs/lib/store/engine/index.js +13 -0
  27. package/build/cjs/lib/store/engine/index.js.map +1 -0
  28. package/build/cjs/lib/store/engine/lib/file_system/index.d.ts +56 -0
  29. package/build/cjs/lib/store/engine/lib/file_system/index.js +160 -0
  30. package/build/cjs/lib/store/engine/lib/file_system/index.js.map +1 -0
  31. package/build/cjs/lib/store/engine/lib/redis/index.d.ts +82 -0
  32. package/build/cjs/lib/store/engine/lib/redis/index.js +132 -0
  33. package/build/cjs/lib/store/engine/lib/redis/index.js.map +1 -0
  34. package/build/cjs/lib/store/index.d.ts +22 -0
  35. package/build/cjs/lib/store/index.js +38 -0
  36. package/build/cjs/lib/store/index.js.map +1 -0
  37. package/build/cjs/lib/whatsapp/index.d.ts +179 -0
  38. package/build/cjs/lib/whatsapp/index.js +754 -0
  39. package/build/cjs/lib/whatsapp/index.js.map +1 -0
  40. package/build/esm/decorators.d.ts +9 -0
  41. package/build/esm/decorators.js +9 -0
  42. package/build/esm/decorators.js.map +1 -0
  43. package/build/esm/index.d.ts +6 -10
  44. package/build/esm/index.js +4 -6
  45. package/build/esm/index.js.map +1 -1
  46. package/build/esm/lib/bot/decorator.d.ts +77 -0
  47. package/build/esm/lib/bot/decorator.js +210 -0
  48. package/build/esm/lib/bot/decorator.js.map +1 -0
  49. package/build/esm/lib/bot/decorators.d.ts +113 -0
  50. package/build/esm/lib/bot/decorators.js +242 -0
  51. package/build/esm/lib/bot/decorators.js.map +1 -0
  52. package/build/esm/lib/bot/index.d.ts +3 -0
  53. package/build/esm/lib/bot/index.js +3 -0
  54. package/build/esm/lib/bot/index.js.map +1 -0
  55. package/build/esm/lib/chat/index.d.ts +227 -0
  56. package/build/esm/lib/chat/index.js +319 -0
  57. package/build/esm/lib/chat/index.js.map +1 -0
  58. package/build/esm/lib/contact/index.d.ts +203 -0
  59. package/build/esm/lib/contact/index.js +221 -0
  60. package/build/esm/lib/contact/index.js.map +1 -0
  61. package/build/esm/lib/message/index.d.ts +237 -0
  62. package/build/esm/lib/message/index.js +673 -0
  63. package/build/esm/lib/message/index.js.map +1 -0
  64. package/build/esm/lib/store/engine/index.d.ts +34 -0
  65. package/build/esm/lib/store/engine/index.js +8 -0
  66. package/build/esm/lib/store/engine/index.js.map +1 -0
  67. package/build/esm/lib/store/engine/lib/file_system/index.d.ts +56 -0
  68. package/build/esm/lib/store/engine/lib/file_system/index.js +156 -0
  69. package/build/esm/lib/store/engine/lib/file_system/index.js.map +1 -0
  70. package/build/esm/lib/store/engine/lib/redis/index.d.ts +82 -0
  71. package/build/esm/lib/store/engine/lib/redis/index.js +128 -0
  72. package/build/esm/lib/store/engine/lib/redis/index.js.map +1 -0
  73. package/build/esm/lib/store/index.d.ts +22 -0
  74. package/build/esm/lib/store/index.js +31 -0
  75. package/build/esm/lib/store/index.js.map +1 -0
  76. package/build/esm/lib/whatsapp/index.d.ts +179 -0
  77. package/build/esm/lib/whatsapp/index.js +714 -0
  78. package/build/esm/lib/whatsapp/index.js.map +1 -0
  79. package/package.json +8 -6
  80. package/build/cjs/Chat.d.ts +0 -317
  81. package/build/cjs/Chat.js +0 -275
  82. package/build/cjs/Chat.js.map +0 -1
  83. package/build/cjs/Contact.d.ts +0 -1163
  84. package/build/cjs/Contact.js +0 -162
  85. package/build/cjs/Contact.js.map +0 -1
  86. package/build/cjs/Message.d.ts +0 -902
  87. package/build/cjs/Message.js +0 -515
  88. package/build/cjs/Message.js.map +0 -1
  89. package/build/cjs/WhatsApp.d.ts +0 -80
  90. package/build/cjs/WhatsApp.js +0 -412
  91. package/build/cjs/WhatsApp.js.map +0 -1
  92. package/build/cjs/store/driver/FileEngine.d.ts +0 -34
  93. package/build/cjs/store/driver/FileEngine.js +0 -86
  94. package/build/cjs/store/driver/FileEngine.js.map +0 -1
  95. package/build/cjs/store/driver/RedisEngine.d.ts +0 -47
  96. package/build/cjs/store/driver/RedisEngine.js +0 -70
  97. package/build/cjs/store/driver/RedisEngine.js.map +0 -1
  98. package/build/cjs/store/engine.d.ts +0 -53
  99. package/build/cjs/store/engine.js +0 -7
  100. package/build/cjs/store/engine.js.map +0 -1
  101. package/build/cjs/store/index.d.ts +0 -8
  102. package/build/cjs/store/index.js +0 -12
  103. package/build/cjs/store/index.js.map +0 -1
  104. package/build/esm/Chat.d.ts +0 -317
  105. package/build/esm/Chat.js +0 -270
  106. package/build/esm/Chat.js.map +0 -1
  107. package/build/esm/Contact.d.ts +0 -1163
  108. package/build/esm/Contact.js +0 -157
  109. package/build/esm/Contact.js.map +0 -1
  110. package/build/esm/Message.d.ts +0 -902
  111. package/build/esm/Message.js +0 -510
  112. package/build/esm/Message.js.map +0 -1
  113. package/build/esm/WhatsApp.d.ts +0 -80
  114. package/build/esm/WhatsApp.js +0 -372
  115. package/build/esm/WhatsApp.js.map +0 -1
  116. package/build/esm/store/driver/FileEngine.d.ts +0 -34
  117. package/build/esm/store/driver/FileEngine.js +0 -82
  118. package/build/esm/store/driver/FileEngine.js.map +0 -1
  119. package/build/esm/store/driver/RedisEngine.d.ts +0 -47
  120. package/build/esm/store/driver/RedisEngine.js +0 -66
  121. package/build/esm/store/driver/RedisEngine.js.map +0 -1
  122. package/build/esm/store/engine.d.ts +0 -53
  123. package/build/esm/store/engine.js +0 -6
  124. package/build/esm/store/engine.js.map +0 -1
  125. package/build/esm/store/index.d.ts +0 -8
  126. package/build/esm/store/index.js +0 -7
  127. package/build/esm/store/index.js.map +0 -1
@@ -0,0 +1,253 @@
1
+ "use strict";
2
+ /**
3
+ * @file playground/bot/decorators.ts
4
+ * @description Decoradores públicos del bot.
5
+ * Public bot decorators.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.pair = exports.guard = exports.on = void 0;
9
+ exports.once = once;
10
+ exports.connect = connect;
11
+ exports.disconnect = disconnect;
12
+ exports.every = every;
13
+ exports.from = from;
14
+ exports.Bot = Bot;
15
+ exports.pipe = pipe;
16
+ exports.command = command;
17
+ const decorator_1 = require("./decorator");
18
+ /**
19
+ * Registra el método como listener del evento indicado. Apilable: varios `@on`
20
+ * sobre el mismo método crean múltiples suscripciones.
21
+ * Registers the method as a listener of the given event. Stackable: several
22
+ * `@on` on the same method produce multiple subscriptions.
23
+ *
24
+ * @param event - Nombre del evento del cliente / Client event name
25
+ */
26
+ exports.on = (0, decorator_1.decorator)((_meta, h, [event]) => {
27
+ if (!h.events.includes(event)) {
28
+ h.events.push(event);
29
+ }
30
+ });
31
+ /**
32
+ * Pre-chequeo del handler. Los guards se acumulan y se evalúan en orden con AND.
33
+ * Si el método no tiene `@on` explícito, se auto-registra a `message:created`.
34
+ * Handler pre-check. Guards accumulate and run in order with AND semantics.
35
+ * If the method has no explicit `@on`, it auto-registers to `message:created`.
36
+ *
37
+ * @param pred - Predicate que recibe los argumentos del evento / Predicate receiving the event arguments
38
+ */
39
+ exports.guard = (0, decorator_1.decorator)((_meta, h, [pred]) => {
40
+ h.guards.push(pred);
41
+ });
42
+ /**
43
+ * Marca el handler para ejecutarse una sola vez y luego auto-desuscribirse.
44
+ * Con `event` actúa como shortcut de `@on(event) + @once()`.
45
+ * Marks the handler to run once and then auto-unsubscribe. With `event` it acts
46
+ * as a shortcut of `@on(event) + @once()`.
47
+ *
48
+ * @param event - Evento opcional para combinar `@on + @once` en un solo decorador / Optional event to combine `@on + @once` in a single decorator
49
+ */
50
+ function once(event) {
51
+ return (_value, context) => {
52
+ if (context.kind !== 'method') {
53
+ throw new Error('@once only applicable to methods');
54
+ }
55
+ const metadata = context.metadata;
56
+ if (!metadata[decorator_1.HANDLERS]) {
57
+ metadata[decorator_1.HANDLERS] = { handlers: {}, workflows: {} };
58
+ }
59
+ const schema = metadata[decorator_1.HANDLERS];
60
+ const method_name = String(context.name);
61
+ schema.handlers[method_name] ||= {
62
+ method: method_name,
63
+ events: [],
64
+ guards: [],
65
+ transforms: [],
66
+ once: false,
67
+ };
68
+ schema.handlers[method_name].once = true;
69
+ if (event && !schema.handlers[method_name].events.includes(event)) {
70
+ schema.handlers[method_name].events.push(event);
71
+ }
72
+ };
73
+ }
74
+ /**
75
+ * Alias semántico de `@on('connected')`. El método se invoca al establecerse
76
+ * la conexión con WhatsApp.
77
+ * Semantic alias of `@on('connected')`. The method runs when the WhatsApp
78
+ * connection opens.
79
+ */
80
+ function connect() {
81
+ return (0, exports.on)('connected');
82
+ }
83
+ /**
84
+ * Alias semántico de `@on('disconnected')`. El método se invoca al cerrarse
85
+ * la conexión con WhatsApp.
86
+ * Semantic alias of `@on('disconnected')`. The method runs when the WhatsApp
87
+ * connection closes.
88
+ */
89
+ function disconnect() {
90
+ return (0, exports.on)('disconnected');
91
+ }
92
+ /**
93
+ * Ejecuta el método cada `ms` milisegundos mientras el bot esté conectado.
94
+ * Los timers arrancan en `connected` y se cancelan en `disconnected`.
95
+ * Runs the method every `ms` milliseconds while the bot is connected. Timers
96
+ * start on `connected` and are cancelled on `disconnected`.
97
+ *
98
+ * @param ms - Intervalo en milisegundos / Interval in milliseconds
99
+ */
100
+ function every(ms) {
101
+ return (0, decorator_1.decorator)((_meta, h) => {
102
+ h.events.push(`__every:${ms}`);
103
+ })();
104
+ }
105
+ /**
106
+ * Marca el método como callback de pairing (PIN/QR). Múltiples métodos `@pair`
107
+ * se invocan en paralelo cuando baileys entrega el código.
108
+ * Marks the method as a pairing (PIN/QR) callback. Multiple `@pair` methods run
109
+ * in parallel when baileys delivers the code.
110
+ */
111
+ exports.pair = (0, decorator_1.decorator)((_meta, h) => {
112
+ if (!h.events.includes('__pair')) {
113
+ h.events.push('__pair');
114
+ }
115
+ });
116
+ /**
117
+ * Filtra por autor del mensaje. Acepta JID, LID o teléfono numérico; el string
118
+ * se normaliza vía `wa._resolve_jid` con cache lazy. Un array produce match OR.
119
+ * Filters by message author. Accepts JID, LID or numeric phone; the string is
120
+ * normalized via `wa._resolve_jid` with lazy cache. An array yields OR matching.
121
+ *
122
+ * @param source - Identificador(es) permitidos o predicate sobre `msg.from` / Allowed identifier(s) or predicate on `msg.from`
123
+ */
124
+ function from(source) {
125
+ return (0, decorator_1.decorator)((_meta, h) => {
126
+ if (typeof source === 'function') {
127
+ h.guards.push((...args) => source(args[0].from));
128
+ }
129
+ else {
130
+ const list = Array.isArray(source) ? source : [source];
131
+ let resolved = null;
132
+ h.guards.push(async (...args) => {
133
+ const msg = args[0];
134
+ const wa = args[args.length - 1];
135
+ if (resolved === null) {
136
+ resolved = new Set();
137
+ for (const raw of list) {
138
+ const r = await wa._resolve_jid(raw);
139
+ if (r) {
140
+ resolved.add(r);
141
+ }
142
+ }
143
+ }
144
+ return resolved.has(msg.from);
145
+ });
146
+ }
147
+ })();
148
+ }
149
+ /**
150
+ * Class decorator que convierte la clase en un bot WhatsApp con opciones default.
151
+ * La clase no necesita extender `WhatsAppBot` manualmente; el decorador produce
152
+ * una subclase que hereda de `WhatsAppBot` y copia los métodos + metadata del
153
+ * target. El constructor acepta un override parcial que se fusiona con las opts
154
+ * por default.
155
+ * Class decorator that turns the class into a WhatsApp bot with default options.
156
+ * The class does not need to extend `WhatsAppBot` manually; the decorator
157
+ * produces a subclass that inherits from `WhatsAppBot` and copies the target's
158
+ * methods and metadata. The constructor accepts a partial override that is
159
+ * merged with the default options.
160
+ *
161
+ * @param default_options - Opciones base para la instancia / Default options for the instance
162
+ */
163
+ function Bot(default_options) {
164
+ return function (target, _context) {
165
+ const Mixed = class extends decorator_1.WhatsAppBot {
166
+ constructor(override) {
167
+ super({ ...default_options, ...(override ?? {}) });
168
+ }
169
+ };
170
+ for (const key of Object.getOwnPropertyNames(target.prototype)) {
171
+ if (key !== 'constructor') {
172
+ const desc = Object.getOwnPropertyDescriptor(target.prototype, key);
173
+ if (desc) {
174
+ Object.defineProperty(Mixed.prototype, key, desc);
175
+ }
176
+ }
177
+ }
178
+ const meta = target[Symbol.metadata];
179
+ if (meta !== undefined) {
180
+ Object.defineProperty(Mixed, Symbol.metadata, {
181
+ value: meta,
182
+ enumerable: true,
183
+ configurable: true,
184
+ writable: true,
185
+ });
186
+ }
187
+ return Mixed;
188
+ };
189
+ }
190
+ /**
191
+ * Registra el método como paso de un workflow. Todos los steps del mismo
192
+ * `workflow` se ejecutan secuencialmente al recibir `message:created`, ordenados
193
+ * por `index`. Comparten los mismos argumentos (msg, chat, wa), por lo que las
194
+ * mutaciones sobre esos objetos son visibles en los steps posteriores.
195
+ * Registers the method as a step of a workflow. All steps of the same
196
+ * `workflow` run sequentially on `message:created`, ordered by `index`. They
197
+ * share the same arguments (msg, chat, wa), so mutations on those objects are
198
+ * visible to later steps.
199
+ *
200
+ * @param workflow - Nombre del workflow / Workflow name
201
+ * @param index - Posición dentro del workflow (ASC) / Position within the workflow (ASC)
202
+ */
203
+ function pipe(workflow, index) {
204
+ return (_value, context) => {
205
+ if (context.kind !== 'method') {
206
+ throw new Error('@pipe only applicable to methods');
207
+ }
208
+ const metadata = context.metadata;
209
+ (0, decorator_1.register_workflow_step)(metadata, workflow, {
210
+ index,
211
+ method: String(context.name),
212
+ });
213
+ };
214
+ }
215
+ /**
216
+ * Registra el método como comando textual. Internamente aplica
217
+ * `@on('message:created')`, un guard que matchea el `pattern` y un transform
218
+ * que pasa `(msg, chat, args)` al método.
219
+ * Registers the method as a textual command. Internally applies
220
+ * `@on('message:created')`, a guard matching the `pattern` and a transform that
221
+ * passes `(msg, chat, args)` to the method.
222
+ *
223
+ * @param pattern - Prefijo textual o RegExp a matchear contra `msg.caption` / Text prefix or RegExp matched against `msg.caption`
224
+ */
225
+ function command(pattern) {
226
+ return (value, context) => {
227
+ (0, exports.on)('message:created')(value, context);
228
+ (0, exports.guard)((...args) => {
229
+ const msg = args[0];
230
+ const text = msg.caption ?? '';
231
+ if (typeof pattern === 'string') {
232
+ return text.startsWith(pattern);
233
+ }
234
+ return pattern.test(text);
235
+ })(value, context);
236
+ const metadata = context.metadata;
237
+ const schema = metadata[decorator_1.HANDLERS];
238
+ const handler = schema.handlers[String(context.name)];
239
+ handler.transforms.push((args) => {
240
+ const msg = args[0];
241
+ const chat = args[1];
242
+ const text = msg.caption ?? '';
243
+ if (typeof pattern === 'string') {
244
+ const rest = text.slice(pattern.length).trim();
245
+ const parsed = rest.length > 0 ? rest.split(/\s+/) : [];
246
+ return [msg, chat, parsed];
247
+ }
248
+ const match = pattern.exec(text);
249
+ return [msg, chat, match ? match.slice(1) : []];
250
+ });
251
+ };
252
+ }
253
+ //# sourceMappingURL=decorators.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../../../../src/lib/bot/decorators.ts"],"names":[],"mappings":";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AAM,IAAI,GAAG,IAAI,CAAC,KAAK,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';
2
+ export type { HandlerMeta, BotSchema, WorkflowStep } from './decorator';
3
+ export { on, guard, command, from, once, connect, disconnect, every, pipe, pair, Bot } from './decorators';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Bot = exports.pair = exports.pipe = exports.every = exports.disconnect = exports.connect = exports.once = exports.from = exports.command = exports.guard = exports.on = exports.decorator = exports.HANDLERS = exports.WhatsAppBot = void 0;
4
+ var decorator_1 = require("./decorator");
5
+ Object.defineProperty(exports, "WhatsAppBot", { enumerable: true, get: function () { return decorator_1.WhatsAppBot; } });
6
+ Object.defineProperty(exports, "HANDLERS", { enumerable: true, get: function () { return decorator_1.HANDLERS; } });
7
+ Object.defineProperty(exports, "decorator", { enumerable: true, get: function () { return decorator_1.decorator; } });
8
+ var decorators_1 = require("./decorators");
9
+ Object.defineProperty(exports, "on", { enumerable: true, get: function () { return decorators_1.on; } });
10
+ Object.defineProperty(exports, "guard", { enumerable: true, get: function () { return decorators_1.guard; } });
11
+ Object.defineProperty(exports, "command", { enumerable: true, get: function () { return decorators_1.command; } });
12
+ Object.defineProperty(exports, "from", { enumerable: true, get: function () { return decorators_1.from; } });
13
+ Object.defineProperty(exports, "once", { enumerable: true, get: function () { return decorators_1.once; } });
14
+ Object.defineProperty(exports, "connect", { enumerable: true, get: function () { return decorators_1.connect; } });
15
+ Object.defineProperty(exports, "disconnect", { enumerable: true, get: function () { return decorators_1.disconnect; } });
16
+ Object.defineProperty(exports, "every", { enumerable: true, get: function () { return decorators_1.every; } });
17
+ Object.defineProperty(exports, "pipe", { enumerable: true, get: function () { return decorators_1.pipe; } });
18
+ Object.defineProperty(exports, "pair", { enumerable: true, get: function () { return decorators_1.pair; } });
19
+ Object.defineProperty(exports, "Bot", { enumerable: true, get: function () { return decorators_1.Bot; } });
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/bot/index.ts"],"names":[],"mappings":";;;AAAA,yCAA+D;AAAtD,wGAAA,WAAW,OAAA;AAAE,qGAAA,QAAQ,OAAA;AAAE,sGAAA,SAAS,OAAA;AAEzC,2CAA2G;AAAlG,gGAAA,EAAE,OAAA;AAAE,mGAAA,KAAK,OAAA;AAAE,qGAAA,OAAO,OAAA;AAAE,kGAAA,IAAI,OAAA;AAAE,kGAAA,IAAI,OAAA;AAAE,qGAAA,OAAO,OAAA;AAAE,wGAAA,UAAU,OAAA;AAAE,mGAAA,KAAK,OAAA;AAAE,kGAAA,IAAI,OAAA;AAAE,kGAAA,IAAI,OAAA;AAAE,iGAAA,GAAG,OAAA"}
@@ -0,0 +1,227 @@
1
+ /**
2
+ * @file chat/index.ts
3
+ * @description Entidad Chat — conversaciones individuales y grupales.
4
+ * Chat entity — individual and group conversations.
5
+ */
6
+ import type { Message } from '../../lib/message';
7
+ import type { WhatsApp } from '../../lib/whatsapp';
8
+ /**
9
+ * Participante de grupo.
10
+ * Group participant.
11
+ */
12
+ export interface GroupParticipant {
13
+ id: string;
14
+ admin: string | null;
15
+ }
16
+ /**
17
+ * Shape persistido del chat (snake_case).
18
+ * Persisted chat shape (snake_case).
19
+ */
20
+ export interface IChatRaw {
21
+ id: string;
22
+ name?: string | null;
23
+ display_name?: string | null;
24
+ description?: string | null;
25
+ unread_count?: number | null;
26
+ read_only?: boolean | null;
27
+ archived?: boolean | null;
28
+ pinned?: number | null;
29
+ mute_end_time?: number | null;
30
+ marked_as_unread?: boolean | null;
31
+ participants?: GroupParticipant[] | null;
32
+ created_by?: string | null;
33
+ created_at?: number | null;
34
+ ephemeral_expiration?: number | null;
35
+ }
36
+ /**
37
+ * Clase base del chat (forma pública, solo lectura).
38
+ * Base Chat class (public shape, read-only).
39
+ */
40
+ export declare class Chat {
41
+ /** @internal Shape persistido. Uso interno. / Internal persisted shape. */
42
+ readonly _raw: IChatRaw;
43
+ constructor(raw: IChatRaw);
44
+ /** JID del chat. / Chat JID. */
45
+ get id(): string;
46
+ /** CID (alias). / CID (alias). */
47
+ get cid(): string;
48
+ /** Tipo: contact o group. / Type: contact or group. */
49
+ get type(): 'contact' | 'group';
50
+ /** Nombre del chat. / Chat name. */
51
+ get name(): string;
52
+ /** Descripción del grupo. / Group description. */
53
+ get content(): string;
54
+ /** Si está fijado. / Whether it's pinned. */
55
+ get pinned(): boolean;
56
+ /** Si está archivado. / Whether it's archived. */
57
+ get archived(): boolean;
58
+ /** true si el chat está silenciado y el silencio aún no expira. / true if chat is muted and the mute has not expired. */
59
+ get muted(): boolean;
60
+ /** Si está leído. / Whether it's read. */
61
+ get read(): boolean;
62
+ /** Si es solo lectura. / Whether it's read-only. */
63
+ get readonly(): boolean;
64
+ }
65
+ /**
66
+ * Factoría de Chat ligada al contexto WhatsApp.
67
+ * Context-bound Chat factory.
68
+ *
69
+ * @param wa - Instancia principal / Main WhatsApp instance
70
+ */
71
+ export declare function chat(wa: WhatsApp): {
72
+ new (raw: IChatRaw): {
73
+ /** Re-hidrata metadata del chat desde el socket. / Re-hydrates chat metadata from the socket. */
74
+ refresh(): Promise</*elided*/ any | null>;
75
+ /** Fija/desfija el chat. / Pins or unpins the chat. */
76
+ pin(value: boolean): Promise<boolean>;
77
+ /** Archiva/desarchiva el chat. / Archives or unarchives the chat. */
78
+ archive(value: boolean): Promise<boolean>;
79
+ /** Silencia/des-silencia el chat. / Mutes or unmutes the chat. */
80
+ mute(value: boolean): Promise<boolean>;
81
+ /** Marca todos los mensajes del chat como leídos. / Marks all chat messages as read. */
82
+ seen(): Promise<boolean>;
83
+ /** Toggle "Escribiendo...". / Toggles the "typing..." indicator. */
84
+ typing(on: boolean): Promise<boolean>;
85
+ /** Toggle "Grabando audio...". / Toggles the "recording audio..." indicator. */
86
+ recording(on: boolean): Promise<boolean>;
87
+ /** Vacía mensajes del chat (engine local). / Clears chat messages (local engine). */
88
+ clear(): Promise<boolean>;
89
+ /** Elimina el chat y sus mensajes (remoto + local). / Deletes the chat and its messages (remote + local). */
90
+ delete(): Promise<boolean>;
91
+ /** Participantes del chat paginados (incluyéndome en grupos). / Chat participants paginated (self included in groups). */
92
+ members(offset?: number, limit?: number): Promise<InstanceType<typeof wa.Contact>[]>;
93
+ /** Mensajes del chat paginados por mtime DESC. / Chat messages paginated by mtime DESC. */
94
+ messages(offset?: number, limit?: number): Promise<Message[]>;
95
+ /** @internal Shape persistido. Uso interno. / Internal persisted shape. */
96
+ readonly _raw: IChatRaw;
97
+ /** JID del chat. / Chat JID. */
98
+ get id(): string;
99
+ /** CID (alias). / CID (alias). */
100
+ get cid(): string;
101
+ /** Tipo: contact o group. / Type: contact or group. */
102
+ get type(): "contact" | "group";
103
+ /** Nombre del chat. / Chat name. */
104
+ get name(): string;
105
+ /** Descripción del grupo. / Group description. */
106
+ get content(): string;
107
+ /** Si está fijado. / Whether it's pinned. */
108
+ get pinned(): boolean;
109
+ /** Si está archivado. / Whether it's archived. */
110
+ get archived(): boolean;
111
+ /** true si el chat está silenciado y el silencio aún no expira. / true if chat is muted and the mute has not expired. */
112
+ get muted(): boolean;
113
+ /** Si está leído. / Whether it's read. */
114
+ get read(): boolean;
115
+ /** Si es solo lectura. / Whether it's read-only. */
116
+ get readonly(): boolean;
117
+ };
118
+ /**
119
+ * Obtiene un chat por CID. Si no está persistido, lo crea a partir del contacto.
120
+ * Retrieves a chat by CID. If not persisted, creates it from the contact.
121
+ */
122
+ get(cid: string): Promise<{
123
+ /** Re-hidrata metadata del chat desde el socket. / Re-hydrates chat metadata from the socket. */
124
+ refresh(): Promise</*elided*/ any | null>;
125
+ /** Fija/desfija el chat. / Pins or unpins the chat. */
126
+ pin(value: boolean): Promise<boolean>;
127
+ /** Archiva/desarchiva el chat. / Archives or unarchives the chat. */
128
+ archive(value: boolean): Promise<boolean>;
129
+ /** Silencia/des-silencia el chat. / Mutes or unmutes the chat. */
130
+ mute(value: boolean): Promise<boolean>;
131
+ /** Marca todos los mensajes del chat como leídos. / Marks all chat messages as read. */
132
+ seen(): Promise<boolean>;
133
+ /** Toggle "Escribiendo...". / Toggles the "typing..." indicator. */
134
+ typing(on: boolean): Promise<boolean>;
135
+ /** Toggle "Grabando audio...". / Toggles the "recording audio..." indicator. */
136
+ recording(on: boolean): Promise<boolean>;
137
+ /** Vacía mensajes del chat (engine local). / Clears chat messages (local engine). */
138
+ clear(): Promise<boolean>;
139
+ /** Elimina el chat y sus mensajes (remoto + local). / Deletes the chat and its messages (remote + local). */
140
+ delete(): Promise<boolean>;
141
+ /** Participantes del chat paginados (incluyéndome en grupos). / Chat participants paginated (self included in groups). */
142
+ members(offset?: number, limit?: number): Promise<InstanceType<typeof wa.Contact>[]>;
143
+ /** Mensajes del chat paginados por mtime DESC. / Chat messages paginated by mtime DESC. */
144
+ messages(offset?: number, limit?: number): Promise<Message[]>;
145
+ /** @internal Shape persistido. Uso interno. / Internal persisted shape. */
146
+ readonly _raw: IChatRaw;
147
+ /** JID del chat. / Chat JID. */
148
+ get id(): string;
149
+ /** CID (alias). / CID (alias). */
150
+ get cid(): string;
151
+ /** Tipo: contact o group. / Type: contact or group. */
152
+ get type(): "contact" | "group";
153
+ /** Nombre del chat. / Chat name. */
154
+ get name(): string;
155
+ /** Descripción del grupo. / Group description. */
156
+ get content(): string;
157
+ /** Si está fijado. / Whether it's pinned. */
158
+ get pinned(): boolean;
159
+ /** Si está archivado. / Whether it's archived. */
160
+ get archived(): boolean;
161
+ /** true si el chat está silenciado y el silencio aún no expira. / true if chat is muted and the mute has not expired. */
162
+ get muted(): boolean;
163
+ /** Si está leído. / Whether it's read. */
164
+ get read(): boolean;
165
+ /** Si es solo lectura. / Whether it's read-only. */
166
+ get readonly(): boolean;
167
+ } | null>;
168
+ /** Pagina los chats persistidos por mtime DESC. / Paginates persisted chats by mtime DESC. */
169
+ list(offset?: number, limit?: number): Promise<{
170
+ /** Re-hidrata metadata del chat desde el socket. / Re-hydrates chat metadata from the socket. */
171
+ refresh(): Promise</*elided*/ any | null>;
172
+ /** Fija/desfija el chat. / Pins or unpins the chat. */
173
+ pin(value: boolean): Promise<boolean>;
174
+ /** Archiva/desarchiva el chat. / Archives or unarchives the chat. */
175
+ archive(value: boolean): Promise<boolean>;
176
+ /** Silencia/des-silencia el chat. / Mutes or unmutes the chat. */
177
+ mute(value: boolean): Promise<boolean>;
178
+ /** Marca todos los mensajes del chat como leídos. / Marks all chat messages as read. */
179
+ seen(): Promise<boolean>;
180
+ /** Toggle "Escribiendo...". / Toggles the "typing..." indicator. */
181
+ typing(on: boolean): Promise<boolean>;
182
+ /** Toggle "Grabando audio...". / Toggles the "recording audio..." indicator. */
183
+ recording(on: boolean): Promise<boolean>;
184
+ /** Vacía mensajes del chat (engine local). / Clears chat messages (local engine). */
185
+ clear(): Promise<boolean>;
186
+ /** Elimina el chat y sus mensajes (remoto + local). / Deletes the chat and its messages (remote + local). */
187
+ delete(): Promise<boolean>;
188
+ /** Participantes del chat paginados (incluyéndome en grupos). / Chat participants paginated (self included in groups). */
189
+ members(offset?: number, limit?: number): Promise<InstanceType<typeof wa.Contact>[]>;
190
+ /** Mensajes del chat paginados por mtime DESC. / Chat messages paginated by mtime DESC. */
191
+ messages(offset?: number, limit?: number): Promise<Message[]>;
192
+ /** @internal Shape persistido. Uso interno. / Internal persisted shape. */
193
+ readonly _raw: IChatRaw;
194
+ /** JID del chat. / Chat JID. */
195
+ get id(): string;
196
+ /** CID (alias). / CID (alias). */
197
+ get cid(): string;
198
+ /** Tipo: contact o group. / Type: contact or group. */
199
+ get type(): "contact" | "group";
200
+ /** Nombre del chat. / Chat name. */
201
+ get name(): string;
202
+ /** Descripción del grupo. / Group description. */
203
+ get content(): string;
204
+ /** Si está fijado. / Whether it's pinned. */
205
+ get pinned(): boolean;
206
+ /** Si está archivado. / Whether it's archived. */
207
+ get archived(): boolean;
208
+ /** true si el chat está silenciado y el silencio aún no expira. / true if chat is muted and the mute has not expired. */
209
+ get muted(): boolean;
210
+ /** Si está leído. / Whether it's read. */
211
+ get read(): boolean;
212
+ /** Si es solo lectura. / Whether it's read-only. */
213
+ get readonly(): boolean;
214
+ }[]>;
215
+ /** Fija/desfija un chat por CID. / Pins or unpins a chat by CID. */
216
+ pin(cid: string, value: boolean): Promise<boolean>;
217
+ /** Archiva/desarchiva un chat por CID. / Archives or unarchives a chat by CID. */
218
+ archive(cid: string, value: boolean): Promise<boolean>;
219
+ /** Silencia/des-silencia un chat por CID. / Mutes or unmutes a chat by CID. */
220
+ mute(cid: string, value: boolean): Promise<boolean>;
221
+ /** Marca todos los mensajes del chat como leídos. / Marks all chat messages as read. */
222
+ seen(cid: string): Promise<boolean>;
223
+ /** Vacía mensajes del chat (local). / Clears the chat's messages (local only). */
224
+ clear(cid: string): Promise<boolean>;
225
+ /** Elimina el chat y sus mensajes. / Deletes the chat and its messages. */
226
+ delete(cid: string): Promise<boolean>;
227
+ };