@arcaelas/whatsapp 1.2.3 → 2.0.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 (78) hide show
  1. package/build/cjs/Chat.d.ts +317 -0
  2. package/build/cjs/Chat.js +273 -0
  3. package/build/cjs/Chat.js.map +1 -0
  4. package/build/{Contact.d.ts → cjs/Contact.d.ts} +317 -304
  5. package/build/cjs/Contact.js +144 -0
  6. package/build/cjs/Contact.js.map +1 -0
  7. package/build/cjs/Message.d.ts +882 -0
  8. package/build/cjs/Message.js +483 -0
  9. package/build/cjs/Message.js.map +1 -0
  10. package/build/{WhatsApp.d.ts → cjs/WhatsApp.d.ts} +16 -4
  11. package/build/{WhatsApp.js → cjs/WhatsApp.js} +84 -81
  12. package/build/cjs/WhatsApp.js.map +1 -0
  13. package/build/{index.d.ts → cjs/index.d.ts} +2 -2
  14. package/build/cjs/index.js +17 -0
  15. package/build/cjs/index.js.map +1 -0
  16. package/build/cjs/package.json +1 -0
  17. package/build/cjs/store/driver/FileEngine.d.ts +34 -0
  18. package/build/{store → cjs/store}/driver/FileEngine.js +16 -20
  19. package/build/cjs/store/driver/FileEngine.js.map +1 -0
  20. package/build/{store → cjs/store}/driver/RedisEngine.d.ts +14 -5
  21. package/build/{store → cjs/store}/driver/RedisEngine.js +23 -22
  22. package/build/cjs/store/driver/RedisEngine.js.map +1 -0
  23. package/build/{store → cjs/store}/engine.d.ts +9 -10
  24. package/build/cjs/store/engine.js.map +1 -0
  25. package/build/cjs/store/index.d.ts +8 -0
  26. package/build/{store → cjs/store}/index.js +2 -2
  27. package/build/cjs/store/index.js.map +1 -0
  28. package/build/esm/Chat.d.ts +317 -0
  29. package/build/esm/Chat.js +268 -0
  30. package/build/esm/Chat.js.map +1 -0
  31. package/build/esm/Contact.d.ts +869 -0
  32. package/build/esm/Contact.js +139 -0
  33. package/build/esm/Contact.js.map +1 -0
  34. package/build/esm/Message.d.ts +882 -0
  35. package/build/esm/Message.js +478 -0
  36. package/build/esm/Message.js.map +1 -0
  37. package/build/esm/WhatsApp.d.ts +80 -0
  38. package/build/esm/WhatsApp.js +362 -0
  39. package/build/esm/WhatsApp.js.map +1 -0
  40. package/build/esm/index.d.ts +13 -0
  41. package/build/esm/index.js +10 -0
  42. package/build/esm/index.js.map +1 -0
  43. package/build/esm/package.json +1 -0
  44. package/build/esm/store/driver/FileEngine.d.ts +34 -0
  45. package/build/esm/store/driver/FileEngine.js +82 -0
  46. package/build/esm/store/driver/FileEngine.js.map +1 -0
  47. package/build/esm/store/driver/RedisEngine.d.ts +47 -0
  48. package/build/esm/store/driver/RedisEngine.js +66 -0
  49. package/build/esm/store/driver/RedisEngine.js.map +1 -0
  50. package/build/esm/store/engine.d.ts +53 -0
  51. package/build/esm/store/engine.js +6 -0
  52. package/build/{store → esm/store}/engine.js.map +1 -1
  53. package/build/esm/store/index.d.ts +8 -0
  54. package/build/esm/store/index.js +7 -0
  55. package/build/esm/store/index.js.map +1 -0
  56. package/package.json +70 -58
  57. package/API.md +0 -776
  58. package/CHANGELOG.md +0 -53
  59. package/DOC.md +0 -532
  60. package/build/Chat.d.ts +0 -335
  61. package/build/Chat.js +0 -396
  62. package/build/Chat.js.map +0 -1
  63. package/build/Contact.js +0 -188
  64. package/build/Contact.js.map +0 -1
  65. package/build/Message.d.ts +0 -580
  66. package/build/Message.js +0 -463
  67. package/build/Message.js.map +0 -1
  68. package/build/WhatsApp.js.map +0 -1
  69. package/build/index.js +0 -2
  70. package/build/index.js.map +0 -7
  71. package/build/store/driver/FileEngine.d.ts +0 -23
  72. package/build/store/driver/FileEngine.js.map +0 -1
  73. package/build/store/driver/RedisEngine.js.map +0 -1
  74. package/build/store/index.d.ts +0 -8
  75. package/build/store/index.js.map +0 -1
  76. package/context7.json +0 -4
  77. package/tsconfig.json +0 -27
  78. /package/build/{store → cjs/store}/engine.js +0 -0
@@ -0,0 +1,139 @@
1
+ /**
2
+ * @file Contact.ts
3
+ * @description Clase Contact para gestión de contactos de WhatsApp
4
+ */
5
+ import { BufferJSON, jidNormalizedUser } from 'baileys';
6
+ /**
7
+ * @description Construye IContactRaw normalizado.
8
+ * Builds a normalized IContactRaw.
9
+ */
10
+ function build_contact(raw) {
11
+ return {
12
+ id: raw.id,
13
+ lid: raw.lid ?? null,
14
+ name: raw.name ?? null,
15
+ notify: raw.notify ?? null,
16
+ verifiedName: raw.verifiedName ?? null,
17
+ imgUrl: raw.imgUrl ?? null,
18
+ status: raw.status ?? null,
19
+ };
20
+ }
21
+ /**
22
+ * @description
23
+ * Clase base para representar un contacto de WhatsApp.
24
+ * Base class representing a WhatsApp contact.
25
+ */
26
+ export class Contact {
27
+ constructor(raw) {
28
+ this.raw = raw;
29
+ }
30
+ /** JID único del contacto / Unique contact JID */
31
+ get id() { return this.raw.id; }
32
+ /** Nombre del contacto / Contact name */
33
+ get name() { return this.raw.name ?? this.raw.notify ?? this.raw.id.split('@')[0]; }
34
+ /** URL de la foto de perfil o null / Profile picture URL or null */
35
+ get photo() { return this.raw.imgUrl ?? null; }
36
+ /** Número de teléfono sin formato / Phone number without format */
37
+ get phone() { return this.raw.id.split('@')[0]; }
38
+ /** Bio del contacto / Contact bio */
39
+ get content() { return this.raw.status ?? ''; }
40
+ }
41
+ /**
42
+ * @description Factory que retorna la clase Contact enlazada al contexto.
43
+ * Factory that returns the Contact class bound to context.
44
+ * @param wa Instancia de WhatsApp.
45
+ */
46
+ export function contact(wa) {
47
+ return class _Contact extends Contact {
48
+ /**
49
+ * @description Obtiene un contacto por su ID.
50
+ * Retrieves a contact by its ID.
51
+ * @param uid JID del contacto o número de teléfono.
52
+ */
53
+ static async get(uid) {
54
+ const jid = await wa.resolveJID(uid);
55
+ if (!jid)
56
+ return null;
57
+ const stored = await wa.engine.get(`contact/${jid}/index`);
58
+ if (stored)
59
+ return new _Contact(JSON.parse(stored, BufferJSON.reviver));
60
+ if (!wa.socket)
61
+ return null;
62
+ const found = (await wa.socket.onWhatsApp(jid.split('@')[0]))?.[0];
63
+ if (!found?.exists)
64
+ return null;
65
+ const id = jidNormalizedUser(found.jid);
66
+ const raw = { id, name: null, notify: null, imgUrl: null, status: null };
67
+ try {
68
+ raw.imgUrl = (await wa.socket.profilePictureUrl(id, 'image')) ?? null;
69
+ }
70
+ catch { /* profile picture may not exist */ }
71
+ try {
72
+ const result = await wa.socket.fetchStatus(id);
73
+ const status_data = result?.[0];
74
+ raw.status = status_data?.status?.status ?? null;
75
+ }
76
+ catch { /* status fetch may fail */ }
77
+ const data = build_contact(raw);
78
+ await wa.engine.set(`contact/${id}/index`, JSON.stringify(data, BufferJSON.replacer));
79
+ return new _Contact(data);
80
+ }
81
+ /**
82
+ * @description Obtiene contactos paginados.
83
+ * Retrieves paginated contacts.
84
+ * @param offset Inicio de paginación.
85
+ * @param limit Cantidad máxima de resultados.
86
+ */
87
+ static async list(offset = 0, limit = 50) {
88
+ const contacts = [];
89
+ for (const key of await wa.engine.list('contact/', offset, limit)) {
90
+ const stored = await wa.engine.get(key);
91
+ if (stored)
92
+ contacts.push(new _Contact(JSON.parse(stored, BufferJSON.reviver)));
93
+ }
94
+ return contacts;
95
+ }
96
+ /**
97
+ * @description Cambia el nombre del contacto.
98
+ * Renames the contact.
99
+ * @param name Nuevo nombre.
100
+ */
101
+ async rename(name) {
102
+ const stored = await wa.engine.get(`contact/${this.id}/index`);
103
+ if (stored) {
104
+ this.raw.name = name;
105
+ await wa.engine.set(`contact/${this.id}/index`, JSON.stringify(this.raw, BufferJSON.replacer));
106
+ return true;
107
+ }
108
+ return false;
109
+ }
110
+ /**
111
+ * @description Actualiza los datos del perfil desde WhatsApp.
112
+ * Refreshes profile data from WhatsApp.
113
+ */
114
+ async refresh() {
115
+ if (!wa.socket)
116
+ return null;
117
+ try {
118
+ this.raw.imgUrl = (await wa.socket.profilePictureUrl(this.id, 'image')) ?? null;
119
+ }
120
+ catch { /* profile picture may not exist */ }
121
+ try {
122
+ const result = await wa.socket.fetchStatus(this.id);
123
+ const status_data = result?.[0];
124
+ this.raw.status = status_data?.status?.status ?? null;
125
+ }
126
+ catch { /* status fetch may fail */ }
127
+ await wa.engine.set(`contact/${this.id}/index`, JSON.stringify(this.raw, BufferJSON.replacer));
128
+ return this;
129
+ }
130
+ /**
131
+ * @description Obtiene o crea el chat con este contacto.
132
+ * Gets or creates the chat with this contact.
133
+ */
134
+ async chat() {
135
+ return wa.Chat.get(this.id);
136
+ }
137
+ };
138
+ }
139
+ //# sourceMappingURL=Contact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Contact.js","sourceRoot":"","sources":["../../src/Contact.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAwBxD;;;GAGG;AACH,SAAS,aAAa,CAAC,GAAgB;IACnC,OAAO;QACH,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,IAAI;QACpB,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,IAAI;QACtB,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,IAAI;QAC1B,YAAY,EAAE,GAAG,CAAC,YAAY,IAAI,IAAI;QACtC,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,IAAI;QAC1B,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,IAAI;KAC7B,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,OAAO;IAChB,YAAqB,GAAgB;QAAhB,QAAG,GAAH,GAAG,CAAa;IAAI,CAAC;IAE1C,kDAAkD;IAClD,IAAI,EAAE,KAAa,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IACxC,yCAAyC;IACzC,IAAI,IAAI,KAAa,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,G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