@prototypevip/baileys 0.0.1

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 (118) hide show
  1. package/LICENSE +23 -0
  2. package/WAProto/index.js +131118 -0
  3. package/engine-requirements.js +1 -0
  4. package/lib/Defaults/index.js +187 -0
  5. package/lib/Signal/Group/ciphertext-message.js +11 -0
  6. package/lib/Signal/Group/group-session-builder.js +41 -0
  7. package/lib/Signal/Group/group_cipher.js +108 -0
  8. package/lib/Signal/Group/index.js +11 -0
  9. package/lib/Signal/Group/keyhelper.js +14 -0
  10. package/lib/Signal/Group/sender-chain-key.js +31 -0
  11. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  12. package/lib/Signal/Group/sender-key-message.js +79 -0
  13. package/lib/Signal/Group/sender-key-name.js +49 -0
  14. package/lib/Signal/Group/sender-key-record.js +46 -0
  15. package/lib/Signal/Group/sender-key-state.js +104 -0
  16. package/lib/Signal/Group/sender-message-key.js +29 -0
  17. package/lib/Signal/libsignal.js +532 -0
  18. package/lib/Signal/lid-mapping.js +312 -0
  19. package/lib/Socket/Client/index.js +2 -0
  20. package/lib/Socket/Client/types.js +10 -0
  21. package/lib/Socket/Client/websocket.js +64 -0
  22. package/lib/Socket/business.js +293 -0
  23. package/lib/Socket/chats.js +1124 -0
  24. package/lib/Socket/communities.js +528 -0
  25. package/lib/Socket/groups.js +465 -0
  26. package/lib/Socket/index.js +14 -0
  27. package/lib/Socket/messages-recv.js +2325 -0
  28. package/lib/Socket/messages-send.js +1746 -0
  29. package/lib/Socket/mex.js +55 -0
  30. package/lib/Socket/newsletter.js +317 -0
  31. package/lib/Socket/socket.js +1185 -0
  32. package/lib/Store/cache-factory.js +20 -0
  33. package/lib/Store/index.js +5 -0
  34. package/lib/Store/make-in-memory-store.js +523 -0
  35. package/lib/Store/make-ordered-dictionary.js +203 -0
  36. package/lib/Store/object-repository.js +23 -0
  37. package/lib/Store/prototype-store.js +958 -0
  38. package/lib/Types/Auth.js +1 -0
  39. package/lib/Types/Bussines.js +1 -0
  40. package/lib/Types/Call.js +1 -0
  41. package/lib/Types/Chat.js +7 -0
  42. package/lib/Types/Contact.js +1 -0
  43. package/lib/Types/Events.js +1 -0
  44. package/lib/Types/GroupMetadata.js +1 -0
  45. package/lib/Types/Label.js +24 -0
  46. package/lib/Types/LabelAssociation.js +6 -0
  47. package/lib/Types/Message.js +18 -0
  48. package/lib/Types/Mex.js +37 -0
  49. package/lib/Types/Newsletter.js +36 -0
  50. package/lib/Types/Product.js +1 -0
  51. package/lib/Types/RichType.js +25 -0
  52. package/lib/Types/Signal.js +1 -0
  53. package/lib/Types/Socket.js +2 -0
  54. package/lib/Types/State.js +78 -0
  55. package/lib/Types/USync.js +1 -0
  56. package/lib/Types/index.js +33 -0
  57. package/lib/Utils/auth-utils.js +303 -0
  58. package/lib/Utils/browser-utils.js +32 -0
  59. package/lib/Utils/business.js +245 -0
  60. package/lib/Utils/chat-utils.js +971 -0
  61. package/lib/Utils/companion-reg-client-utils.js +54 -0
  62. package/lib/Utils/constants.js +24 -0
  63. package/lib/Utils/crypto.js +133 -0
  64. package/lib/Utils/cstoken-utils.js +41 -0
  65. package/lib/Utils/decode-wa-message.js +406 -0
  66. package/lib/Utils/event-buffer.js +616 -0
  67. package/lib/Utils/generics.js +438 -0
  68. package/lib/Utils/history.js +147 -0
  69. package/lib/Utils/identity-change-handler.js +63 -0
  70. package/lib/Utils/index.js +29 -0
  71. package/lib/Utils/interactive-message-handler.js +478 -0
  72. package/lib/Utils/link-preview.js +91 -0
  73. package/lib/Utils/logger.js +2 -0
  74. package/lib/Utils/lt-hash.js +6 -0
  75. package/lib/Utils/make-mutex.js +31 -0
  76. package/lib/Utils/message-retry-manager.js +291 -0
  77. package/lib/Utils/messages-media.js +881 -0
  78. package/lib/Utils/messages.js +1434 -0
  79. package/lib/Utils/noise-handler.js +229 -0
  80. package/lib/Utils/normalize-message-identity.js +73 -0
  81. package/lib/Utils/offline-node-processor.js +50 -0
  82. package/lib/Utils/pre-key-manager.js +119 -0
  83. package/lib/Utils/process-message.js +648 -0
  84. package/lib/Utils/reporting-utils.js +355 -0
  85. package/lib/Utils/rich-message-utils.js +264 -0
  86. package/lib/Utils/signal.js +233 -0
  87. package/lib/Utils/stanza-ack.js +33 -0
  88. package/lib/Utils/sticker-utils.js +221 -0
  89. package/lib/Utils/sync-action-utils.js +53 -0
  90. package/lib/Utils/tc-token-utils.js +182 -0
  91. package/lib/Utils/use-multi-file-auth-state.js +118 -0
  92. package/lib/Utils/use-prototype-auth-state.js +217 -0
  93. package/lib/Utils/use-single-file-auth-state.js +94 -0
  94. package/lib/Utils/validate-connection.js +235 -0
  95. package/lib/WABinary/constants.js +1468 -0
  96. package/lib/WABinary/decode.js +258 -0
  97. package/lib/WABinary/encode.js +219 -0
  98. package/lib/WABinary/generic-utils.js +202 -0
  99. package/lib/WABinary/index.js +5 -0
  100. package/lib/WABinary/jid-utils.js +94 -0
  101. package/lib/WABinary/types.js +1 -0
  102. package/lib/WAM/BinaryInfo.js +9 -0
  103. package/lib/WAM/constants.js +20669 -0
  104. package/lib/WAM/encode.js +151 -0
  105. package/lib/WAM/index.js +3 -0
  106. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -0
  107. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +59 -0
  108. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -0
  109. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +29 -0
  110. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  111. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +59 -0
  112. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +21 -0
  113. package/lib/WAUSync/Protocols/index.js +4 -0
  114. package/lib/WAUSync/USyncQuery.js +133 -0
  115. package/lib/WAUSync/USyncUser.js +22 -0
  116. package/lib/WAUSync/index.js +3 -0
  117. package/lib/index.js +12 -0
  118. package/package.json +78 -0
@@ -0,0 +1,465 @@
1
+ import { proto } from "../../WAProto/index.js";
2
+ import { WAMessageAddressingMode, WAMessageStubType } from "../Types/index.js";
3
+ import { generateMessageIDV2, unixTimestampSeconds } from "../Utils/index.js";
4
+ import {
5
+ getBinaryNodeChild,
6
+ getBinaryNodeChildren,
7
+ getBinaryNodeChildString,
8
+ isLidUser,
9
+ isPnUser,
10
+ jidEncode,
11
+ jidNormalizedUser,
12
+ } from "../WABinary/index.js";
13
+ import { makeChatsSocket } from "./chats.js";
14
+ import { groupMetadataCache as defaultCache } from "../Store/cache-factory.js";
15
+
16
+ export const makeGroupsSocket = (config) => {
17
+ const cache = config.groupMetadataCache || defaultCache;
18
+
19
+ const sock = makeChatsSocket(config);
20
+ const { authState, ev, query, upsertMessage } = sock;
21
+ const groupQuery = async (jid, type, content) =>
22
+ query({
23
+ tag: "iq",
24
+ attrs: { type: type, xmlns: "w:g2", to: jid },
25
+ content: content,
26
+ });
27
+ const groupMetadata = async (jid, useCache = true) => {
28
+ if (useCache) {
29
+ const cached = cache.get(jid) || config.store?.groups[jid];
30
+ if (cached && Array.isArray(cached.participants)) {
31
+ return cached;
32
+ }
33
+ }
34
+ const result = await groupQuery(jid, "get", [
35
+ { tag: "query", attrs: { request: "interactive" } },
36
+ ]);
37
+ const metadata = extractGroupMetadata(result);
38
+ cache.set(jid, metadata);
39
+ if (config.store && config.store.groups) {
40
+ config.store.groups[jid] = metadata;
41
+ }
42
+ return metadata;
43
+ };
44
+ const groupFetchAllParticipating = async () => {
45
+ const result = await query({
46
+ tag: "iq",
47
+ attrs: { to: "@g.us", xmlns: "w:g2", type: "get" },
48
+ content: [
49
+ {
50
+ tag: "participating",
51
+ attrs: {},
52
+ content: [
53
+ { tag: "participants", attrs: {} },
54
+ { tag: "description", attrs: {} },
55
+ ],
56
+ },
57
+ ],
58
+ });
59
+ const data = Object.create(null);
60
+ const groupsChild = getBinaryNodeChild(result, "groups");
61
+ if (groupsChild) {
62
+ const groups = getBinaryNodeChildren(groupsChild, "group");
63
+ for (const groupNode of groups) {
64
+ const meta = extractGroupMetadata({
65
+ tag: "result",
66
+ attrs: {},
67
+ content: [groupNode],
68
+ });
69
+ data[meta.id] = meta;
70
+ cache.set(meta.id, meta);
71
+ if (config.store && config.store.groups) {
72
+ config.store.groups[meta.id] = meta;
73
+ }
74
+ const lidMappings = meta.participants
75
+ .filter((p) => p.lid && p.pn)
76
+ .map((p) => ({ lid: p.lid, pn: p.pn }));
77
+ if (lidMappings.length > 0) {
78
+ await sock.signalRepository.lidMapping.storeLIDPNMappings(
79
+ lidMappings,
80
+ );
81
+ }
82
+ }
83
+ }
84
+ sock.ev.emit("groups.update", Object.values(data));
85
+ return data;
86
+ };
87
+ sock.ws.on("CB:ib,,dirty", async (node) => {
88
+ const { attrs } = getBinaryNodeChild(node, "dirty");
89
+ if (attrs.type !== "groups") {
90
+ return;
91
+ }
92
+ await groupFetchAllParticipating();
93
+ await sock.cleanDirtyBits("groups");
94
+ });
95
+ return {
96
+ ...sock,
97
+ extractGroupMetadata: extractGroupMetadata,
98
+ groupMetadata: groupMetadata,
99
+ groupCreate: async (subject, participants) => {
100
+ const key = generateMessageIDV2();
101
+ const result = await groupQuery("@g.us", "set", [
102
+ {
103
+ tag: "create",
104
+ attrs: { subject: subject, key: key },
105
+ content: participants.map((jid) => ({
106
+ tag: "participant",
107
+ attrs: { jid: jid },
108
+ })),
109
+ },
110
+ ]);
111
+ return extractGroupMetadata(result);
112
+ },
113
+ groupLeave: async (id) => {
114
+ await groupQuery("@g.us", "set", [
115
+ {
116
+ tag: "leave",
117
+ attrs: {},
118
+ content: [{ tag: "group", attrs: { id: id } }],
119
+ },
120
+ ]);
121
+ },
122
+ groupUpdateSubject: async (jid, subject) => {
123
+ await groupQuery(jid, "set", [
124
+ {
125
+ tag: "subject",
126
+ attrs: {},
127
+ content: Buffer.from(subject, "utf-8"),
128
+ },
129
+ ]);
130
+ cache.del(jid);
131
+ if (config.store && config.store.groups) {
132
+ delete config.store.groups[jid];
133
+ }
134
+ },
135
+ groupRequestParticipantsList: async (jid) => {
136
+ const result = await groupQuery(jid, "get", [
137
+ { tag: "membership_approval_requests", attrs: {} },
138
+ ]);
139
+ const node = getBinaryNodeChild(result, "membership_approval_requests");
140
+ const participants = getBinaryNodeChildren(
141
+ node,
142
+ "membership_approval_request",
143
+ );
144
+ return participants.map((v) => v.attrs);
145
+ },
146
+ groupRequestParticipantsUpdate: async (jid, participants, action) => {
147
+ const result = await groupQuery(jid, "set", [
148
+ {
149
+ tag: "membership_requests_action",
150
+ attrs: {},
151
+ content: [
152
+ {
153
+ tag: action,
154
+ attrs: {},
155
+ content: participants.map((jid) => ({
156
+ tag: "participant",
157
+ attrs: { jid: jid },
158
+ })),
159
+ },
160
+ ],
161
+ },
162
+ ]);
163
+ const node = getBinaryNodeChild(result, "membership_requests_action");
164
+ const nodeAction = getBinaryNodeChild(node, action);
165
+ const participantsAffected = getBinaryNodeChildren(
166
+ nodeAction,
167
+ "participant",
168
+ );
169
+ return participantsAffected.map((p) => {
170
+ return { status: p.attrs.error || "200", jid: p.attrs.jid };
171
+ });
172
+ },
173
+ groupParticipantsUpdate: async (jid, participants, action) => {
174
+ // PN-First API: Translate PN to LID only if the group's addressingMode requires it
175
+ const metadata = await groupMetadata(jid);
176
+ if (
177
+ metadata &&
178
+ metadata.addressingMode === "lid" &&
179
+ sock.signalRepository &&
180
+ sock.signalRepository.lidMapping
181
+ ) {
182
+ const resolvedParticipants = [];
183
+ for (const p of participants) {
184
+ if (p.includes("@s.whatsapp.net")) {
185
+ try {
186
+ let lid = await sock.signalRepository.lidMapping.getLIDForPN(p);
187
+ if (!lid && sock.onWhatsApp) {
188
+ await sock.onWhatsApp(p);
189
+ lid = await sock.signalRepository.lidMapping.getLIDForPN(p);
190
+ }
191
+ resolvedParticipants.push(lid || p);
192
+ } catch (e) {
193
+ resolvedParticipants.push(p);
194
+ }
195
+ } else {
196
+ resolvedParticipants.push(p);
197
+ }
198
+ }
199
+ participants = resolvedParticipants;
200
+ }
201
+
202
+ const result = await groupQuery(jid, "set", [
203
+ {
204
+ tag: action,
205
+ attrs: {},
206
+ content: participants.map((jid) => ({
207
+ tag: "participant",
208
+ attrs: { jid: jid },
209
+ })),
210
+ },
211
+ ]);
212
+ const node = getBinaryNodeChild(result, action);
213
+ const participantsAffected = getBinaryNodeChildren(node, "participant");
214
+ return participantsAffected.map((p) => {
215
+ return {
216
+ status: p.attrs.error || "200",
217
+ jid: p.attrs.jid,
218
+ content: p,
219
+ };
220
+ });
221
+ },
222
+ groupUpdateDescription: async (jid, description) => {
223
+ const metadata = await groupMetadata(jid);
224
+ const prev = metadata.descId ?? null;
225
+ await groupQuery(jid, "set", [
226
+ {
227
+ tag: "description",
228
+ attrs: {
229
+ ...(description
230
+ ? { id: generateMessageIDV2() }
231
+ : { delete: "true" }),
232
+ ...(prev ? { prev: prev } : {}),
233
+ },
234
+ content: description
235
+ ? [
236
+ {
237
+ tag: "body",
238
+ attrs: {},
239
+ content: Buffer.from(description, "utf-8"),
240
+ },
241
+ ]
242
+ : undefined,
243
+ },
244
+ ]);
245
+ cache.del(jid);
246
+ if (config.store && config.store.groups) {
247
+ delete config.store.groups[jid];
248
+ }
249
+ },
250
+ groupInviteCode: async (jid) => {
251
+ const result = await groupQuery(jid, "get", [
252
+ { tag: "invite", attrs: {} },
253
+ ]);
254
+ const inviteNode = getBinaryNodeChild(result, "invite");
255
+ return inviteNode?.attrs.code;
256
+ },
257
+ groupRevokeInvite: async (jid) => {
258
+ const result = await groupQuery(jid, "set", [
259
+ { tag: "invite", attrs: {} },
260
+ ]);
261
+ const inviteNode = getBinaryNodeChild(result, "invite");
262
+ return inviteNode?.attrs.code;
263
+ },
264
+ groupAcceptInvite: async (code) => {
265
+ const results = await groupQuery("@g.us", "set", [
266
+ { tag: "invite", attrs: { code: code } },
267
+ ]);
268
+ const result = getBinaryNodeChild(results, "group");
269
+ return result?.attrs.jid;
270
+ },
271
+ /**
272
+ * revoke a v4 invite for someone
273
+ * @param groupJid group jid
274
+ * @param invitedJid jid of person you invited
275
+ * @returns true if successful
276
+ */
277
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
278
+ const result = await groupQuery(groupJid, "set", [
279
+ {
280
+ tag: "revoke",
281
+ attrs: {},
282
+ content: [{ tag: "participant", attrs: { jid: invitedJid } }],
283
+ },
284
+ ]);
285
+ return !!result;
286
+ },
287
+ /**
288
+ * accept a GroupInviteMessage
289
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
290
+ * @param inviteMessage the message to accept
291
+ */
292
+ groupAcceptInviteV4: ev.createBufferedFunction(
293
+ async (key, inviteMessage) => {
294
+ key = typeof key === "string" ? { remoteJid: key } : key;
295
+ const results = await groupQuery(inviteMessage.groupJid, "set", [
296
+ {
297
+ tag: "accept",
298
+ attrs: {
299
+ code: inviteMessage.inviteCode,
300
+ expiration: inviteMessage.inviteExpiration.toString(),
301
+ admin: key.remoteJid,
302
+ },
303
+ },
304
+ ]);
305
+ // if we have the full message key
306
+ // update the invite message to be expired
307
+ if (key.id) {
308
+ // create new invite message that is expired
309
+ inviteMessage =
310
+ proto.Message.GroupInviteMessage.fromObject(inviteMessage);
311
+ inviteMessage.inviteExpiration = 0;
312
+ inviteMessage.inviteCode = "";
313
+ ev.emit("messages.update", [
314
+ {
315
+ key: key,
316
+ update: {
317
+ message: { groupInviteMessage: inviteMessage },
318
+ },
319
+ },
320
+ ]);
321
+ }
322
+ // generate the group add message
323
+ await upsertMessage(
324
+ {
325
+ key: {
326
+ remoteJid: inviteMessage.groupJid,
327
+ id: generateMessageIDV2(sock.user?.id),
328
+ fromMe: false,
329
+ participant: key.remoteJid,
330
+ },
331
+ messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
332
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
333
+ participant: key.remoteJid,
334
+ messageTimestamp: unixTimestampSeconds(),
335
+ },
336
+ "notify",
337
+ );
338
+ return results.attrs.from;
339
+ },
340
+ ),
341
+ groupGetInviteInfo: async (code) => {
342
+ const results = await groupQuery("@g.us", "get", [
343
+ { tag: "invite", attrs: { code: code } },
344
+ ]);
345
+ return extractGroupMetadata(results);
346
+ },
347
+ groupToggleEphemeral: async (jid, ephemeralExpiration) => {
348
+ const content = ephemeralExpiration
349
+ ? {
350
+ tag: "ephemeral",
351
+ attrs: { expiration: ephemeralExpiration.toString() },
352
+ }
353
+ : { tag: "not_ephemeral", attrs: {} };
354
+ await groupQuery(jid, "set", [content]);
355
+ },
356
+ groupSettingUpdate: async (jid, setting) => {
357
+ await groupQuery(jid, "set", [{ tag: setting, attrs: {} }]);
358
+ },
359
+ groupMemberAddMode: async (jid, mode) => {
360
+ await groupQuery(jid, "set", [
361
+ { tag: "member_add_mode", attrs: {}, content: mode },
362
+ ]);
363
+ },
364
+ groupJoinApprovalMode: async (jid, mode) => {
365
+ await groupQuery(jid, "set", [
366
+ {
367
+ tag: "membership_approval_mode",
368
+ attrs: {},
369
+ content: [{ tag: "group_join", attrs: { state: mode } }],
370
+ },
371
+ ]);
372
+ cache.del(jid);
373
+ if (config.store && config.store.groups) {
374
+ delete config.store.groups[jid];
375
+ }
376
+ },
377
+ groupFetchAllParticipating: groupFetchAllParticipating,
378
+ groupQuery: groupQuery,
379
+ };
380
+ };
381
+ export const extractGroupMetadata = (result) => {
382
+ const group = getBinaryNodeChild(result, "group");
383
+ const descChild = getBinaryNodeChild(group, "description");
384
+ let desc;
385
+ let descId;
386
+ let descOwner;
387
+ let descOwnerPn;
388
+ let descTime;
389
+ if (descChild) {
390
+ desc = getBinaryNodeChildString(descChild, "body");
391
+ descOwner = descChild.attrs.participant
392
+ ? jidNormalizedUser(descChild.attrs.participant)
393
+ : undefined;
394
+ descOwnerPn = descChild.attrs.participant_pn
395
+ ? jidNormalizedUser(descChild.attrs.participant_pn)
396
+ : undefined;
397
+ descTime = +descChild.attrs.t;
398
+ descId = descChild.attrs.id;
399
+ }
400
+ const groupId = group.attrs.id.includes("@")
401
+ ? group.attrs.id
402
+ : jidEncode(group.attrs.id, "g.us");
403
+ const eph = getBinaryNodeChild(group, "ephemeral")?.attrs.expiration;
404
+ const memberAddMode =
405
+ getBinaryNodeChildString(group, "member_add_mode") === "all_member_add";
406
+ const metadata = {
407
+ id: groupId,
408
+ notify: group.attrs.notify,
409
+ addressingMode:
410
+ group.attrs.addressing_mode === "lid"
411
+ ? WAMessageAddressingMode.LID
412
+ : WAMessageAddressingMode.PN,
413
+ subject: group.attrs.subject,
414
+ subjectOwner: group.attrs.s_o,
415
+ subjectOwnerPn: group.attrs.s_o_pn,
416
+ subjectTime: +group.attrs.s_t,
417
+ size: group.attrs.size
418
+ ? +group.attrs.size
419
+ : getBinaryNodeChildren(group, "participant").length,
420
+ creation: +group.attrs.creation,
421
+ owner: group.attrs.creator
422
+ ? jidNormalizedUser(group.attrs.creator)
423
+ : undefined,
424
+ ownerPn: group.attrs.creator_pn
425
+ ? jidNormalizedUser(group.attrs.creator_pn)
426
+ : undefined,
427
+ owner_country_code: group.attrs.creator_country_code,
428
+ desc: desc,
429
+ descId: descId,
430
+ descOwner: descOwner,
431
+ descOwnerPn: descOwnerPn,
432
+ descTime: descTime,
433
+ linkedParent:
434
+ getBinaryNodeChild(group, "linked_parent")?.attrs.jid || undefined,
435
+ restrict: !!getBinaryNodeChild(group, "locked"),
436
+ announce: !!getBinaryNodeChild(group, "announcement"),
437
+ isCommunity: !!getBinaryNodeChild(group, "parent"),
438
+ isCommunityAnnounce: !!getBinaryNodeChild(group, "default_sub_group"),
439
+ joinApprovalMode: !!getBinaryNodeChild(group, "membership_approval_mode"),
440
+ memberAddMode: memberAddMode,
441
+ participants: getBinaryNodeChildren(group, "participant").map(
442
+ ({ attrs }) => {
443
+ const id = jidNormalizedUser(attrs.jid);
444
+ const phone = attrs.phone_number
445
+ ? jidNormalizedUser(attrs.phone_number)
446
+ : isPnUser(id)
447
+ ? id
448
+ : undefined;
449
+ const lid = attrs.lid
450
+ ? jidNormalizedUser(attrs.lid)
451
+ : isLidUser(id)
452
+ ? id
453
+ : undefined;
454
+ return {
455
+ id: phone,
456
+ lid: lid,
457
+ jid: phone,
458
+ admin: attrs.type || false,
459
+ };
460
+ },
461
+ ),
462
+ ephemeralDuration: eph ? +eph : undefined,
463
+ };
464
+ return metadata;
465
+ };
@@ -0,0 +1,14 @@
1
+ import { DEFAULT_CONNECTION_CONFIG } from "../Defaults/index.js";
2
+ import { makeCommunitiesSocket } from "./communities.js";
3
+ const makeWASocket = (config) => {
4
+ delete config.userDevicesCache;
5
+ const newConfig = { ...DEFAULT_CONNECTION_CONFIG, ...config };
6
+ let sock;
7
+ const originalGetMessage = newConfig.getMessage;
8
+ newConfig.getMessage = async function (key) {
9
+ return originalGetMessage.call(sock || this, key);
10
+ };
11
+ sock = makeCommunitiesSocket(newConfig);
12
+ return sock;
13
+ };
14
+ export default makeWASocket;