@arcaelas/whatsapp 3.1.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/_index.d.ts +14 -0
- package/build/cjs/_index.js +346 -0
- package/build/cjs/_index.js.map +1 -0
- package/build/cjs/decorators.d.ts +9 -0
- package/build/cjs/decorators.js +26 -0
- package/build/cjs/decorators.js.map +1 -0
- package/build/cjs/index.d.ts +11 -0
- package/build/cjs/index.js +21 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/lib/bot/decorator.d.ts +77 -0
- package/build/cjs/lib/bot/decorator.js +219 -0
- package/build/cjs/lib/bot/decorator.js.map +1 -0
- package/build/cjs/lib/bot/decorators.d.ts +113 -0
- package/build/cjs/lib/bot/decorators.js +253 -0
- package/build/cjs/lib/bot/decorators.js.map +1 -0
- package/build/cjs/lib/bot/index.d.ts +3 -0
- package/build/cjs/lib/bot/index.js +20 -0
- package/build/cjs/lib/bot/index.js.map +1 -0
- package/build/cjs/lib/chat/index.d.ts +260 -0
- package/build/cjs/lib/chat/index.js +341 -0
- package/build/cjs/lib/chat/index.js.map +1 -0
- package/build/cjs/lib/contact/index.d.ts +203 -0
- package/build/cjs/lib/contact/index.js +226 -0
- package/build/cjs/lib/contact/index.js.map +1 -0
- package/build/cjs/lib/message/index.d.ts +277 -0
- package/build/cjs/lib/message/index.js +767 -0
- package/build/cjs/lib/message/index.js.map +1 -0
- package/build/cjs/lib/status/index.d.ts +85 -0
- package/build/cjs/lib/status/index.js +137 -0
- package/build/cjs/lib/status/index.js.map +1 -0
- package/build/cjs/lib/store/engine/index.d.ts +34 -0
- package/build/cjs/lib/store/engine/index.js +13 -0
- package/build/cjs/lib/store/engine/index.js.map +1 -0
- package/build/cjs/lib/store/engine/lib/file_system/index.d.ts +56 -0
- package/build/cjs/lib/store/engine/lib/file_system/index.js +160 -0
- package/build/cjs/lib/store/engine/lib/file_system/index.js.map +1 -0
- package/build/cjs/lib/store/engine/lib/redis/index.d.ts +82 -0
- package/build/cjs/lib/store/engine/lib/redis/index.js +132 -0
- package/build/cjs/lib/store/engine/lib/redis/index.js.map +1 -0
- package/build/cjs/lib/store/index.d.ts +22 -0
- package/build/cjs/lib/store/index.js +38 -0
- package/build/cjs/lib/store/index.js.map +1 -0
- package/build/cjs/lib/whatsapp/index.d.ts +185 -0
- package/build/cjs/lib/whatsapp/index.js +870 -0
- package/build/cjs/lib/whatsapp/index.js.map +1 -0
- package/build/cjs/package.json +1 -0
- package/build/esm/_index.d.ts +14 -0
- package/build/esm/_index.js +344 -0
- package/build/esm/_index.js.map +1 -0
- package/build/esm/decorators.d.ts +9 -0
- package/build/esm/decorators.js +9 -0
- package/build/esm/decorators.js.map +1 -0
- package/build/esm/index.d.ts +11 -0
- package/build/esm/index.js +9 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/lib/bot/decorator.d.ts +77 -0
- package/build/esm/lib/bot/decorator.js +210 -0
- package/build/esm/lib/bot/decorator.js.map +1 -0
- package/build/esm/lib/bot/decorators.d.ts +113 -0
- package/build/esm/lib/bot/decorators.js +242 -0
- package/build/esm/lib/bot/decorators.js.map +1 -0
- package/build/esm/lib/bot/index.d.ts +3 -0
- package/build/esm/lib/bot/index.js +3 -0
- package/build/esm/lib/bot/index.js.map +1 -0
- package/build/esm/lib/chat/index.d.ts +260 -0
- package/build/esm/lib/chat/index.js +336 -0
- package/build/esm/lib/chat/index.js.map +1 -0
- package/build/esm/lib/contact/index.d.ts +203 -0
- package/build/esm/lib/contact/index.js +221 -0
- package/build/esm/lib/contact/index.js.map +1 -0
- package/build/esm/lib/message/index.d.ts +277 -0
- package/build/esm/lib/message/index.js +755 -0
- package/build/esm/lib/message/index.js.map +1 -0
- package/build/esm/lib/status/index.d.ts +85 -0
- package/build/esm/lib/status/index.js +133 -0
- package/build/esm/lib/status/index.js.map +1 -0
- package/build/esm/lib/store/engine/index.d.ts +34 -0
- package/build/esm/lib/store/engine/index.js +8 -0
- package/build/esm/lib/store/engine/index.js.map +1 -0
- package/build/esm/lib/store/engine/lib/file_system/index.d.ts +56 -0
- package/build/esm/lib/store/engine/lib/file_system/index.js +156 -0
- package/build/esm/lib/store/engine/lib/file_system/index.js.map +1 -0
- package/build/esm/lib/store/engine/lib/redis/index.d.ts +82 -0
- package/build/esm/lib/store/engine/lib/redis/index.js +128 -0
- package/build/esm/lib/store/engine/lib/redis/index.js.map +1 -0
- package/build/esm/lib/store/index.d.ts +22 -0
- package/build/esm/lib/store/index.js +31 -0
- package/build/esm/lib/store/index.js.map +1 -0
- package/build/esm/lib/whatsapp/index.d.ts +185 -0
- package/build/esm/lib/whatsapp/index.js +830 -0
- package/build/esm/lib/whatsapp/index.js.map +1 -0
- package/build/esm/package.json +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file contact/index.ts
|
|
3
|
+
* @description Entidad Contact — lectura/escritura documental sobre `wa.engine`.
|
|
4
|
+
* Contact entity — documental read/write over `wa.engine`.
|
|
5
|
+
*/
|
|
6
|
+
import { Chat } from '../../lib/chat';
|
|
7
|
+
import type { WhatsApp } from '../../lib/whatsapp';
|
|
8
|
+
/**
|
|
9
|
+
* Shape persistido del contacto.
|
|
10
|
+
* Persisted contact shape.
|
|
11
|
+
*/
|
|
12
|
+
export interface IContactRaw {
|
|
13
|
+
id: string;
|
|
14
|
+
lid?: string | null;
|
|
15
|
+
name?: string | null;
|
|
16
|
+
notify?: string | null;
|
|
17
|
+
verified_name?: string | null;
|
|
18
|
+
img_url?: string | null;
|
|
19
|
+
status?: string | null;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Clase base del contacto (forma pública, solo lectura).
|
|
23
|
+
* Base Contact class (public shape, read-only).
|
|
24
|
+
*/
|
|
25
|
+
export declare class Contact {
|
|
26
|
+
/** @internal Shape persistido. Uso interno (convención underscore). / Internal persisted shape. */
|
|
27
|
+
readonly _raw: IContactRaw;
|
|
28
|
+
/** Chat 1:1 asociado (hidratado). / Associated 1:1 chat (hydrated). */
|
|
29
|
+
readonly chat: Chat;
|
|
30
|
+
constructor(raw: IContactRaw, chat: Chat);
|
|
31
|
+
/** JID único. / Unique JID. */
|
|
32
|
+
get id(): string;
|
|
33
|
+
/** JID (alias). / JID (alias). */
|
|
34
|
+
get jid(): string;
|
|
35
|
+
/** LID si está disponible. / LID when available. */
|
|
36
|
+
get lid(): string | null;
|
|
37
|
+
/** Nombre: local → push → teléfono. / Name: local → push → phone. */
|
|
38
|
+
get name(): string;
|
|
39
|
+
/** Número sin formato. / Raw phone number. */
|
|
40
|
+
get phone(): string;
|
|
41
|
+
/** URL de foto de perfil. / Profile picture URL. */
|
|
42
|
+
get photo(): string | null;
|
|
43
|
+
/** Bio del contacto. / Contact bio. */
|
|
44
|
+
get content(): string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Factoría de Contact ligada al contexto WhatsApp.
|
|
48
|
+
* Context-bound Contact factory.
|
|
49
|
+
*
|
|
50
|
+
* @param wa - Instancia principal / Main WhatsApp instance
|
|
51
|
+
*/
|
|
52
|
+
export declare function contact(wa: WhatsApp): {
|
|
53
|
+
new (raw: IContactRaw, chat: InstanceType<typeof wa.Chat>): {
|
|
54
|
+
/** Chat 1:1 asociado como subclase enriquecida. / Associated 1:1 chat as enriched subclass. */
|
|
55
|
+
readonly chat: InstanceType<typeof wa.Chat>;
|
|
56
|
+
/** true si la instancia representa la cuenta autenticada. / true if this instance is the authenticated account. */
|
|
57
|
+
get me(): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Renombra el contacto localmente (solo agenda del dispositivo).
|
|
60
|
+
* Renames the contact locally (device address book only).
|
|
61
|
+
*/
|
|
62
|
+
rename(name: string): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* Re-hidrata foto y bio desde el socket.
|
|
65
|
+
* Re-hydrates profile picture and bio from the socket.
|
|
66
|
+
*/
|
|
67
|
+
refresh(): Promise</*elided*/ any | null>;
|
|
68
|
+
/** @internal Shape persistido. Uso interno (convención underscore). / Internal persisted shape. */
|
|
69
|
+
readonly _raw: IContactRaw;
|
|
70
|
+
/** JID único. / Unique JID. */
|
|
71
|
+
get id(): string;
|
|
72
|
+
/** JID (alias). / JID (alias). */
|
|
73
|
+
get jid(): string;
|
|
74
|
+
/** LID si está disponible. / LID when available. */
|
|
75
|
+
get lid(): string | null;
|
|
76
|
+
/** Nombre: local → push → teléfono. / Name: local → push → phone. */
|
|
77
|
+
get name(): string;
|
|
78
|
+
/** Número sin formato. / Raw phone number. */
|
|
79
|
+
get phone(): string;
|
|
80
|
+
/** URL de foto de perfil. / Profile picture URL. */
|
|
81
|
+
get photo(): string | null;
|
|
82
|
+
/** Bio del contacto. / Contact bio. */
|
|
83
|
+
get content(): string;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Obtiene un contacto. Dispatch inteligente:
|
|
87
|
+
* - Si `uid` contiene `@` → se interpreta como JID (`@s.whatsapp.net` / `@g.us`) o LID (`@lid`) y se resuelve con el mapping.
|
|
88
|
+
* - Si no contiene `@` → se limpian los dígitos y se consulta `socket.onWhatsApp(phone)` para obtener el JID canónico.
|
|
89
|
+
*
|
|
90
|
+
* Retrieves a contact. Smart dispatch:
|
|
91
|
+
* - If `uid` contains `@` → treated as JID or LID, resolved via mapping.
|
|
92
|
+
* - If `uid` lacks `@` → digits are extracted and `socket.onWhatsApp(phone)` resolves the canonical JID.
|
|
93
|
+
*/
|
|
94
|
+
get(uid: string): Promise<{
|
|
95
|
+
/** Chat 1:1 asociado como subclase enriquecida. / Associated 1:1 chat as enriched subclass. */
|
|
96
|
+
readonly chat: InstanceType<typeof wa.Chat>;
|
|
97
|
+
/** true si la instancia representa la cuenta autenticada. / true if this instance is the authenticated account. */
|
|
98
|
+
get me(): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Renombra el contacto localmente (solo agenda del dispositivo).
|
|
101
|
+
* Renames the contact locally (device address book only).
|
|
102
|
+
*/
|
|
103
|
+
rename(name: string): Promise<boolean>;
|
|
104
|
+
/**
|
|
105
|
+
* Re-hidrata foto y bio desde el socket.
|
|
106
|
+
* Re-hydrates profile picture and bio from the socket.
|
|
107
|
+
*/
|
|
108
|
+
refresh(): Promise</*elided*/ any | null>;
|
|
109
|
+
/** @internal Shape persistido. Uso interno (convención underscore). / Internal persisted shape. */
|
|
110
|
+
readonly _raw: IContactRaw;
|
|
111
|
+
/** JID único. / Unique JID. */
|
|
112
|
+
get id(): string;
|
|
113
|
+
/** JID (alias). / JID (alias). */
|
|
114
|
+
get jid(): string;
|
|
115
|
+
/** LID si está disponible. / LID when available. */
|
|
116
|
+
get lid(): string | null;
|
|
117
|
+
/** Nombre: local → push → teléfono. / Name: local → push → phone. */
|
|
118
|
+
get name(): string;
|
|
119
|
+
/** Número sin formato. / Raw phone number. */
|
|
120
|
+
get phone(): string;
|
|
121
|
+
/** URL de foto de perfil. / Profile picture URL. */
|
|
122
|
+
get photo(): string | null;
|
|
123
|
+
/** Bio del contacto. / Contact bio. */
|
|
124
|
+
get content(): string;
|
|
125
|
+
} | null>;
|
|
126
|
+
/**
|
|
127
|
+
* Pagina los contactos persistidos por mtime DESC, pre-cargando el chat de cada uno.
|
|
128
|
+
* Paginates persisted contacts by mtime DESC, pre-loading the chat of each one.
|
|
129
|
+
*/
|
|
130
|
+
list(offset?: number, limit?: number): Promise<{
|
|
131
|
+
/** Chat 1:1 asociado como subclase enriquecida. / Associated 1:1 chat as enriched subclass. */
|
|
132
|
+
readonly chat: InstanceType<typeof wa.Chat>;
|
|
133
|
+
/** true si la instancia representa la cuenta autenticada. / true if this instance is the authenticated account. */
|
|
134
|
+
get me(): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Renombra el contacto localmente (solo agenda del dispositivo).
|
|
137
|
+
* Renames the contact locally (device address book only).
|
|
138
|
+
*/
|
|
139
|
+
rename(name: string): Promise<boolean>;
|
|
140
|
+
/**
|
|
141
|
+
* Re-hidrata foto y bio desde el socket.
|
|
142
|
+
* Re-hydrates profile picture and bio from the socket.
|
|
143
|
+
*/
|
|
144
|
+
refresh(): Promise</*elided*/ any | null>;
|
|
145
|
+
/** @internal Shape persistido. Uso interno (convención underscore). / Internal persisted shape. */
|
|
146
|
+
readonly _raw: IContactRaw;
|
|
147
|
+
/** JID único. / Unique JID. */
|
|
148
|
+
get id(): string;
|
|
149
|
+
/** JID (alias). / JID (alias). */
|
|
150
|
+
get jid(): string;
|
|
151
|
+
/** LID si está disponible. / LID when available. */
|
|
152
|
+
get lid(): string | null;
|
|
153
|
+
/** Nombre: local → push → teléfono. / Name: local → push → phone. */
|
|
154
|
+
get name(): string;
|
|
155
|
+
/** Número sin formato. / Raw phone number. */
|
|
156
|
+
get phone(): string;
|
|
157
|
+
/** URL de foto de perfil. / Profile picture URL. */
|
|
158
|
+
get photo(): string | null;
|
|
159
|
+
/** Bio del contacto. / Contact bio. */
|
|
160
|
+
get content(): string;
|
|
161
|
+
}[]>;
|
|
162
|
+
/**
|
|
163
|
+
* Renombra localmente un contacto por id.
|
|
164
|
+
* Renames a contact locally by id.
|
|
165
|
+
*/
|
|
166
|
+
rename(uid: string, name: string): Promise<boolean>;
|
|
167
|
+
/**
|
|
168
|
+
* Re-hidrata los datos del contacto por id desde el socket.
|
|
169
|
+
* Re-hydrates contact data from the socket by id.
|
|
170
|
+
*/
|
|
171
|
+
refresh(uid: string): Promise<{
|
|
172
|
+
/** Chat 1:1 asociado como subclase enriquecida. / Associated 1:1 chat as enriched subclass. */
|
|
173
|
+
readonly chat: InstanceType<typeof wa.Chat>;
|
|
174
|
+
/** true si la instancia representa la cuenta autenticada. / true if this instance is the authenticated account. */
|
|
175
|
+
get me(): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Renombra el contacto localmente (solo agenda del dispositivo).
|
|
178
|
+
* Renames the contact locally (device address book only).
|
|
179
|
+
*/
|
|
180
|
+
rename(name: string): Promise<boolean>;
|
|
181
|
+
/**
|
|
182
|
+
* Re-hidrata foto y bio desde el socket.
|
|
183
|
+
* Re-hydrates profile picture and bio from the socket.
|
|
184
|
+
*/
|
|
185
|
+
refresh(): Promise</*elided*/ any | null>;
|
|
186
|
+
/** @internal Shape persistido. Uso interno (convención underscore). / Internal persisted shape. */
|
|
187
|
+
readonly _raw: IContactRaw;
|
|
188
|
+
/** JID único. / Unique JID. */
|
|
189
|
+
get id(): string;
|
|
190
|
+
/** JID (alias). / JID (alias). */
|
|
191
|
+
get jid(): string;
|
|
192
|
+
/** LID si está disponible. / LID when available. */
|
|
193
|
+
get lid(): string | null;
|
|
194
|
+
/** Nombre: local → push → teléfono. / Name: local → push → phone. */
|
|
195
|
+
get name(): string;
|
|
196
|
+
/** Número sin formato. / Raw phone number. */
|
|
197
|
+
get phone(): string;
|
|
198
|
+
/** URL de foto de perfil. / Profile picture URL. */
|
|
199
|
+
get photo(): string | null;
|
|
200
|
+
/** Bio del contacto. / Contact bio. */
|
|
201
|
+
get content(): string;
|
|
202
|
+
} | null>;
|
|
203
|
+
};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file contact/index.ts
|
|
4
|
+
* @description Entidad Contact — lectura/escritura documental sobre `wa.engine`.
|
|
5
|
+
* Contact entity — documental read/write over `wa.engine`.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.Contact = void 0;
|
|
9
|
+
exports.contact = contact;
|
|
10
|
+
const baileys_1 = require("baileys");
|
|
11
|
+
const store_1 = require("../../lib/store");
|
|
12
|
+
/**
|
|
13
|
+
* Clase base del contacto (forma pública, solo lectura).
|
|
14
|
+
* Base Contact class (public shape, read-only).
|
|
15
|
+
*/
|
|
16
|
+
class Contact {
|
|
17
|
+
constructor(raw, chat) {
|
|
18
|
+
this._raw = raw;
|
|
19
|
+
this.chat = chat;
|
|
20
|
+
}
|
|
21
|
+
/** JID único. / Unique JID. */
|
|
22
|
+
get id() {
|
|
23
|
+
return this._raw.id;
|
|
24
|
+
}
|
|
25
|
+
/** JID (alias). / JID (alias). */
|
|
26
|
+
get jid() {
|
|
27
|
+
return this._raw.id;
|
|
28
|
+
}
|
|
29
|
+
/** LID si está disponible. / LID when available. */
|
|
30
|
+
get lid() {
|
|
31
|
+
return this._raw.lid ?? null;
|
|
32
|
+
}
|
|
33
|
+
/** Nombre: local → push → teléfono. / Name: local → push → phone. */
|
|
34
|
+
get name() {
|
|
35
|
+
return this._raw.name ?? this._raw.notify ?? this._raw.id.split('@')[0];
|
|
36
|
+
}
|
|
37
|
+
/** Número sin formato. / Raw phone number. */
|
|
38
|
+
get phone() {
|
|
39
|
+
return this._raw.id.split('@')[0];
|
|
40
|
+
}
|
|
41
|
+
/** URL de foto de perfil. / Profile picture URL. */
|
|
42
|
+
get photo() {
|
|
43
|
+
return this._raw.img_url ?? null;
|
|
44
|
+
}
|
|
45
|
+
/** Bio del contacto. / Contact bio. */
|
|
46
|
+
get content() {
|
|
47
|
+
return this._raw.status ?? '';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.Contact = Contact;
|
|
51
|
+
/**
|
|
52
|
+
* Factoría de Contact ligada al contexto WhatsApp.
|
|
53
|
+
* Context-bound Contact factory.
|
|
54
|
+
*
|
|
55
|
+
* @param wa - Instancia principal / Main WhatsApp instance
|
|
56
|
+
*/
|
|
57
|
+
function contact(wa) {
|
|
58
|
+
/**
|
|
59
|
+
* Descubre el JID canónico y el LID (cuando aplica) de un número consultando al socket.
|
|
60
|
+
* Discovers the canonical JID and LID (when applicable) of a phone number via the socket.
|
|
61
|
+
*/
|
|
62
|
+
async function discover_by_phone(phone) {
|
|
63
|
+
let result = null;
|
|
64
|
+
if (wa._socket && phone.length > 0) {
|
|
65
|
+
const found = (await wa._socket.onWhatsApp(phone))?.[0];
|
|
66
|
+
if (found?.exists) {
|
|
67
|
+
result = { jid: (0, baileys_1.jidNormalizedUser)(found.jid), lid: found.lid ?? null };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Obtiene foto y bio del contacto desde el socket.
|
|
74
|
+
* Fetches profile picture and bio from the socket.
|
|
75
|
+
*/
|
|
76
|
+
async function fetch_profile_data(id) {
|
|
77
|
+
let img_url = null;
|
|
78
|
+
let status = null;
|
|
79
|
+
if (wa._socket) {
|
|
80
|
+
try {
|
|
81
|
+
img_url = (await wa._socket.profilePictureUrl(id, 'image')) ?? null;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
/* may not exist */
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
const result = await wa._socket.fetchStatus(id);
|
|
88
|
+
const data = result?.[0];
|
|
89
|
+
status = data?.status?.status ?? null;
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
/* may fail */
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { img_url, status };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Carga la instancia Chat 1:1 del contacto. Si no existe en engine, fabrica una mínima.
|
|
99
|
+
* Loads the 1:1 Chat instance for a contact. Falls back to a minimal instance if missing.
|
|
100
|
+
*/
|
|
101
|
+
async function load_chat_for(jid, fallback_name) {
|
|
102
|
+
const cached = (0, store_1.deserialize)(await wa.engine.get(`/chat/${jid}`));
|
|
103
|
+
return new wa.Chat(cached ?? { id: jid, name: fallback_name });
|
|
104
|
+
}
|
|
105
|
+
return class _Contact extends Contact {
|
|
106
|
+
constructor(raw, chat) {
|
|
107
|
+
super(raw, chat);
|
|
108
|
+
}
|
|
109
|
+
/** true si la instancia representa la cuenta autenticada. / true if this instance is the authenticated account. */
|
|
110
|
+
get me() {
|
|
111
|
+
const self_id = wa._socket?.user?.id;
|
|
112
|
+
return Boolean(self_id) && (0, baileys_1.jidNormalizedUser)(self_id) === this.id;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Obtiene un contacto. Dispatch inteligente:
|
|
116
|
+
* - Si `uid` contiene `@` → se interpreta como JID (`@s.whatsapp.net` / `@g.us`) o LID (`@lid`) y se resuelve con el mapping.
|
|
117
|
+
* - Si no contiene `@` → se limpian los dígitos y se consulta `socket.onWhatsApp(phone)` para obtener el JID canónico.
|
|
118
|
+
*
|
|
119
|
+
* Retrieves a contact. Smart dispatch:
|
|
120
|
+
* - If `uid` contains `@` → treated as JID or LID, resolved via mapping.
|
|
121
|
+
* - If `uid` lacks `@` → digits are extracted and `socket.onWhatsApp(phone)` resolves the canonical JID.
|
|
122
|
+
*/
|
|
123
|
+
static async get(uid) {
|
|
124
|
+
let result = null;
|
|
125
|
+
let jid = null;
|
|
126
|
+
let lid = null;
|
|
127
|
+
if (uid.includes('@')) {
|
|
128
|
+
jid = await wa._resolve_jid(uid);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
const discovered = await discover_by_phone(uid.replace(/\D+/g, ''));
|
|
132
|
+
if (discovered) {
|
|
133
|
+
jid = discovered.jid;
|
|
134
|
+
lid = discovered.lid;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (jid && !jid.endsWith('@g.us')) {
|
|
138
|
+
const cached = (0, store_1.deserialize)(await wa.engine.get(`/contact/${jid}`));
|
|
139
|
+
if (cached) {
|
|
140
|
+
const fallback_name = cached.name ?? cached.notify ?? jid.split('@')[0];
|
|
141
|
+
result = new _Contact(cached, await load_chat_for(jid, fallback_name));
|
|
142
|
+
}
|
|
143
|
+
else if (wa._socket) {
|
|
144
|
+
const needs_check = !lid && !uid.endsWith('@lid');
|
|
145
|
+
const discovered = needs_check
|
|
146
|
+
? await discover_by_phone(jid.split('@')[0])
|
|
147
|
+
: { jid, lid };
|
|
148
|
+
if (discovered) {
|
|
149
|
+
const { img_url, status } = await fetch_profile_data(discovered.jid);
|
|
150
|
+
const raw = {
|
|
151
|
+
id: discovered.jid,
|
|
152
|
+
lid: discovered.lid,
|
|
153
|
+
name: null,
|
|
154
|
+
notify: null,
|
|
155
|
+
verified_name: null,
|
|
156
|
+
img_url,
|
|
157
|
+
status,
|
|
158
|
+
};
|
|
159
|
+
await wa.engine.set(`/contact/${discovered.jid}`, (0, store_1.serialize)(raw));
|
|
160
|
+
if (discovered.lid) {
|
|
161
|
+
await wa.engine.set(`/lid/${discovered.lid}`, (0, store_1.serialize)(discovered.jid));
|
|
162
|
+
}
|
|
163
|
+
result = new _Contact(raw, await load_chat_for(discovered.jid, discovered.jid.split('@')[0]));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Pagina los contactos persistidos por mtime DESC, pre-cargando el chat de cada uno.
|
|
171
|
+
* Paginates persisted contacts by mtime DESC, pre-loading the chat of each one.
|
|
172
|
+
*/
|
|
173
|
+
static async list(offset = 0, limit = 50) {
|
|
174
|
+
const contacts = [];
|
|
175
|
+
for (const raw of await wa.engine.list('/contact', offset, limit)) {
|
|
176
|
+
const parsed = (0, store_1.deserialize)(raw);
|
|
177
|
+
if (parsed) {
|
|
178
|
+
const fallback_name = parsed.name ?? parsed.notify ?? parsed.id.split('@')[0];
|
|
179
|
+
contacts.push(new _Contact(parsed, await load_chat_for(parsed.id, fallback_name)));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return contacts;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Renombra localmente un contacto por id.
|
|
186
|
+
* Renames a contact locally by id.
|
|
187
|
+
*/
|
|
188
|
+
static async rename(uid, name) {
|
|
189
|
+
const c = await _Contact.get(uid);
|
|
190
|
+
return c ? c.rename(name) : false;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Re-hidrata los datos del contacto por id desde el socket.
|
|
194
|
+
* Re-hydrates contact data from the socket by id.
|
|
195
|
+
*/
|
|
196
|
+
static async refresh(uid) {
|
|
197
|
+
const c = await _Contact.get(uid);
|
|
198
|
+
return c ? c.refresh() : null;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Renombra el contacto localmente (solo agenda del dispositivo).
|
|
202
|
+
* Renames the contact locally (device address book only).
|
|
203
|
+
*/
|
|
204
|
+
async rename(name) {
|
|
205
|
+
this._raw.name = name;
|
|
206
|
+
await wa.engine.set(`/contact/${this.id}`, (0, store_1.serialize)(this._raw));
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Re-hidrata foto y bio desde el socket.
|
|
211
|
+
* Re-hydrates profile picture and bio from the socket.
|
|
212
|
+
*/
|
|
213
|
+
async refresh() {
|
|
214
|
+
let ok = false;
|
|
215
|
+
if (wa._socket) {
|
|
216
|
+
const { img_url, status } = await fetch_profile_data(this.id);
|
|
217
|
+
this._raw.img_url = img_url;
|
|
218
|
+
this._raw.status = status;
|
|
219
|
+
await wa.engine.set(`/contact/${this.id}`, (0, store_1.serialize)(this._raw));
|
|
220
|
+
ok = true;
|
|
221
|
+
}
|
|
222
|
+
return ok ? this : null;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/contact/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAwEH,0BA+LC;AArQD,qCAA4C;AAE5C,uCAAqD;AAiBrD;;;GAGG;AACH,MAAa,OAAO;IAMlB,YAAY,GAAgB,EAAE,IAAU;QACtC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAChB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,+BAA+B;IAC/B,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IACtB,CAAC;IACD,kCAAkC;IAClC,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IACtB,CAA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