@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,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":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EACH,WAAW,EACX,SAAS,EACT,QAAQ,EACR,sBAAsB,GAGzB,MAAM,aAAa,CAAC;AAErB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,EAAE,GAAG,SAAS,CAAkB,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE;IAC/D,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,CAA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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"}
@@ -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/index.js';
7
+ import type { WhatsApp } from '../../lib/whatsapp/index.js';
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
+ };