keithbaileys 1.0.5 → 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.
@@ -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 || {})
@@ -1,3 +1,4 @@
1
+
1
2
  "use strict";
2
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -200,7 +201,7 @@ const makeMessagesSocket = (config) => {
200
201
  }
201
202
  return didFetchNewSession;
202
203
  };
203
-
204
+ //
204
205
  const sendPeerDataOperationMessage = async (pdoMessage) => {
205
206
  var _a;
206
207
  if (!((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id)) {
@@ -597,6 +598,114 @@ const makeMessagesSocket = (config) => {
597
598
  const giftedStatus = new GiftedStatus(Utils_1, waUploadToServer, relayMessage, config, sock);
598
599
 
599
600
  const waitForMsgMediaUpdate = (0, Utils_1.bindWaitForEvent)(ev, 'messages.media-update');
601
+ // ============ RICH MESSAGE METHODS ============
602
+ /**
603
+ * Send a table as a rich (AI-forwarded-style) message.
604
+ * @param {string} jid
605
+ * @param {{ headers: string[], rows: string[][] } | string[][] | [string, string, string]} table
606
+ * Accepts any of:
607
+ * - { headers: string[], rows: string[][] }
608
+ * - a 2D array: [[headers...], [row1...], [row2...]]
609
+ * - legacy flat array: [title, "h1|h2", "r1c1|r1c2;;r2c1|r2c2"]
610
+ * @param {object} [quoted]
611
+ * @param {object} [options]
612
+ */
613
+ const sendTable = async (jid, table, quoted, options = {}) => {
614
+ const { message, messageId } = Utils_1.generateTableContentV2(table, quoted, options);
615
+ await relayMessage(jid, message, { messageId });
616
+ return { message, messageId };
617
+ };
618
+ /**
619
+ * Send a list as a rich message.
620
+ */
621
+ const sendList = async (jid, title, items, quoted, options = {}) => {
622
+ const { message, messageId } = Utils_1.generateListContent(title, items, quoted, options);
623
+ await relayMessage(jid, message, { messageId });
624
+ return { message, messageId };
625
+ };
626
+ /**
627
+ * Send a syntax-highlighted code block as a rich message.
628
+ * @param {string} jid
629
+ * @param {string} code
630
+ * @param {object} [quoted]
631
+ * @param {object} [options] - { language }
632
+ */
633
+ const sendCodeBlock = async (jid, code, quoted, options = {}) => {
634
+ const { message, messageId } = Utils_1.generateCodeBlockContentV2(code, quoted, options);
635
+ await relayMessage(jid, message, { messageId });
636
+ return { message, messageId };
637
+ };
638
+ /**
639
+ * Send one or more links as a rich message.
640
+ */
641
+ const sendLink = async (jid, text, links, quoted, options = {}) => {
642
+ const { message, messageId } = Utils_1.generateLinkContentV2(text, links, quoted, options);
643
+ await relayMessage(jid, message, { messageId });
644
+ return { message, messageId };
645
+ };
646
+ /**
647
+ * Send a LaTeX expression as text metadata (renders client-side).
648
+ */
649
+ const sendLatex = async (jid, quoted, options = {}) => {
650
+ const { message, messageId } = Utils_1.generateLatexContent(quoted, options);
651
+ await relayMessage(jid, message, { messageId });
652
+ return { message, messageId };
653
+ };
654
+ /**
655
+ * Uploads a raw image buffer the same way updateCoverPhoto does, for use by the
656
+ * LaTeX-image rich message senders below (waUploadToServer expects a file path
657
+ * + its sha256, not a raw buffer).
658
+ */
659
+ const uploadRawImageBuffer = async (buffer, mediaType = 'image') => {
660
+ const { fileSha256, filePath } = await Utils_1.getRawMediaUploadData(buffer, mediaType);
661
+ return waUploadToServer(filePath, {
662
+ fileEncSha256B64: fileSha256.toString('base64'),
663
+ mediaType
664
+ });
665
+ };
666
+ /**
667
+ * Send LaTeX expressions rendered to images. Requires a renderLatexToPng(expr) => { buffer, width, height }
668
+ * function to be supplied, since Baileys does not bundle a LaTeX renderer.
669
+ */
670
+ const sendLatexImage = async (jid, quoted, options = {}, renderLatexToPng) => {
671
+ if (typeof renderLatexToPng !== 'function') {
672
+ throw new boom_1.Boom('sendLatexImage requires a renderLatexToPng(expression) function to be passed in');
673
+ }
674
+ const { message, messageId } = await Utils_1.generateLatexImageContent(quoted, options, uploadRawImageBuffer, renderLatexToPng);
675
+ await relayMessage(jid, message, { messageId });
676
+ return { message, messageId };
677
+ };
678
+ /**
679
+ * Send LaTeX expressions rendered inline as images. Requires the same renderLatexToPng function as sendLatexImage.
680
+ */
681
+ const sendLatexInlineImage = async (jid, quoted, options = {}, renderLatexToPng) => {
682
+ if (typeof renderLatexToPng !== 'function') {
683
+ throw new boom_1.Boom('sendLatexInlineImage requires a renderLatexToPng(expression) function to be passed in');
684
+ }
685
+ const { message, messageId } = await Utils_1.generateLatexInlineImageContent(quoted, options, uploadRawImageBuffer, renderLatexToPng);
686
+ await relayMessage(jid, message, { messageId });
687
+ return { message, messageId };
688
+ };
689
+ /**
690
+ * Capture an outgoing/quoted rich (unified-response) message so it can later be re-sent verbatim.
691
+ */
692
+ const captureUnifiedResponse = Utils_1.captureUnifiedResponse;
693
+ /**
694
+ * Re-send a previously captured unified response message.
695
+ */
696
+ const sendUnifiedResponse = async (jid, quoted, captured) => {
697
+ const { message, messageId } = Utils_1.generateUnifiedResponseContent(quoted, captured);
698
+ await relayMessage(jid, message, { messageId });
699
+ return { message, messageId };
700
+ };
701
+ /**
702
+ * Send a rich message composed of multiple submessages (text/table/code/etc).
703
+ */
704
+ const sendRichMessage = async (jid, submessages, quoted, options = {}) => {
705
+ const { message, messageId } = Utils_1.generateRichMessageContent(submessages, quoted);
706
+ await relayMessage(jid, message, { messageId });
707
+ return { message, messageId };
708
+ };
600
709
 
601
710
  return {
602
711
  ...sock,
@@ -614,6 +723,16 @@ const makeMessagesSocket = (config) => {
614
723
  sendPeerDataOperationMessage,
615
724
  createParticipantNodes,
616
725
  getUSyncDevices,
726
+ sendTable,
727
+ sendList,
728
+ sendCodeBlock,
729
+ sendLink,
730
+ sendLatex,
731
+ sendLatexImage,
732
+ sendLatexInlineImage,
733
+ captureUnifiedResponse,
734
+ sendUnifiedResponse,
735
+ sendRichMessage,
617
736
  updateMediaMessage: async (message) => {
618
737
  const content = (0, Utils_1.assertMediaContent)(message.message);
619
738
  const mediaKey = content.mediaKey;
@@ -808,7 +927,7 @@ const makeMessagesSocket = (config) => {
808
927
 
809
928
  return msg;
810
929
  },
811
- sendMessage: async (jid, content, options = {}) => {
930
+ sendMessage: async (jid, content, options = {}) => {
812
931
  var _a, _b, _c;
813
932
  const userJid = authState.creds.me.id;
814
933
  if (typeof content === 'object' &&
@@ -866,6 +985,7 @@ const makeMessagesSocket = (config) => {
866
985
  uploadImage: generateHighQualityLinkPreview ? waUploadToServer : undefined
867
986
  }),
868
987
  getProfilePicUrl: sock.profilePictureUrl,
988
+ getCallLink: sock.createCallLink,
869
989
  upload: waUploadToServer,
870
990
  mediaCache: config.mediaCache,
871
991
  options: config.options,