keithbaileys 1.0.6 → 1.0.8

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/README.md CHANGED
@@ -1 +1 @@
1
- # baileys
1
+ ## baileys
@@ -72,7 +72,10 @@ exports.MEDIA_PATH_MAP = {
72
72
  'thumbnail-link': '/mms/image',
73
73
  'product-catalog-image': '/product/image',
74
74
  'md-app-state': '',
75
- 'md-msg-hist': '/mms/md-app-state'
75
+ 'md-msg-hist': '/mms/md-app-state',
76
+ 'biz-cover-photo': '/pps/biz-cover-photo',
77
+ 'sticker-pack': '/mms/sticker',
78
+ 'thumbnail-sticker-pack': '/mms/sticker'
76
79
  };
77
80
  exports.MEDIA_HKDF_KEY_MAPPING = {
78
81
  audio: 'Audio',
@@ -92,7 +95,10 @@ exports.MEDIA_HKDF_KEY_MAPPING = {
92
95
  'md-app-state': 'App State',
93
96
  'product-catalog-image': '',
94
97
  'payment-bg-image': 'Payment Background',
95
- ptv: 'Video'
98
+ ptv: 'Video',
99
+ 'biz-cover-photo': 'Image',
100
+ 'sticker-pack': 'Sticker Pack',
101
+ 'thumbnail-sticker-pack': 'Sticker Pack'
96
102
  };
97
103
  exports.MEDIA_KEYS = Object.keys(exports.MEDIA_PATH_MAP);
98
104
  exports.MIN_PREKEY_COUNT = 5;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.makeBusinessSocket = void 0;
4
4
  const business_1 = require("../Utils/business");
5
+ const messages_media_1 = require("../Utils/messages-media");
5
6
  const WABinary_1 = require("../WABinary");
6
7
  const generic_utils_1 = require("../WABinary/generic-utils");
7
8
  const messages_recv_1 = require("./messages-recv");
@@ -246,6 +247,126 @@ const makeBusinessSocket = (config) => {
246
247
  deleted: +((productCatalogDelNode === null || productCatalogDelNode === void 0 ? void 0 : productCatalogDelNode.attrs.deleted_count) || 0)
247
248
  };
248
249
  };
250
+ const updateBussinesProfile = async (args) => {
251
+ const node = [];
252
+ const simpleFields = ['address', 'email', 'description'];
253
+ node.push(...simpleFields
254
+ .filter(key => args[key] !== undefined && args[key] !== null)
255
+ .map(key => ({
256
+ tag: key,
257
+ attrs: {},
258
+ content: args[key]
259
+ })));
260
+ if (args.websites !== undefined) {
261
+ node.push(...args.websites.map(website => ({
262
+ tag: 'website',
263
+ attrs: {},
264
+ content: website
265
+ })));
266
+ }
267
+ if (args.hours !== undefined) {
268
+ node.push({
269
+ tag: 'business_hours',
270
+ attrs: { timezone: args.hours.timezone },
271
+ content: args.hours.days.map(dayConfig => {
272
+ const base = {
273
+ tag: 'business_hours_config',
274
+ attrs: {
275
+ day_of_week: dayConfig.day,
276
+ mode: dayConfig.mode
277
+ }
278
+ };
279
+ if (dayConfig.mode === 'specific_hours') {
280
+ return {
281
+ ...base,
282
+ attrs: {
283
+ ...base.attrs,
284
+ open_time: dayConfig.openTimeInMinutes,
285
+ close_time: dayConfig.closeTimeInMinutes
286
+ }
287
+ };
288
+ }
289
+ return base;
290
+ })
291
+ });
292
+ }
293
+ const result = await query({
294
+ tag: 'iq',
295
+ attrs: {
296
+ to: WABinary_1.S_WHATSAPP_NET,
297
+ type: 'set',
298
+ xmlns: 'w:biz'
299
+ },
300
+ content: [
301
+ {
302
+ tag: 'business_profile',
303
+ attrs: {
304
+ v: '3',
305
+ mutation_type: 'delta'
306
+ },
307
+ content: node
308
+ }
309
+ ]
310
+ });
311
+ return result;
312
+ };
313
+ const updateCoverPhoto = async (photo) => {
314
+ const { fileSha256, filePath } = await (0, messages_media_1.getRawMediaUploadData)(photo, 'biz-cover-photo');
315
+ const fileSha256B64 = fileSha256.toString('base64');
316
+ const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
317
+ fileEncSha256B64: fileSha256B64,
318
+ mediaType: 'biz-cover-photo'
319
+ });
320
+ await query({
321
+ tag: 'iq',
322
+ attrs: {
323
+ to: WABinary_1.S_WHATSAPP_NET,
324
+ type: 'set',
325
+ xmlns: 'w:biz'
326
+ },
327
+ content: [
328
+ {
329
+ tag: 'business_profile',
330
+ attrs: {
331
+ v: '3',
332
+ mutation_type: 'delta'
333
+ },
334
+ content: [
335
+ {
336
+ tag: 'cover_photo',
337
+ attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
338
+ }
339
+ ]
340
+ }
341
+ ]
342
+ });
343
+ return fbid;
344
+ };
345
+ const removeCoverPhoto = async (id) => {
346
+ return await query({
347
+ tag: 'iq',
348
+ attrs: {
349
+ to: WABinary_1.S_WHATSAPP_NET,
350
+ type: 'set',
351
+ xmlns: 'w:biz'
352
+ },
353
+ content: [
354
+ {
355
+ tag: 'business_profile',
356
+ attrs: {
357
+ v: '3',
358
+ mutation_type: 'delta'
359
+ },
360
+ content: [
361
+ {
362
+ tag: 'cover_photo',
363
+ attrs: { op: 'delete', id }
364
+ }
365
+ ]
366
+ }
367
+ ]
368
+ });
369
+ };
249
370
  return {
250
371
  ...sock,
251
372
  logger: config.logger,
@@ -254,7 +375,10 @@ const makeBusinessSocket = (config) => {
254
375
  getCollections,
255
376
  productCreate,
256
377
  productDelete,
257
- productUpdate
378
+ productUpdate,
379
+ updateBussinesProfile,
380
+ updateCoverPhoto,
381
+ removeCoverPhoto
258
382
  };
259
383
  };
260
384
  exports.makeBusinessSocket = makeBusinessSocket;
@@ -0,0 +1,439 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractCommunityMetadata = exports.makeCommunitiesSocket = void 0;
4
+ const WAProto_1 = require("../../WAProto");
5
+ const Types_1 = require("../Types");
6
+ const Utils_1 = require("../Utils");
7
+ const logger_1 = require("../Utils/logger");
8
+ const WABinary_1 = require("../WABinary");
9
+ const business_1 = require("./business");
10
+ const makeCommunitiesSocket = (config) => {
11
+ const sock = (0, business_1.makeBusinessSocket)(config);
12
+ const { authState, ev, query, upsertMessage } = sock;
13
+ const communityQuery = async (jid, type, content) => query({
14
+ tag: 'iq',
15
+ attrs: {
16
+ type,
17
+ xmlns: 'w:g2',
18
+ to: jid
19
+ },
20
+ content
21
+ });
22
+ const communityMetadata = async (jid) => {
23
+ const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
24
+ return (0, exports.extractCommunityMetadata)(result);
25
+ };
26
+ const communityFetchAllParticipating = async () => {
27
+ const result = await query({
28
+ tag: 'iq',
29
+ attrs: {
30
+ to: '@g.us',
31
+ xmlns: 'w:g2',
32
+ type: 'get'
33
+ },
34
+ content: [
35
+ {
36
+ tag: 'participating',
37
+ attrs: {},
38
+ content: [
39
+ { tag: 'participants', attrs: {} },
40
+ { tag: 'description', attrs: {} }
41
+ ]
42
+ }
43
+ ]
44
+ });
45
+ const data = {};
46
+ const communitiesChild = (0, WABinary_1.getBinaryNodeChild)(result, 'communities');
47
+ if (communitiesChild) {
48
+ const communities = (0, WABinary_1.getBinaryNodeChildren)(communitiesChild, 'community');
49
+ for (const communityNode of communities) {
50
+ const meta = (0, exports.extractCommunityMetadata)({
51
+ tag: 'result',
52
+ attrs: {},
53
+ content: [communityNode]
54
+ });
55
+ data[meta.id] = meta;
56
+ }
57
+ }
58
+ sock.ev.emit('groups.update', Object.values(data));
59
+ return data;
60
+ };
61
+ async function parseGroupResult(node) {
62
+ logger_1.default.info({ node }, 'parseGroupResult');
63
+ const groupNode = (0, WABinary_1.getBinaryNodeChild)(node, 'group');
64
+ if (groupNode) {
65
+ try {
66
+ logger_1.default.info({ groupNode }, 'groupNode');
67
+ const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
68
+ return metadata ? metadata : Optional.empty();
69
+ }
70
+ catch (error) {
71
+ console.error('Error parsing group metadata:', error);
72
+ return Optional.empty();
73
+ }
74
+ }
75
+ return Optional.empty();
76
+ }
77
+ const Optional = {
78
+ empty: () => null,
79
+ of: (value) => (value !== null ? { value } : null)
80
+ };
81
+ sock.ws.on('CB:ib,,dirty', async (node) => {
82
+ const { attrs } = (0, WABinary_1.getBinaryNodeChild)(node, 'dirty');
83
+ if (attrs.type !== 'communities') {
84
+ return;
85
+ }
86
+ await communityFetchAllParticipating();
87
+ await sock.cleanDirtyBits('groups');
88
+ });
89
+ return {
90
+ ...sock,
91
+ communityMetadata,
92
+ communityCreate: async (subject, body) => {
93
+ const descriptionId = (0, Utils_1.generateMessageID)().substring(0, 12);
94
+ const result = await communityQuery('@g.us', 'set', [
95
+ {
96
+ tag: 'create',
97
+ attrs: { subject },
98
+ content: [
99
+ {
100
+ tag: 'description',
101
+ attrs: { id: descriptionId },
102
+ content: [
103
+ {
104
+ tag: 'body',
105
+ attrs: {},
106
+ content: Buffer.from(body || '', 'utf-8')
107
+ }
108
+ ]
109
+ },
110
+ {
111
+ tag: 'parent',
112
+ attrs: { default_membership_approval_mode: 'request_required' }
113
+ },
114
+ {
115
+ tag: 'allow_non_admin_sub_group_creation',
116
+ attrs: {}
117
+ },
118
+ {
119
+ tag: 'create_general_chat',
120
+ attrs: {}
121
+ }
122
+ ]
123
+ }
124
+ ]);
125
+ return await parseGroupResult(result);
126
+ },
127
+ communityCreateGroup: async (subject, participants, parentCommunityJid) => {
128
+ const key = (0, Utils_1.generateMessageIDV2)();
129
+ const result = await communityQuery('@g.us', 'set', [
130
+ {
131
+ tag: 'create',
132
+ attrs: {
133
+ subject,
134
+ key
135
+ },
136
+ content: [
137
+ ...participants.map(jid => ({
138
+ tag: 'participant',
139
+ attrs: { jid }
140
+ })),
141
+ { tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
142
+ ]
143
+ }
144
+ ]);
145
+ return await parseGroupResult(result);
146
+ },
147
+ communityLeave: async (id) => {
148
+ await communityQuery('@g.us', 'set', [
149
+ {
150
+ tag: 'leave',
151
+ attrs: {},
152
+ content: [{ tag: 'community', attrs: { id } }]
153
+ }
154
+ ]);
155
+ },
156
+ communityUpdateSubject: async (jid, subject) => {
157
+ await communityQuery(jid, 'set', [
158
+ {
159
+ tag: 'subject',
160
+ attrs: {},
161
+ content: Buffer.from(subject, 'utf-8')
162
+ }
163
+ ]);
164
+ },
165
+ communityLinkGroup: async (groupJid, parentCommunityJid) => {
166
+ await communityQuery(parentCommunityJid, 'set', [
167
+ {
168
+ tag: 'links',
169
+ attrs: {},
170
+ content: [
171
+ {
172
+ tag: 'link',
173
+ attrs: { link_type: 'sub_group' },
174
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
175
+ }
176
+ ]
177
+ }
178
+ ]);
179
+ },
180
+ communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
181
+ await communityQuery(parentCommunityJid, 'set', [
182
+ {
183
+ tag: 'unlink',
184
+ attrs: { unlink_type: 'sub_group' },
185
+ content: [{ tag: 'group', attrs: { jid: groupJid } }]
186
+ }
187
+ ]);
188
+ },
189
+ communityFetchLinkedGroups: async (jid) => {
190
+ let communityJid = jid;
191
+ let isCommunity = false;
192
+ // Try to determine if it is a subgroup or a community
193
+ const metadata = await sock.groupMetadata(jid);
194
+ if (metadata.linkedParent) {
195
+ // It is a subgroup, get the community jid
196
+ communityJid = metadata.linkedParent;
197
+ }
198
+ else {
199
+ // It is a community
200
+ isCommunity = true;
201
+ }
202
+ // Fetch all subgroups of the community
203
+ const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }]);
204
+ const linkedGroupsData = [];
205
+ const subGroupsNode = (0, WABinary_1.getBinaryNodeChild)(result, 'sub_groups');
206
+ if (subGroupsNode) {
207
+ const groupNodes = (0, WABinary_1.getBinaryNodeChildren)(subGroupsNode, 'group');
208
+ for (const groupNode of groupNodes) {
209
+ linkedGroupsData.push({
210
+ id: groupNode.attrs.id ? (0, WABinary_1.jidEncode)(groupNode.attrs.id, 'g.us') : undefined,
211
+ subject: groupNode.attrs.subject || '',
212
+ creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
213
+ owner: groupNode.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(groupNode.attrs.creator) : undefined,
214
+ size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
215
+ });
216
+ }
217
+ }
218
+ return {
219
+ communityJid,
220
+ isCommunity,
221
+ linkedGroups: linkedGroupsData
222
+ };
223
+ },
224
+ communityRequestParticipantsList: async (jid) => {
225
+ const result = await communityQuery(jid, 'get', [
226
+ {
227
+ tag: 'membership_approval_requests',
228
+ attrs: {}
229
+ }
230
+ ]);
231
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_approval_requests');
232
+ const participants = (0, WABinary_1.getBinaryNodeChildren)(node, 'membership_approval_request');
233
+ return participants.map(v => v.attrs);
234
+ },
235
+ communityRequestParticipantsUpdate: async (jid, participants, action) => {
236
+ const result = await communityQuery(jid, 'set', [
237
+ {
238
+ tag: 'membership_requests_action',
239
+ attrs: {},
240
+ content: [
241
+ {
242
+ tag: action,
243
+ attrs: {},
244
+ content: participants.map(jid => ({
245
+ tag: 'participant',
246
+ attrs: { jid }
247
+ }))
248
+ }
249
+ ]
250
+ }
251
+ ]);
252
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action');
253
+ const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action);
254
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(nodeAction, 'participant');
255
+ return participantsAffected.map(p => {
256
+ return { status: p.attrs.error || '200', jid: p.attrs.jid };
257
+ });
258
+ },
259
+ communityParticipantsUpdate: async (jid, participants, action) => {
260
+ const result = await communityQuery(jid, 'set', [
261
+ {
262
+ tag: action,
263
+ attrs: action === 'remove' ? { linked_groups: 'true' } : {},
264
+ content: participants.map(jid => ({
265
+ tag: 'participant',
266
+ attrs: { jid }
267
+ }))
268
+ }
269
+ ]);
270
+ const node = (0, WABinary_1.getBinaryNodeChild)(result, action);
271
+ const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(node, 'participant');
272
+ return participantsAffected.map(p => {
273
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
274
+ });
275
+ },
276
+ communityUpdateDescription: async (jid, description) => {
277
+ var _a;
278
+ const metadata = await communityMetadata(jid);
279
+ const prev = (_a = metadata.descId) !== null && _a !== void 0 ? _a : null;
280
+ await communityQuery(jid, 'set', [
281
+ {
282
+ tag: 'description',
283
+ attrs: {
284
+ ...(description ? { id: (0, Utils_1.generateMessageID)() } : { delete: 'true' }),
285
+ ...(prev ? { prev } : {})
286
+ },
287
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
288
+ }
289
+ ]);
290
+ },
291
+ communityInviteCode: async (jid) => {
292
+ const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
293
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
294
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
295
+ },
296
+ communityRevokeInvite: async (jid) => {
297
+ const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
298
+ const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
299
+ return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
300
+ },
301
+ communityAcceptInvite: async (code) => {
302
+ const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
303
+ const result = (0, WABinary_1.getBinaryNodeChild)(results, 'community');
304
+ return result === null || result === void 0 ? void 0 : result.attrs.jid;
305
+ },
306
+ /**
307
+ * revoke a v4 invite for someone
308
+ * @param communityJid community jid
309
+ * @param invitedJid jid of person you invited
310
+ * @returns true if successful
311
+ */
312
+ communityRevokeInviteV4: async (communityJid, invitedJid) => {
313
+ const result = await communityQuery(communityJid, 'set', [
314
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
315
+ ]);
316
+ return !!result;
317
+ },
318
+ /**
319
+ * accept a CommunityInviteMessage
320
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
321
+ * @param inviteMessage the message to accept
322
+ */
323
+ communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
324
+ var _a;
325
+ key = typeof key === 'string' ? { remoteJid: key } : key;
326
+ const results = await communityQuery(inviteMessage.groupJid, 'set', [
327
+ {
328
+ tag: 'accept',
329
+ attrs: {
330
+ code: inviteMessage.inviteCode,
331
+ expiration: inviteMessage.inviteExpiration.toString(),
332
+ admin: key.remoteJid
333
+ }
334
+ }
335
+ ]);
336
+ // if we have the full message key
337
+ // update the invite message to be expired
338
+ if (key.id) {
339
+ // create new invite message that is expired
340
+ inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
341
+ inviteMessage.inviteExpiration = 0;
342
+ inviteMessage.inviteCode = '';
343
+ ev.emit('messages.update', [
344
+ {
345
+ key,
346
+ update: {
347
+ message: {
348
+ groupInviteMessage: inviteMessage
349
+ }
350
+ }
351
+ }
352
+ ]);
353
+ }
354
+ // generate the community add message
355
+ await upsertMessage({
356
+ key: {
357
+ remoteJid: inviteMessage.groupJid,
358
+ id: (0, Utils_1.generateMessageIDV2)((_a = sock.user) === null || _a === void 0 ? void 0 : _a.id),
359
+ fromMe: false,
360
+ participant: key.remoteJid // TODO: investigate if this makes any sense at all
361
+ },
362
+ messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
363
+ messageStubParameters: [JSON.stringify(authState.creds.me)],
364
+ participant: key.remoteJid,
365
+ messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
366
+ }, 'notify');
367
+ return results.attrs.from;
368
+ }),
369
+ communityGetInviteInfo: async (code) => {
370
+ const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
371
+ return (0, exports.extractCommunityMetadata)(results);
372
+ },
373
+ communityToggleEphemeral: async (jid, ephemeralExpiration) => {
374
+ const content = ephemeralExpiration
375
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
376
+ : { tag: 'not_ephemeral', attrs: {} };
377
+ await communityQuery(jid, 'set', [content]);
378
+ },
379
+ communitySettingUpdate: async (jid, setting) => {
380
+ await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
381
+ },
382
+ communityMemberAddMode: async (jid, mode) => {
383
+ await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
384
+ },
385
+ communityJoinApprovalMode: async (jid, mode) => {
386
+ await communityQuery(jid, 'set', [
387
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
388
+ ]);
389
+ },
390
+ communityFetchAllParticipating
391
+ };
392
+ };
393
+ exports.makeCommunitiesSocket = makeCommunitiesSocket;
394
+ const extractCommunityMetadata = (result) => {
395
+ var _a;
396
+ const community = (0, WABinary_1.getBinaryNodeChild)(result, 'community');
397
+ const descChild = (0, WABinary_1.getBinaryNodeChild)(community, 'description');
398
+ let desc;
399
+ let descId;
400
+ if (descChild) {
401
+ desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
402
+ descId = descChild.attrs.id;
403
+ }
404
+ const communityId = ((_a = community.attrs.id) === null || _a === void 0 ? void 0 : _a.includes('@'))
405
+ ? community.attrs.id
406
+ : (0, WABinary_1.jidEncode)(community.attrs.id || '', 'g.us');
407
+ const eph = (0, WABinary_1.getBinaryNodeChild)(community, 'ephemeral');
408
+ const ephExpiration = eph === null || eph === void 0 ? void 0 : eph.attrs.expiration;
409
+ const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(community, 'member_add_mode') === 'all_member_add';
410
+ const linkedParentNode = (0, WABinary_1.getBinaryNodeChild)(community, 'linked_parent');
411
+ const metadata = {
412
+ id: communityId,
413
+ subject: community.attrs.subject || '',
414
+ subjectOwner: community.attrs.s_o,
415
+ subjectTime: Number(community.attrs.s_t || 0),
416
+ size: (0, WABinary_1.getBinaryNodeChildren)(community, 'participant').length,
417
+ creation: Number(community.attrs.creation || 0),
418
+ owner: community.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(community.attrs.creator) : undefined,
419
+ desc,
420
+ descId,
421
+ linkedParent: (linkedParentNode === null || linkedParentNode === void 0 ? void 0 : linkedParentNode.attrs.jid) || undefined,
422
+ restrict: !!(0, WABinary_1.getBinaryNodeChild)(community, 'locked'),
423
+ announce: !!(0, WABinary_1.getBinaryNodeChild)(community, 'announcement'),
424
+ isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(community, 'parent'),
425
+ isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(community, 'default_sub_community'),
426
+ joinApprovalMode: !!(0, WABinary_1.getBinaryNodeChild)(community, 'membership_approval_mode'),
427
+ memberAddMode,
428
+ participants: (0, WABinary_1.getBinaryNodeChildren)(community, 'participant').map(({ attrs }) => {
429
+ return {
430
+ id: attrs.jid,
431
+ admin: attrs.type || null
432
+ };
433
+ }),
434
+ ephemeralDuration: ephExpiration ? +ephExpiration : undefined,
435
+ addressingMode: (0, WABinary_1.getBinaryNodeChildString)(community, 'addressing_mode')
436
+ };
437
+ return metadata;
438
+ };
439
+ exports.extractCommunityMetadata = extractCommunityMetadata;
@@ -281,11 +281,13 @@ const extractGroupMetadata = (result) => {
281
281
  let descId;
282
282
  let descOwner;
283
283
  let descOwnerJid;
284
+ let descOwnerUsername;
284
285
  let descTime;
285
286
  if (descChild) {
286
287
  desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
287
288
  descOwner = descChild.attrs.participant ? (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant) : undefined;
288
289
  descOwnerJid = descChild.attrs.participant_pn ? (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant_pn) : undefined;
290
+ descOwnerUsername = descChild.attrs.participant_username || undefined;
289
291
  descTime = +descChild.attrs.t;
290
292
  descId = descChild.attrs.id;
291
293
  }
@@ -298,15 +300,18 @@ const extractGroupMetadata = (result) => {
298
300
  subject: group.attrs.subject,
299
301
  subjectOwner: group.attrs.s_o,
300
302
  subjectOwnerJid: group.attrs.s_o_pn,
303
+ subjectOwnerUsername: group.attrs.s_o_username,
301
304
  subjectTime: +group.attrs.s_t,
302
305
  size: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
303
306
  creation: +group.attrs.creation,
304
307
  owner: group.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) : undefined,
305
308
  ownerJid: group.attrs.creator_pn ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator_pn) : undefined,
309
+ ownerUsername: group.attrs.creator_username || undefined,
306
310
  desc,
307
311
  descId,
308
312
  descOwner,
309
313
  descOwnerJid,
314
+ descOwnerUsername,
310
315
  descTime,
311
316
  linkedParent: ((_b = (0, WABinary_1.getBinaryNodeChild)(group, 'linked_parent')) === null || _b === void 0 ? void 0 : _b.attrs.jid) || undefined,
312
317
  restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
@@ -331,6 +336,7 @@ const extractGroupMetadata = (result) => {
331
336
  pn,
332
337
  lid,
333
338
  jid: (0, WABinary_1.isJidUser)(attrs.jid) ? attrs.jid : (0, WABinary_1.jidNormalizedUser)(attrs.phone_number),
339
+ username: attrs.participant_username || attrs.username || undefined,
334
340
  admin: (attrs.type || null)
335
341
  };
336
342
  }) // Added missing closing parenthesis and brace for the map function
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const Defaults_1 = require("../Defaults");
4
- const business_1 = require("./business");
4
+ const communities_1 = require("./communities");
5
5
  // export the last socket layer
6
- const makeWASocket = (config) => (0, business_1.makeBusinessSocket)({
6
+ const makeWASocket = (config) => (0, communities_1.makeCommunitiesSocket)({
7
7
  ...Defaults_1.DEFAULT_CONNECTION_CONFIG,
8
8
  ...config
9
9
  });
@@ -604,6 +604,7 @@ const makeMessagesRecvSocket = (config) => {
604
604
  fromMe,
605
605
  participant: node.attrs.participant,
606
606
  participantAlt: notifParticipantAlt,
607
+ participantUsername: node.attrs.participant_username,
607
608
  addressingMode: notifAddrMode,
608
609
  id: node.attrs.id,
609
610
  ...(msg.key || {})